<commit_before>import mock

from django.test import TestCase
from imdb.Person import Person
from imdb.Movie import Movie as IMDbMovie

from moviesdata.data import Actor
from moviesdata.services import search_actor, get_actor_info


class ServicesTests(TestCase):

    @classmethod
    def setUpClass(cls):
        super(ServicesTests, cls).setUpClass()
        cls.imdb_search_person_patcher = mock.patch('imdb.parser.http.IMDbHTTPAccessSystem.search_person')
        cls.imdb_get_person_patcher = mock.patch('imdb.parser.http.IMDbHTTPAccessSystem.get_person')
        cls.imdb_search_person_mock = cls.imdb_search_person_patcher.start()
        cls.imdb_get_person_mock = cls.imdb_get_person_patcher.start()

    @classmethod
    def tearDownClass(cls):
        cls.imdb_search_person_patcher.stop()
        cls.imdb_get_person_patcher.stop()
        super(ServicesTests, cls).tearDownClass()

    def test__search_actors__actors_found__actors_list(self):
        # Arrange
        self.imdb_search_person_mock.return_value = [
            Person(personID=1, name='Actor1'), Person(personID=2, name='Name2')
        ]
        # Act
        actors = search_actor('myname')
        # Assert
        self.assertEquals(actors, [Actor(1, 'Actor1'), Actor(2, 'Name2')])

    def test__search_actors__None_returned__empty_list(self):
        # Arrange
        self.imdb_search_person_mock.return_value = None
        # Act
        actors = search_actor('myname')
        # Assert
        self.assertEquals(actors, [])

    def test__get_actor_info__actor_found__actor(self):
        # Arrange
        person = Person(
            personID=1,
            data={
                'name': 'Actor1',
                'headshot': 'hs',
                'actor': [
                    IMDbMovie(
                        movieID=1,
                        data={
                            'title': 'mymovie',
                            'year': 2015,
                            'kind': 'movie'
                        })
                ]
            }
        )
        self.imdb_get_person_mock.return_value = person
        expected_actor = Actor.create(person, True)
        # Act
        actor = get_actor_info(1)
        # Assert
        self.assertEquals(actor, expected_actor)

    def test__get_actor_info__actor_not_found__None(self):
        # Arrange
        personID = 1
        self.imdb_get_person_mock.return_value = Person(
            personID=personID, data={})
        # Act
        actor = get_actor_info(personID)
        # Assert
        self.assertIsNone(actor)
<commit_msg>#13 - Breaking remaining lines with 80+ characters<commit_after>import mock

from django.test import TestCase
from imdb.Person import Person
from imdb.Movie import Movie as IMDbMovie

from moviesdata.data import Actor
from moviesdata.services import search_actor, get_actor_info


class ServicesTests(TestCase):

    @classmethod
    def setUpClass(cls):
        super(ServicesTests, cls).setUpClass()
        cls.imdb_search_person_patcher = mock.patch(
            'imdb.parser.http.IMDbHTTPAccessSystem.search_person')
        cls.imdb_get_person_patcher = mock.patch(
            'imdb.parser.http.IMDbHTTPAccessSystem.get_person')
        cls.imdb_search_person_mock = cls.imdb_search_person_patcher.start()
        cls.imdb_get_person_mock = cls.imdb_get_person_patcher.start()

    @classmethod
    def tearDownClass(cls):
        cls.imdb_search_person_patcher.stop()
        cls.imdb_get_person_patcher.stop()
        super(ServicesTests, cls).tearDownClass()

    def test__search_actors__actors_found__actors_list(self):
        # Arrange
        self.imdb_search_person_mock.return_value = [
            Person(personID=1, name='Actor1'), Person(personID=2, name='Name2')
        ]
        # Act
        actors = search_actor('myname')
        # Assert
        self.assertEquals(actors, [Actor(1, 'Actor1'), Actor(2, 'Name2')])

    def test__search_actors__None_returned__empty_list(self):
        # Arrange
        self.imdb_search_person_mock.return_value = None
        # Act
        actors = search_actor('myname')
        # Assert
        self.assertEquals(actors, [])

    def test__get_actor_info__actor_found__actor(self):
        # Arrange
        person = Person(
            personID=1,
            data={
                'name': 'Actor1',
                'headshot': 'hs',
                'actor': [
                    IMDbMovie(
                        movieID=1,
                        data={
                            'title': 'mymovie',
                            'year': 2015,
                            'kind': 'movie'
                        })
                ]
            }
        )
        self.imdb_get_person_mock.return_value = person
        expected_actor = Actor.create(person, True)
        # Act
        actor = get_actor_info(1)
        # Assert
        self.assertEquals(actor, expected_actor)

    def test__get_actor_info__actor_not_found__None(self):
        # Arrange
        personID = 1
        self.imdb_get_person_mock.return_value = Person(
            personID=personID, data={})
        # Act
        actor = get_actor_info(personID)
        # Assert
        self.assertIsNone(actor)

{'fraction_non_alphanumeric': 0.08962354290082171, 'fraction_numerical': 0.007261609019682782, 'mean_word_length': 2.0697947214076247, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6263660', 'n_tokens_mistral': 1592, 'n_tokens_neox': 1529, 'n_words': 248}