def setUpClass(cls): super(IntraHealthTestCase, cls).setUpClass() cls.session_helper = connection_manager.get_session_helper( settings.SQL_REPORTING_DATABASE_URL) cls.engine = cls.session_helper.engine cls.domain = create_domain(TEST_DOMAIN) cls.region_type = LocationType.objects.create(domain=TEST_DOMAIN, name=u'Région') cls.district_type = LocationType.objects.create(domain=TEST_DOMAIN, name=u'District') cls.pps_type = LocationType.objects.create(domain=TEST_DOMAIN, name=u'PPS') cls.region = make_location(domain=TEST_DOMAIN, name='Test region', location_type=u'Région') cls.region.save() cls.district = make_location(domain=TEST_DOMAIN, name='Test district', location_type=u'District', parent=cls.region) cls.district.save() cls.pps = make_location(domain=TEST_DOMAIN, name='Test PPS', location_type=u'PPS', parent=cls.district) cls.pps.save() cls.mobile_worker = create_mobile_worker(domain=TEST_DOMAIN, username='******', password='******', phone_number='777777') cls.mobile_worker.location_id = cls.pps.get_id cls.mobile_worker.save() cls.product = Product(_id=u'81457658bdedd663f8b0bdadb19d8f22', name=u'ASAQ Nourisson', domain=TEST_DOMAIN) cls.product2 = Product(_id=u'81457658bdedd663f8b0bdadb19d83d8', name=u'ASAQ Petit Enfant', domain=TEST_DOMAIN) cls.product.save() cls.product2.save() cls.recap_table = RecapPassageFluff._table cls.intra_table = IntraHealthFluff._table cls.taux_rupt_table = TauxDeRuptureFluff._table cls.livraison_table = LivraisonFluff._table cls.taux_sat_table = TauxDeSatisfactionFluff._table cls.couverture_table = CouvertureFluff._table with cls.engine.begin() as connection: cls.recap_table.create(connection, checkfirst=True) cls.intra_table.create(connection, checkfirst=True) cls.taux_rupt_table.create(connection, checkfirst=True) cls.livraison_table.create(connection, checkfirst=True) cls.taux_sat_table.create(connection, checkfirst=True) cls.couverture_table.create(connection, checkfirst=True)
def test_app_manager(self): for domain_name in [self.domain.name, self.domain2.name]: location = make_location( domain=domain_name, site_code='testcode', name='test', location_type='facility' ) location.save() AppReleaseByLocation.objects.create(domain=domain_name, app_id='123', build_id='456', version=23, location=location) with patch('corehq.apps.app_manager.models.GlobalAppConfig.by_app_id'): LatestEnabledBuildProfiles.objects.create(domain=domain_name, app_id='123', build_id='456', version=10) GlobalAppConfig.objects.create(domain=domain_name, app_id='123') ResourceOverride.objects.create(domain=domain_name, app_id='123', root_name='test', pre_id='456', post_id='789') self._assert_app_manager_counts(domain_name, 1) self.domain.delete() self._assert_app_manager_counts(self.domain.name, 0) self._assert_app_manager_counts(self.domain2.name, 1) location.delete()
def make_loc(code, name, domain, type, metadata=None, parent=None): name = name or code LocationType.objects.get(domain=domain, name=type) loc = make_location(site_code=code, name=name, domain=domain, location_type=type, parent=parent) loc.metadata = metadata or {} loc.save() return loc
def _create_data(self, domain_name, i): product = Product(domain=domain_name, name='test-{}'.format(i)) product.save() location = make_location(domain=domain_name, site_code='testcode-{}'.format(i), name='test-{}'.format(i), location_type='facility') location.save() report = StockReport.objects.create( type='balance', domain=domain_name, form_id='fake', date=datetime.utcnow(), server_date=datetime.utcnow(), ) StockTransaction.objects.create( report=report, product_id=product.get_id, sql_product=SQLProduct.objects.get(product_id=product.get_id), section_id='stock', type='stockonhand', case_id=location.linked_supply_point().get_id, stock_on_hand=100) SMS.objects.create(domain=domain_name) Call.objects.create(domain=domain_name) SQLLastReadMessage.objects.create(domain=domain_name) ExpectedCallback.objects.create(domain=domain_name) PhoneNumber.objects.create(domain=domain_name, is_two_way=False, pending_verification=False) event = MessagingEvent.objects.create( domain=domain_name, date=datetime.utcnow(), source=MessagingEvent.SOURCE_REMINDER, content_type=MessagingEvent.CONTENT_SMS, status=MessagingEvent.STATUS_COMPLETED) MessagingSubEvent.objects.create( parent=event, date=datetime.utcnow(), recipient_type=MessagingEvent.RECIPIENT_CASE, content_type=MessagingEvent.CONTENT_SMS, status=MessagingEvent.STATUS_COMPLETED) SelfRegistrationInvitation.objects.create( domain=domain_name, phone_number='999123', token=uuid.uuid4().hex, expiration_date=datetime.utcnow().date(), created_date=datetime.utcnow()) backend = SQLMobileBackend.objects.create(domain=domain_name, is_global=False) SQLMobileBackendMapping.objects.create( domain=domain_name, backend_type=SQLMobileBackend.SMS, prefix=str(i), backend=backend) MobileBackendInvitation.objects.create(domain=domain_name, backend=backend)
def testDoesntDuplicate(self): location = make_location(name="Location", domain=self.domain, location_type="type") location.save() self.assertEqual(location.site_code, 'location') location = make_location(name="Location", domain=self.domain, location_type="type") location.save() self.assertEqual(location.site_code, 'location1')
def setUpClass(cls): super(UpdateLocationKeywordTest, cls).setUpClass() cls.domain = "opt-test" cls.domain_obj = Domain(name=cls.domain) cls.domain_obj.save() cls.setup_subscription(cls.domain_obj.name, SoftwarePlanEdition.ADVANCED) cls.backend, cls.backend_mapping = setup_default_sms_test_backend() cls.user = create_mobile_worker(cls.domain, 'test', '*****', '4444') cls.location_type = LocationType.objects.create( domain=cls.domain, name='test' ) cls.location = make_location( domain=cls.domain, name='test', site_code='site_code', location_type='test' ) cls.location.save()
def create_test_locations(domain): country = make_location(name='national', site_code='ghana', location_type='country', domain=domain) country.save() crms = make_location(name='Central Regional Medical Store', site_code='crms', location_type='country', domain=domain) crms.save() test_region = make_location(name='Test Region', site_code='testregion', location_type='region', domain=domain, parent=country) test_region.save() test_region2 = make_location(name='Test Region2', site_code='testregion2', location_type='region', domain=domain, parent=country) test_region2.save() rsp = make_location(name='Test Regional Medical Store', site_code='rsp', location_type='Regional Medical Store', domain=domain, parent=test_region2) rsp.save() assign_products_to_locations(rsp, ["ad", "al", "mc", "ng", "mg"]) rsp2 = make_location(name='Test Regional Medical Store', site_code='rsp2', location_type='Regional Medical Store', domain=domain, parent=test_region2) rsp2.save() assign_products_to_locations(rsp2, ["ad", "al"]) test_district = make_location(name='Test District', site_code='testdistrict', location_type='district', domain=domain, parent=test_region) test_district.save() test_facility = make_location(name='Active Test hospital', site_code='tsactive', location_type='Hospital', domain=domain, parent=test_district) test_facility.save() assign_products_to_locations(test_facility, ["ad", "al"])
def testOtherCharacters(self): location = make_location(name=u"Somé$ #Location (Old)", domain=self.domain, location_type="type") location.save() self.assertEqual(location.site_code, 'some_location_old')
def testSimpleName(self): location = make_location(name="Some Location", domain=self.domain, location_type="type") location.save() self.assertEqual(location.site_code, 'some_location')
def setUpClass(cls): super(IntraHealthTestCase, cls).setUpClass() cls.engine = connection_manager.get_engine('default') cls.domain = create_domain(TEST_DOMAIN) cls.region_type = LocationType.objects.create(domain=TEST_DOMAIN, name='Région') cls.district_type = LocationType.objects.create(domain=TEST_DOMAIN, name='District') cls.pps_type = LocationType.objects.create(domain=TEST_DOMAIN, name='PPS') cls.region = make_location(domain=TEST_DOMAIN, name='Test region', location_type='Région') cls.region.save() cls.district = make_location( domain=TEST_DOMAIN, name='Test district', location_type='District', parent=cls.region ) cls.district.save() cls.pps = make_location(domain=TEST_DOMAIN, name='Test PPS', location_type='PPS', parent=cls.district) cls.pps.save() cls.mobile_worker = create_mobile_worker( domain=TEST_DOMAIN, username='******', password='******', phone_number='777777' ) cls.mobile_worker.location_id = cls.pps.get_id cls.mobile_worker.save() cls.product = Product(_id='81457658bdedd663f8b0bdadb19d8f22', name='ASAQ Nourisson', domain=TEST_DOMAIN) cls.product2 = Product( _id='81457658bdedd663f8b0bdadb19d83d8', name='ASAQ Petit Enfant', domain=TEST_DOMAIN ) cls.product.save() cls.product2.save() cls.recap_table = RecapPassageFluff._table cls.intra_table = IntraHealthFluff._table cls.taux_rupt_table = TauxDeRuptureFluff._table cls.livraison_table = LivraisonFluff._table cls.taux_sat_table = TauxDeSatisfactionFluff._table cls.couverture_table = CouvertureFluff._table with cls.engine.begin() as connection: cls.recap_table.create(connection, checkfirst=True) cls.intra_table.create(connection, checkfirst=True) cls.taux_rupt_table.create(connection, checkfirst=True) cls.livraison_table.create(connection, checkfirst=True) cls.taux_sat_table.create(connection, checkfirst=True) cls.couverture_table.create(connection, checkfirst=True)
def make_loc(code, name=None, domain=TEST_DOMAIN, type=TEST_LOCATION_TYPE, parent=None): if not Domain.get_by_name(domain): raise AssertionError("You can't make a location on a fake domain") name = name or code LocationType.objects.get_or_create(domain=domain, name=type, defaults={'administrative': False}) loc = make_location(site_code=code, name=name, domain=domain, location_type=type, parent=parent) loc.save() return loc
def make_loc(code, name, domain, type, parent=None): name = name or code sql_type, _ = LocationType.objects.get_or_create(domain=domain, name=type) loc = make_location(site_code=code, name=name, domain=domain, location_type=type, parent=parent) loc.save() sql_location = loc.sql_location sql_location.products = [] sql_location.save() return loc
def testOtherCharacters(self): location = make_location( name="Somé$ #Location (Old)", domain=self.domain, location_type="type" ) location.save() self.assertEqual(location.site_code, 'some_location_old')
def testSimpleName(self): location = make_location( name="Some Location", domain=self.domain, location_type="type" ) location.save() self.assertEqual(location.site_code, 'some_location')
def test_location(self): loc_type = LocationType(domain=self.domain, name='type') loc_type.save() self.addCleanup(loc_type.delete) location = make_location(domain=self.domain, site_code='doc_info_test', name='doc_info_test', location_type='type') location.save() self.addCleanup(location.delete) self._test_doc(location.location_id, "Location")
def testDoesntDuplicate(self): location = make_location( name="Location", domain=self.domain, location_type="type" ) location.save() self.assertEqual(location.site_code, 'location') location = make_location( name="Location", domain=self.domain, location_type="type" ) location.save() self.assertEqual(location.site_code, 'location1')
def _create_data(self, domain_name): product = Product(domain=domain_name, name='test-product') product.save() location = make_location(domain=domain_name, site_code='testcode', name='test1', location_type='facility') location.save() self.locations[domain_name] = location.get_id DeliveryGroupReport.objects.create(location_id=location.get_id, quantity=1, message='test', delivery_group='A') Alert.objects.create(text='test', expires=datetime.utcnow(), date=datetime.utcnow(), location_id=location.get_id) organization_summary = OrganizationSummary.objects.create( date=datetime.utcnow(), location_id=location.get_id) GroupSummary.objects.create(org_summary=organization_summary) ProductAvailabilityData.objects.create(product=product.get_id, date=datetime.utcnow(), location_id=location.get_id) SupplyPointStatus.objects.create(location_id=location.get_id, status_type='del_fac', status_value='received') ReportRun.objects.create(domain=domain_name, start=datetime.utcnow(), end=datetime.utcnow(), start_run=datetime.utcnow()) ILSNotes.objects.create(location=location.sql_location, domain=domain_name, user_name='test', date=datetime.utcnow(), text='test') SupervisionDocument.objects.create(domain=domain_name, document='test', data_type='test', name='test')
def _create_data(self, domain_name): product = Product(domain=domain_name, name='test-product') product.save() location = make_location(domain=domain_name, site_code='testcode', name='test1', location_type='facility') location.save() self.locations[domain_name] = location.sql_location user = CommCareUser.create(domain=domain_name, username='******'.format(domain_name), password='******') FacilityInCharge.objects.create(user_id=user.get_id, location=location.sql_location)
def setUpClass(cls): super(UpdateLocationKeywordTest, cls).setUpClass() cls.domain = "opt-test" cls.domain_obj = Domain(name=cls.domain) cls.domain_obj.save() cls.setup_subscription(cls.domain_obj.name, SoftwarePlanEdition.ADVANCED) cls.backend, cls.backend_mapping = setup_default_sms_test_backend() cls.user = create_mobile_worker(cls.domain, 'test', '*****', '4444') cls.location_type = LocationType.objects.create(domain=cls.domain, name='test') cls.location = make_location(domain=cls.domain, name='test', site_code='site_code', location_type='test') cls.location.save()
def _create_data(self, domain_name, i): product = Product(domain=domain_name, name='test-{}'.format(i)) product.save() location = make_location(domain=domain_name, site_code='testcode-{}'.format(i), name='test-{}'.format(i), location_type='facility') location.save() SMS.objects.create(domain=domain_name) Call.objects.create(domain=domain_name) SQLLastReadMessage.objects.create(domain=domain_name) ExpectedCallback.objects.create(domain=domain_name) PhoneNumber.objects.create(domain=domain_name, is_two_way=False, pending_verification=False) event = MessagingEvent.objects.create( domain=domain_name, date=datetime.utcnow(), source=MessagingEvent.SOURCE_REMINDER, content_type=MessagingEvent.CONTENT_SMS, status=MessagingEvent.STATUS_COMPLETED) MessagingSubEvent.objects.create( parent=event, date=datetime.utcnow(), recipient_type=MessagingEvent.RECIPIENT_CASE, content_type=MessagingEvent.CONTENT_SMS, status=MessagingEvent.STATUS_COMPLETED) backend = SQLMobileBackend.objects.create(domain=domain_name, is_global=False) SQLMobileBackendMapping.objects.create( domain=domain_name, backend_type=SQLMobileBackend.SMS, prefix=str(i), backend=backend) MobileBackendInvitation.objects.create(domain=domain_name, backend=backend)
def _create_data(self, domain_name): product = Product(domain=domain_name, name='test-product') product.save() location = make_location( domain=domain_name, site_code='testcode', name='test1', location_type='facility' ) location.save() self.locations[domain_name] = location.sql_location user = CommCareUser.create( domain=domain_name, username='******'.format(domain_name), password='******' ) FacilityInCharge.objects.create( user_id=user.get_id, location=location.sql_location )
def create_test_locations(domain): country = make_location(name='national', site_code='ghana', location_type='country', domain=domain) country.save() crms = make_location( name='Central Regional Medical Store', site_code='crms', location_type='country', domain=domain ) crms.save() test_region = make_location( name='Test Region', site_code='testregion', location_type='region', domain=domain, parent=country ) test_region.save() test_region2 = make_location( name='Test Region2', site_code='testregion2', location_type='region', domain=domain, parent=country ) test_region2.save() rsp = make_location( name='Test Regional Medical Store', site_code='rsp', location_type='Regional Medical Store', domain=domain, parent=test_region2 ) rsp.save() assign_products_to_locations(rsp, ["ad", "al", "mc", "ng", "mg"]) rsp2 = make_location( name='Test Regional Medical Store', site_code='rsp2', location_type='Regional Medical Store', domain=domain, parent=test_region2 ) rsp2.save() assign_products_to_locations(rsp2, ["ad", "al"]) test_district = make_location( name='Test District', site_code='testdistrict', location_type='district', domain=domain, parent=test_region ) test_district.save() test_facility = make_location( name='Active Test hospital', site_code='tsactive', location_type='Hospital', domain=domain, parent=test_district ) test_facility.save() assign_products_to_locations(test_facility, ["ad", "al"])
def _create_data(self, domain_name): product = Product(domain=domain_name, name='test-product') product.save() location = make_location( domain=domain_name, site_code='testcode', name='test1', location_type='facility' ) location.save() self.locations[domain_name] = location.get_id DeliveryGroupReport.objects.create( location_id=location.get_id, quantity=1, message='test', delivery_group='A' ) Alert.objects.create( text='test', expires=datetime.utcnow(), date=datetime.utcnow(), location_id=location.get_id ) organization_summary = OrganizationSummary.objects.create( date=datetime.utcnow(), location_id=location.get_id ) GroupSummary.objects.create( org_summary=organization_summary ) ProductAvailabilityData.objects.create( product=product.get_id, date=datetime.utcnow(), location_id=location.get_id ) SupplyPointStatus.objects.create( location_id=location.get_id, status_type='del_fac', status_value='received' ) ReportRun.objects.create( domain=domain_name, start=datetime.utcnow(), end=datetime.utcnow(), start_run=datetime.utcnow() ) ILSNotes.objects.create( location=location.sql_location, domain=domain_name, user_name='test', date=datetime.utcnow(), text='test' ) SupervisionDocument.objects.create( domain=domain_name, document='test', data_type='test', name='test' )
def _create_data(self, domain_name, i): product = Product(domain=domain_name, name='test-{}'.format(i)) product.save() location = make_location( domain=domain_name, site_code='testcode-{}'.format(i), name='test-{}'.format(i), location_type='facility' ) location.save() report = StockReport.objects.create( type='balance', domain=domain_name, form_id='fake', date=datetime.utcnow(), server_date=datetime.utcnow(), ) StockTransaction.objects.create( report=report, product_id=product.get_id, sql_product=SQLProduct.objects.get(product_id=product.get_id), section_id='stock', type='stockonhand', case_id=location.linked_supply_point().get_id, stock_on_hand=100 ) SMS.objects.create(domain=domain_name) Call.objects.create(domain=domain_name) SQLLastReadMessage.objects.create(domain=domain_name) ExpectedCallback.objects.create(domain=domain_name) PhoneNumber.objects.create(domain=domain_name, is_two_way=False, pending_verification=False) event = MessagingEvent.objects.create( domain=domain_name, date=datetime.utcnow(), source=MessagingEvent.SOURCE_REMINDER, content_type=MessagingEvent.CONTENT_SMS, status=MessagingEvent.STATUS_COMPLETED ) MessagingSubEvent.objects.create( parent=event, date=datetime.utcnow(), recipient_type=MessagingEvent.RECIPIENT_CASE, content_type=MessagingEvent.CONTENT_SMS, status=MessagingEvent.STATUS_COMPLETED ) SelfRegistrationInvitation.objects.create( domain=domain_name, phone_number='999123', token=uuid.uuid4().hex, expiration_date=datetime.utcnow().date(), created_date=datetime.utcnow() ) backend = SQLMobileBackend.objects.create(domain=domain_name, is_global=False) SQLMobileBackendMapping.objects.create( domain=domain_name, backend_type=SQLMobileBackend.SMS, prefix=str(i), backend=backend ) MobileBackendInvitation.objects.create(domain=domain_name, backend=backend)