Exemplo n.º 1
0
 def test_get_movie_rating_patch_decorator(self):
     with patch('movie.omdb_call',
                return_value={
                    'Response':
                    'True',
                    'Ratings': [{
                        'Value': '7.5/10',
                        'Source': 'Internet Movie Database'
                    }]
                }) as mock_api:
         response = movie_rating('Example Movie')
         self.assertEqual('7.5/10', response)
Exemplo n.º 2
0
    def test_get_movie_rating_mock(self):

        # Create a mock and replace movie.omdb_call with the Mock function
        mock_api = Mock(
            return_value={
                'Response':
                'True',
                'Ratings': [{
                    'Value': '7.5/10',
                    'Source': 'Internet Movie Database'
                }]
            })
        movie.omdb_call = mock_api
        response = movie_rating('Example Movie')
        self.assertEqual('7.5/10', response)

        # If needed, can check how the mock was called. For example, was it called at all?
        mock_api.assert_called(
        )  # New in python 3.6 so check version and upgrade if needed.
Exemplo n.º 3
0
 def test_get_movie_rating(self):
     response = movie_rating('Frozen')
     self.assertEqual('7.5/10', response)
Exemplo n.º 4
0
 def test_get_movie_no_API_key(self):
     with patch.dict('os.environ', {'OMDB_KEY': ''}):
         with self.assertRaises(movie.OMDB_Exception) as ex_context:
             response = movie_rating('Frozen')  # Real movie
             print(response)
         self.assertEqual('No API key provided.', str(ex_context.exception))
Exemplo n.º 5
0
 def test_get_movie_rating_movie_not_found(self):
     with self.assertRaises(movie.OMDB_Exception) as ex_context:
         response = movie_rating(
             'asdsdfdfgdfhdrhjdrth')  # non-existent movie
     self.assertEqual('Movie not found!', str(ex_context.exception))
 def test_get_movie_rating_not_found(self):
     with self.assertRaises(OMDB_Exception) as ex_context:
         movie.movie_rating('Nope')
     self.assertEqual("Movie not found!", str(ex_context.exception))
Exemplo n.º 7
0
 def test_get_movie_rating_no_ratings_returned(self, api_patch):
     with self.assertRaises(OMDB_Exception) as ex_context:
         movie.movie_rating('example')
     self.assertEqual("Error processing response from OMDB",
                      str(ex_context.exception))
Exemplo n.º 8
0
    def test_get_movie_rating_error_returned_in_response(self, api_patch):

        with self.assertRaises(movie.OMDB_Exception) as ex_context:
            response = movie_rating('Example Movie')

        self.assertEqual('Something went wrong', str(ex_context.exception))
Exemplo n.º 9
0
 def test_get_movie_rating_error_connecting(self, api_patch):
     with self.assertRaises(movie.OMDB_Exception) as ex_context:
         response = movie_rating('Example Movie')
     self.assertEqual('Error connecting to OMDB', str(ex_context.exception))
Exemplo n.º 10
0
 def test_get_movie_rating_patch(self, api_patch):
     response = movie_rating('Example Movie')
     self.assertEqual('7.5/10', response)