<commit_before>from mock import MagicMock
from mock import patch

from django.core.management import call_command
from django.test import TestCase
from frontend.models import Presentation

from gcutils.bigquery import Client
from gcutils.bigquery import NotFound

from frontend.bq_schemas import RAW_PRESCRIBING_SCHEMA
from frontend.models import ImportLog


class CommandsTestCase(TestCase):
    fixtures = ['presentations', 'importlog']

    @patch('gcutils.bigquery.Client')
    def test_import_adqs(self, mock_client):
        mock_query = MagicMock(name='query')
        mock_query.query.return_value.rows = [
            ('0202010F0.*AA', 0.333),
        ]
        mock_client.return_value = mock_query
        call_command('import_adqs')

        # check we called bigquery with the right source table
        mock_query.query.assert_called_once()
        self.assertIn(
            "tmp_eu.raw_prescribing_data_2014_11",
            mock_query.query.call_args[0][0])

        # Check we set adq_per_quantity according to the bigquery results
        p = Presentation.objects.get(bnf_code='0202010F0AAAAAA')
        self.assertEqual(p.adq_per_quantity, 0.333)
        p = Presentation.objects.get(bnf_code='0204000I0JKKKAL')
        self.assertEqual(p.adq_per_quantity, None)


class CommandsFunctionalTestCase(TestCase):<commit_msg>Fix failing test<commit_after>from mock import MagicMock
from mock import patch

from django.core.management import call_command
from django.test import TestCase
from frontend.models import Presentation

from gcutils.bigquery import Client
from gcutils.bigquery import NotFound

from frontend.bq_schemas import RAW_PRESCRIBING_SCHEMA
from frontend.models import ImportLog


class CommandsTestCase(TestCase):
    fixtures = ['presentations', 'importlog']

    @patch('frontend.management.commands.import_adqs.Client')
    def test_import_adqs(self, mock_client):
        mock_query = MagicMock(name='query')
        mock_query.query.return_value.rows = [
            ('0202010F0.*AA', 0.333),
        ]
        mock_client.return_value = mock_query
        call_command('import_adqs')

        # check we called bigquery with the right source table
        mock_query.query.assert_called_once()
        self.assertIn(
            "raw_prescribing_data_2014_11",
            mock_query.query.call_args[0][0])

        # Check we set adq_per_quantity according to the bigquery results
        p = Presentation.objects.get(bnf_code='0202010F0AAAAAA')
        self.assertEqual(p.adq_per_quantity, 0.333)
        p = Presentation.objects.get(bnf_code='0204000I0JKKKAL')
        self.assertEqual(p.adq_per_quantity, None)


class CommandsFunctionalTestCase(TestCase):
{'fraction_non_alphanumeric': 0.0811111111111111, 'fraction_numerical': 0.02962962962962963, 'mean_word_length': 3.6730103806228374, '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': '5449373', 'n_tokens_mistral': 881, 'n_tokens_neox': 805, 'n_words': 171}