<commit_before>import json

from django.test import TestCase
import mock

from ..factories import MarketFactory
from ..utils import update_market_alta, update_market_citybikes


class TestAlta(TestCase):
    def setUp(self):
        self.market = MarketFactory(slug='chicago', type='alta')
        with open('bikeme/apps/core/tests/support/divvy_response.json') as f:
            data = json.load(f)
        mock_get = mock.MagicMock(name='mock_get',
                **{'json.return_value': data})
        mock_requests = mock.patch('bikeme.apps.core.utils.requests',
                **{'get.return_value': mock_get})
        mock_requests.start()
        self.mock_requests = mock_requests

    def tearDown(self):
        self.mock_requests.stop()

    def test_it_works(self):
        with self.assertNumQueries(2701):
            update_market_alta(self.market)
        self.assertEqual(self.market.stations.count(), 300)


class TestCityBikes(TestCase):
    def setUp(self):
        self.market = MarketFactory(type='citi')
        with open('bikeme/apps/core/tests/support/citi-bike-nyc.json') as f:
            data = json.load(f)
        mock_get = mock.MagicMock(name='mock_get',
                **{'json.return_value': data})
        mock_requests = mock.patch('bikeme.apps.core.utils.requests',
                **{'get.return_value': mock_get})
        mock_requests.start()
        self.mock_requests = mock_requests
<commit_msg>document how many queries it takes to do a pure update<commit_after>import json

from django.test import TestCase
import mock

from ..factories import MarketFactory
from ..utils import update_market_alta, update_market_citybikes


class TestAlta(TestCase):
    def setUp(self):
        self.market = MarketFactory(slug='chicago', type='alta')
        with open('bikeme/apps/core/tests/support/divvy_response.json') as f:
            data = json.load(f)
        mock_get = mock.MagicMock(name='mock_get',
                **{'json.return_value': data})
        mock_requests = mock.patch('bikeme.apps.core.utils.requests',
                **{'get.return_value': mock_get})
        mock_requests.start()
        self.mock_requests = mock_requests

    def tearDown(self):
        self.mock_requests.stop()

    def test_it_works(self):
        with self.assertNumQueries(2701):
            update_market_alta(self.market)
        self.assertEqual(self.market.stations.count(), 300)
        # do it again
        with self.assertNumQueries(1201):
            update_market_alta(self.market)
        self.assertEqual(self.market.stations.count(), 300)


class TestCityBikes(TestCase):
    def setUp(self):
        self.market = MarketFactory(type='citi')
        with open('bikeme/apps/core/tests/support/citi-bike-nyc.json') as f:
            data = json.load(f)
        mock_get = mock.MagicMock(name='mock_get',
                **{'json.return_value': data})
        mock_requests = mock.patch('bikeme.apps.core.utils.requests',
                **{'get.return_value': mock_get})
        mock_requests.start()
        self.mock_requests = mock_requests

{'fraction_non_alphanumeric': 0.12002588159171788, 'fraction_numerical': 0.006793917825946296, 'mean_word_length': 2.770731707317073, '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': '6628853', 'n_tokens_mistral': 969, 'n_tokens_neox': 928, 'n_words': 166}