<commit_before>from marvin.models import Movie, Stream
from marvin.tests import TestCaseWithTempDB, AuthenticatedUserMixin

from mock import Mock, patch

import unittest

class AllMovieViewTest(TestCaseWithTempDB):

    def setUp(self):
        mission_impossible = Movie(
            title='Mission: Impossible',
            external_id='imdb:tt0499549',
        )
        harry_potter_azkaban = Movie(
            title='<NAME> and the Prisoner of Azkaban',
            external_id='imdb:tt0120338',
        )
        self.addItems(mission_impossible, harry_potter_azkaban)


    def test_search(self):
        with patch('marvin.tasks.external_search', Mock()):
            response = self.client.get('/movies?q=mission+impossible')
        json_response = self.assert200(response)
        self.assertEqual(len(json_response['movies']), 1)
        self.assertEqual(json_response['movies'][0]['title'], 'Mission: Impossible')

    def test_search_results_empty_fetches_external(self):
        # Search results for stuff we don't have should fetch more synchronously

        def create_movie(query): # pylint: disable=unused-argument
            movie = Movie(
                title='<NAME>',
                external_id='imdb:tt0241527'
            )
            self.addItems(movie)

        external_search = Mock(side_effect=create_movie)
        with patch('marvin.tasks.external_search', external_search):
            response = self.client.get('/movies?q=harry')
        json_response = self.assert200(response)
        self.assertEqual(len(json_response['movies']), 1)


    @unittest.skip("Should be reactivated when we want to support POST creation of movies")
    def test_post_movie(self):
        movie = {<commit_msg>Add test case for partial title match<commit_after>from marvin.models import Movie, Stream
from marvin.tests import TestCaseWithTempDB, AuthenticatedUserMixin

from mock import Mock, patch

import unittest

class AllMovieViewTest(TestCaseWithTempDB):

    def setUp(self):
        mission_impossible = Movie(
            title='Mission: Impossible',
            external_id='imdb:tt0499549',
        )
        harry_potter_azkaban = Movie(
            title='<NAME> and the Prisoner of Azkaban',
            external_id='imdb:tt0120338',
        )
        self.addItems(mission_impossible, harry_potter_azkaban)


    def test_search(self):
        with patch('marvin.tasks.external_search', Mock()):
            response = self.client.get('/movies?q=mission+impossible')
        json_response = self.assert200(response)
        self.assertEqual(len(json_response['movies']), 1)
        self.assertEqual(json_response['movies'][0]['title'], 'Mission: Impossible')

        with patch('marvin.tasks.external_search', Mock()):
            response = self.client.get('/movies?q=harry+azkaban')
        json_response = self.assert200(response)
        self.assertEqual(len(json_response['movies']), 1)
        self.assertEqual(json_response['movies'][0]['title'], '<NAME> and the Prisoner of Azkaban')

    def test_search_results_empty_fetches_external(self):
        # Search results for stuff we don't have should fetch more synchronously

        def create_movie(query): # pylint: disable=unused-argument
            movie = Movie(
                title='<NAME>',
                external_id='imdb:tt0241527'
            )
            self.addItems(movie)

        external_search = Mock(side_effect=create_movie)
        with patch('marvin.tasks.external_search', external_search):
            response = self.client.get('/movies?q=harry')
        json_response = self.assert200(response)
        self.assertEqual(len(json_response['movies']), 1)


    @unittest.skip("Should be reactivated when we want to support POST creation of movies")
    def test_post_movie(self):
        movie = {
{'fraction_non_alphanumeric': 0.10538702928870293, 'fraction_numerical': 0.016997907949790794, 'mean_word_length': 3.051906779661017, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6518017', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1088, 'n_words': 220}