예제 #1
0
    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)
예제 #2
0
    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()
예제 #3
0
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
예제 #4
0
    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)
예제 #5
0
    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')
예제 #6
0
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 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()
예제 #8
0
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"])
예제 #9
0
    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')
예제 #10
0
    def testSimpleName(self):
        location = make_location(name="Some Location",
                                 domain=self.domain,
                                 location_type="type")

        location.save()

        self.assertEqual(location.site_code, 'some_location')
예제 #11
0
    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)
예제 #12
0
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
예제 #13
0
파일: util.py 프로젝트: kkrampa/commcare-hq
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
예제 #14
0
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
예제 #15
0
    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')
예제 #16
0
    def testSimpleName(self):
        location = make_location(
            name="Some Location",
            domain=self.domain,
            location_type="type"
        )

        location.save()

        self.assertEqual(location.site_code, 'some_location')
예제 #17
0
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
예제 #18
0
 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")
예제 #19
0
    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')
예제 #20
0
    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')
예제 #21
0
    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()
예제 #23
0
    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)
예제 #24
0
    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
        )
예제 #25
0
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"])
예제 #26
0
    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'
        )
예제 #27
0
    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)