<commit_before>import os
from mock import patch
from vcr import use_cassette
from freezegun import freeze_time
from django.test import TestCase, override_settings
from django.conf import settings
from django.core.management import call_command
from busstops.models import Region, Operator
from ...models import Route


FIXTURES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures')


@override_settings(PASSENGER_OPERATORS=[
    ('Unilink', 'https://www.unilinkbus.co.uk/open-data', 'SW', {
        'SQ': 'UNIL',
        'BLUS': 'BLUS',
    })
])
class ImportPassengerTest(TestCase):
    @classmethod
    def setUpTestData(cls):
        sw = Region.objects.create(pk='SW', name='South West')
        Operator.objects.create(id='BLUS', region=sw, name='Bluestar')
        Operator.objects.create(id='UNIL', region=sw, name='Unilink')

    @freeze_time('2020-05-01')
    @use_cassette(os.path.join(FIXTURES_DIR, 'passenger.yaml'))
    def test_import(self):

        with patch('bustimes.management.commands.import_passenger.download_if_modified',
                   return_value=False) as download_if_modified:
            call_command('import_passenger')

            download_if_modified.assert_called_with(
                os.path.join(settings.DATA_DIR, 'unilink_1586941252.zip'),
                'https://s3-eu-west-1.amazonaws.com/passenger-sources/unilink/txc/unilink_1586941252.zip'
            )

        self.assertFalse(Route.objects.all())<commit_msg>fix test<commit_after>import os
from mock import patch
from vcr import use_cassette
from freezegun import freeze_time
from django.test import TestCase, override_settings
from django.conf import settings
from django.core.management import call_command
from busstops.models import Region, Operator
from ...models import Route


FIXTURES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures')


@override_settings(PASSENGER_OPERATORS=[
    ('Unilink', 'https://www.unilinkbus.co.uk/open-data', 'SW', {
        'SQ': 'UNIL',
        'BLUS': 'BLUS',
    })
])
class ImportPassengerTest(TestCase):
    @classmethod
    def setUpTestData(cls):
        sw = Region.objects.create(pk='SW', name='South West')
        Operator.objects.create(id='BLUS', region=sw, name='Bluestar')
        Operator.objects.create(id='UNIL', region=sw, name='Unilink')

    @freeze_time('2020-05-01')
    @use_cassette(os.path.join(FIXTURES_DIR, 'passenger.yaml'))
    def test_import(self):

        with patch('bustimes.management.commands.import_passenger.download_if_new',
                   return_value=False) as download_if_new:
            call_command('import_passenger')

            download_if_new.assert_called_with(
                os.path.join(settings.DATA_DIR, 'unilink_1586941252.zip'),
                'https://s3-eu-west-1.amazonaws.com/passenger-sources/unilink/txc/unilink_1586941252.zip'
            )

        self.assertFalse(Route.objects.all())
{'fraction_non_alphanumeric': 0.12559402579769177, 'fraction_numerical': 0.020366598778004074, 'mean_word_length': 3.6046875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3012208', 'n_tokens_mistral': 1008, 'n_tokens_neox': 945, 'n_words': 156}