def setUp(self):
     if 'SKIP_BQ_LOAD' not in os.environ:
         # Create local test data from fixtures, then upload this to a
         # test project in bigquery
         call_command('loaddata',
                      'frontend/tests/fixtures/ccgs.json',
                      verbosity=0)
         call_command('loaddata',
                      'frontend/tests/fixtures/practices.json',
                      verbosity=0)
         call_command('loaddata',
                      'frontend/tests/fixtures/practice_listsizes.json',
                      verbosity=0)
         fixtures_base = 'frontend/tests/fixtures/commands/'
         prescribing_fixture = (fixtures_base +
                                'prescribing_bigquery_views_fixture.csv')
         db_name = 'test_' + utils.get_env_setting('DB_NAME')
         env = patch.dict('os.environ', {'DB_NAME': db_name})
         with env:
             # We patch the environment as this is how the
             # ebmdatalab/bigquery library selects a database
             bigquery.load_prescribing_data_from_file(
                 'test_hscic', 'prescribing', prescribing_fixture)
             bigquery.load_ccgs_from_pg('test_hscic')
             bigquery.load_statistics_from_pg('test_hscic')
     ImportLog.objects.create(category='prescribing',
                              current_at='2015-10-01')
     # Create view tables and indexes
     with open('frontend/management/commands/replace_matviews.sql',
               'r') as f:
         with connection.cursor() as c:
             c.execute(f.read())
     args = []
     opts = {'dataset': 'test_hscic'}
     call_command('create_views', *args, **opts)
Exemple #2
0
 def setUpTestData(cls):
     fixtures_base = 'frontend/tests/fixtures/commands/'
     prescribing_fixture = (fixtures_base +
                            'prescribing_bigquery_fixture.csv')
     bigquery.load_prescribing_data_from_file(
         'hscic', settings.BQ_PRESCRIBING_TABLE_NAME_STANDARD,
         prescribing_fixture)
     month = date(2015, 9, 1)
     import_ppu_savings.Command().handle(month=month,
                                         substitutions_csv=fixtures_base +
                                         'ppu_substitutions.csv',
                                         min_ccg_saving=0,
                                         min_practice_saving=0,
                                         limit=1)
 def setUp(self):
     if 'SKIP_BQ_LOAD' not in os.environ:
         # Create local test data from fixtures, then upload this to a
         # test project in bigquery
         call_command('loaddata',
                      'frontend/tests/fixtures/ccgs.json',
                      verbosity=0)
         call_command('loaddata',
                      'frontend/tests/fixtures/practices.json',
                      verbosity=0)
         call_command('loaddata',
                      'frontend/tests/fixtures/practice_listsizes.json',
                      verbosity=0)
         fixtures_base = 'frontend/tests/fixtures/commands/'
         prescribing_fixture = (fixtures_base +
                                'prescribing_bigquery_views_fixture.csv')
         db_name = 'test_' + utils.get_env_setting('DB_NAME')
         env = patch.dict(
             'os.environ', {'DB_NAME': db_name})
         with env:
             # We patch the environment as this is how the
             # ebmdatalab/bigquery library selects a database
             bigquery.load_prescribing_data_from_file(
                 'test_hscic',
                 'prescribing',
                 prescribing_fixture)
             bigquery.load_ccgs_from_pg('test_hscic')
             bigquery.load_statistics_from_pg('test_hscic')
     ImportLog.objects.create(
         category='prescribing', current_at='2015-10-01')
     # Create view tables and indexes
     with open(
             'frontend/management/commands/replace_matviews.sql', 'r') as f:
         with connection.cursor() as c:
             c.execute(f.read())
     args = []
     opts = {
         'dataset': 'test_hscic'
     }
     call_command('create_views', *args, **opts)
Exemple #4
0
    def _createData(cls):
        SHA.objects.create(code='Q51')
        bassetlaw = PCT.objects.create(code='02Q', org_type='CCG')
        lincs_west = PCT.objects.create(code='04D', org_type='CCG')
        lincs_east = PCT.objects.create(code='03T',
                                        org_type='CCG',
                                        open_date='2013-04-01',
                                        close_date='2015-01-01')
        Chemical.objects.create(bnf_code='0703021Q0', chem_name='Desogestrel')
        Chemical.objects.create(bnf_code='0408010A0',
                                chem_name='Levetiracetam')
        Practice.objects.create(code='C84001',
                                ccg=bassetlaw,
                                name='LARWOOD SURGERY',
                                setting=4)
        Practice.objects.create(code='C84024',
                                ccg=bassetlaw,
                                name='NEWGATE MEDICAL GROUP',
                                setting=4)
        Practice.objects.create(code='B82005',
                                ccg=bassetlaw,
                                name='PRIORY MEDICAL GROUP',
                                setting=4,
                                open_date='2015-01-01')
        Practice.objects.create(code='B82010',
                                ccg=bassetlaw,
                                name='RIPON SPA SURGERY',
                                setting=4)
        Practice.objects.create(code='A85017',
                                ccg=bassetlaw,
                                name='BEWICK ROAD SURGERY',
                                setting=4)
        Practice.objects.create(code='A86030',
                                ccg=bassetlaw,
                                name='BETTS AVENUE MEDICAL GROUP',
                                setting=4)
        Practice.objects.create(code='C83051',
                                ccg=lincs_west,
                                name='ABBEY MEDICAL PRACTICE',
                                setting=4)
        Practice.objects.create(code='C83019',
                                ccg=lincs_east,
                                name='BEACON MEDICAL PRACTICE',
                                setting=4)
        # Ensure we only include open practices in our calculations.
        Practice.objects.create(code='B82008',
                                ccg=bassetlaw,
                                name='NORTH SURGERY',
                                setting=4,
                                open_date='2010-04-01',
                                close_date='2012-01-01')
        # Ensure we only include standard practices in our calculations.
        Practice.objects.create(code='Y00581',
                                ccg=bassetlaw,
                                name='BASSETLAW DRUG & ALCOHOL SERVICE',
                                setting=1)

        args = []
        if 'SKIP_BQ_LOAD' not in os.environ:
            fixtures_base = 'frontend/tests/fixtures/commands/'
            prescribing_fixture = (fixtures_base +
                                   'prescribing_bigquery_fixture.csv')
            practices_fixture = fixtures_base + 'practices.csv'
            bigquery.load_prescribing_data_from_file(
                'measures', settings.BQ_PRESCRIBING_TABLE_NAME,
                prescribing_fixture)
            bigquery.load_data_from_file('measures',
                                         settings.BQ_PRACTICES_TABLE_NAME,
                                         practices_fixture,
                                         bigquery.PRACTICE_SCHEMA)
        month = '2015-09-01'
        measure_id = 'cerazette'
        args = []
        opts = {
            'month': month,
            'measure': measure_id,
            'test_mode': True,
            'v': 3
        }
        call_command('import_measures', *args, **opts)