def aggregate_state_form_data(): TempPrevUCRTables().make_all_tables(datetime(2017, 3, 31)) TempPrevIntermediateTables().make_all_tables(datetime(2017, 3, 31)) drop_gm_indices(datetime(2017, 3, 31)) for state_id in ('st1', 'st2'): _aggregate_child_health_pnc_forms(state_id, datetime(2017, 3, 31)) _aggregate_gm_forms(state_id, datetime(2017, 3, 31)) _aggregate_bp_forms(state_id, datetime(2017, 3, 31))
def aggregate_state_form_data(): drop_gm_indices(datetime(2017, 3, 31)) for state_id in ('st1', 'st2'): _aggregate_child_health_pnc_forms(state_id, datetime(2017, 3, 31)) _aggregate_gm_forms(state_id, datetime(2017, 3, 31)) _aggregate_bp_forms(state_id, datetime(2017, 3, 31))
def setUpModule(): if settings.USE_PARTITIONED_DATABASE: print( '============= WARNING: not running test setup because settings.USE_PARTITIONED_DATABASE is True.' ) return _call_center_domain_mock = mock.patch( 'corehq.apps.callcenter.data_source.call_center_data_source_configuration_provider' ) _call_center_domain_mock.start() domain = create_domain('icds-cas') location_type = LocationType.objects.create( domain=domain.name, name='block', ) SQLLocation.objects.create(domain=domain.name, name='b1', location_id='b1', location_type=location_type) state_location_type = LocationType.objects.create( domain=domain.name, name='state', ) SQLLocation.objects.create(domain=domain.name, name='st1', location_id='st1', location_type=state_location_type) awc_location_type = LocationType.objects.create( domain=domain.name, name='awc', ) SQLLocation.objects.create(domain=domain.name, name='a7', location_id='a7', location_type=awc_location_type) with override_settings(SERVER_ENVIRONMENT='icds-new'): configs = StaticDataSourceConfiguration.by_domain('icds-cas') adapters = [get_indicator_adapter(config) for config in configs] for adapter in adapters: try: adapter.drop_table() except Exception: pass adapter.build_table() engine = connection_manager.get_engine(ICDS_UCR_ENGINE_ID) metadata = sqlalchemy.MetaData(bind=engine) metadata.reflect(bind=engine, extend_existing=True) path = os.path.join(os.path.dirname(__file__), 'fixtures') for file_name in os.listdir(path): with open(os.path.join(path, file_name), encoding='utf-8') as f: table_name = FILE_NAME_TO_TABLE_MAPPING[file_name[:-4]] table = metadata.tables[table_name] if not table_name.startswith('icds_dashboard_'): postgres_copy.copy_from(f, table, engine, format=b'csv', null=b'', header=True) _aggregate_child_health_pnc_forms('st1', datetime(2017, 3, 31)) try: move_ucr_data_into_aggregation_tables(datetime(2017, 5, 28), intervals=2) except AssertionError as e: # we always use soft assert to email when the aggregation has completed if "Aggregation completed" not in str(e): print(e) tearDownModule() raise except Exception as e: print(e) tearDownModule() raise finally: _call_center_domain_mock.stop() with connections['icds-ucr'].cursor() as cursor: create_views(cursor)
def setUpModule(): if settings.USE_PARTITIONED_DATABASE: print('============= WARNING: not running test setup because settings.USE_PARTITIONED_DATABASE is True.') return _call_center_domain_mock = mock.patch( 'corehq.apps.callcenter.data_source.call_center_data_source_configuration_provider' ) _call_center_domain_mock.start() domain = create_domain('icds-cas') location_type = LocationType.objects.create( domain=domain.name, name='block', ) SQLLocation.objects.create( domain=domain.name, name='b1', location_id='b1', location_type=location_type ) state_location_type = LocationType.objects.create( domain=domain.name, name='state', ) SQLLocation.objects.create( domain=domain.name, name='st1', location_id='st1', location_type=state_location_type ) SQLLocation.objects.create( domain=domain.name, name='st2', location_id='st2', location_type=state_location_type ) SQLLocation.objects.create( domain=domain.name, name='st3', location_id='st3', location_type=state_location_type ) SQLLocation.objects.create( domain=domain.name, name='st4', location_id='st4', location_type=state_location_type ) SQLLocation.objects.create( domain=domain.name, name='st5', location_id='st5', location_type=state_location_type ) SQLLocation.objects.create( domain=domain.name, name='st6', location_id='st6', location_type=state_location_type ) SQLLocation.objects.create( domain=domain.name, name='st7', location_id='st7', location_type=state_location_type ) awc_location_type = LocationType.objects.create( domain=domain.name, name='awc', ) SQLLocation.objects.create( domain=domain.name, name='a7', location_id='a7', location_type=awc_location_type ) with override_settings(SERVER_ENVIRONMENT='icds'): configs = StaticDataSourceConfiguration.by_domain('icds-cas') adapters = [get_indicator_adapter(config) for config in configs] for adapter in adapters: try: adapter.drop_table() except Exception: pass adapter.build_table() engine = connection_manager.get_engine(ICDS_UCR_ENGINE_ID) metadata = sqlalchemy.MetaData(bind=engine) metadata.reflect(bind=engine, extend_existing=True) path = os.path.join(os.path.dirname(__file__), 'fixtures') for file_name in os.listdir(path): with open(os.path.join(path, file_name), encoding='utf-8') as f: table_name = FILE_NAME_TO_TABLE_MAPPING[file_name[:-4]] table = metadata.tables[table_name] if not table_name.startswith('icds_dashboard_'): columns = [ '"{}"'.format(c.strip()) # quote to preserve case for c in f.readline().split(',') ] postgres_copy.copy_from( f, table, engine, format='csv' if six.PY3 else b'csv', null='' if six.PY3 else b'', columns=columns ) for state_id in ('st1', 'st2'): _aggregate_child_health_pnc_forms(state_id, datetime(2017, 3, 31)) _aggregate_gm_forms(state_id, datetime(2017, 3, 31)) _aggregate_bp_forms(state_id, datetime(2017, 3, 31)) try: move_ucr_data_into_aggregation_tables(datetime(2017, 5, 28), intervals=2) build_incentive_report(agg_date=datetime(2017, 5, 28)) except Exception as e: print(e) tearDownModule() raise finally: _call_center_domain_mock.stop()
def setUpModule(): if settings.USE_PARTITIONED_DATABASE: print('============= WARNING: not running test setup because settings.USE_PARTITIONED_DATABASE is True.') return _call_center_domain_mock = mock.patch( 'corehq.apps.callcenter.data_source.call_center_data_source_configuration_provider' ) _call_center_domain_mock.start() # _use_citus.enable() domain = create_domain('icds-cas') SQLLocation.objects.all().delete() LocationType.objects.all().delete() state_location_type = LocationType.objects.create( domain=domain.name, name='state', ) st1 = SQLLocation.objects.create( domain=domain.name, name='st1', location_id='st1', location_type=state_location_type ) st2 = SQLLocation.objects.create( domain=domain.name, name='st2', location_id='st2', location_type=state_location_type ) st3 = SQLLocation.objects.create( domain=domain.name, name='st3', location_id='st3', location_type=state_location_type ) st4 = SQLLocation.objects.create( domain=domain.name, name='st4', location_id='st4', location_type=state_location_type ) st5 = SQLLocation.objects.create( domain=domain.name, name='st5', location_id='st5', location_type=state_location_type ) st6 = SQLLocation.objects.create( domain=domain.name, name='st6', location_id='st6', location_type=state_location_type ) st7 = SQLLocation.objects.create( domain=domain.name, name='st7', location_id='st7', location_type=state_location_type ) supervisor_location_type = LocationType.objects.create( domain=domain.name, name='supervisor', ) s1 = SQLLocation.objects.create( domain=domain.name, name='s1', location_id='s1', location_type=supervisor_location_type, parent=st1 ) block_location_type = LocationType.objects.create( domain=domain.name, name='block', ) b1 = SQLLocation.objects.create( domain=domain.name, name='b1', location_id='b1', location_type=block_location_type, parent=s1 ) awc_location_type = LocationType.objects.create( domain=domain.name, name='awc', ) a7 = SQLLocation.objects.create( domain=domain.name, name='a7', location_id='a7', location_type=awc_location_type ) with override_settings(SERVER_ENVIRONMENT='icds'): configs = StaticDataSourceConfiguration.by_domain('icds-cas') adapters = [get_indicator_adapter(config) for config in configs] for adapter in adapters: try: adapter.drop_table() except Exception: pass adapter.build_table() engine = connection_manager.get_engine(ICDS_UCR_ENGINE_ID) metadata = sqlalchemy.MetaData(bind=engine) metadata.reflect(bind=engine, extend_existing=True) path = os.path.join(os.path.dirname(__file__), 'fixtures') for file_name in os.listdir(path): with open(os.path.join(path, file_name), encoding='utf-8') as f: table_name = FILE_NAME_TO_TABLE_MAPPING[file_name[:-4]] table = metadata.tables[table_name] if not table_name.startswith('icds_dashboard_'): columns = [ '"{}"'.format(c.strip()) # quote to preserve case for c in f.readline().split(',') ] postgres_copy.copy_from( f, table, engine, format='csv' if six.PY3 else b'csv', null='' if six.PY3 else b'', columns=columns ) _distribute_tables_for_citus(engine) for state_id in ('st1', 'st2'): _aggregate_child_health_pnc_forms(state_id, datetime(2017, 3, 31)) _aggregate_gm_forms(state_id, datetime(2017, 3, 31)) _aggregate_bp_forms(state_id, datetime(2017, 3, 31)) try: move_ucr_data_into_aggregation_tables(datetime(2017, 5, 28), intervals=2) build_incentive_report(agg_date=datetime(2017, 5, 28)) except Exception as e: print(e) tearDownModule() raise finally: _call_center_domain_mock.stop()