def test_format_duration_(self, mock_datetime): """ Tests 'format_duration' function """ # Set up mock return values and side effects mock_datetime.datetime.utcnow.return_value = datetime(2018, 2, 2) mock_created_at = datetime(2018, 1, 2) # Call the function response = BaseReview().format_duration(mock_created_at) # Validate function calls and response self.assertEqual('1 month', response)
def test_format_duration_no_result(self, mock_datetime): """ Tests 'format_duration' function where we have no result """ # Set up mock return values and side effects mock_datetime.datetime.utcnow.return_value = datetime(2018, 2, 2) mock_created_at = datetime(2018, 3, 2) # Call the function response = BaseReview().format_duration(mock_created_at) # Validate function calls and response self.assertEqual('less than 1 minute', response)
def test_format_json(self, mock__json__, mock_json): """ Tests '_format_json' function """ # Set up mock return values and side effects mock_json.dumps.return_value = 'mock_format_json' mock__json__.return_value = 'mock__json__' # Call the function response = BaseReview()._format_json(1, 2, 3) # Validate function calls and response self.assertEqual(response, 'mock_format_json') mock_json.dumps.assert_called_with('mock__json__', indent=2) mock__json__.assert_called_with(3)
def setUp(self): self.mock_base_review = BaseReview() self.mock_base_review.user = '******' self.mock_base_review.title = 'mock_title' self.mock_base_review.url = 'mock_url' self.mock_base_review.time = 'mock_time'