def test_incomplete_with_filter(self): """ User with product type filter will get notification all products of that type are missing reports. """ self.user.get_domain_membership( self.TEST_DOMAIN).program_id = self.program.get_id self.user.save() self.product.program_id = self.program.get_id self.product.save() create_stock_report(self.facility, {'tp': 100}, date=datetime.utcnow() - timedelta(days=365)) other_product = Product(domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each', program_id=self.program.get_id) other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) generated = list( OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
def make_product(domain, name, code): p = Product() p.domain = domain p.name = name p.code = code.lower() p.save() return p
def setUpClass(cls): domain = prepare_domain(TEST_DOMAIN) mohsw = make_loc(code="moh1", name="Test MOHSW 1", type="MOHSW", domain=domain.name) region = make_loc(code="reg1", name="Test Region 1", type="REGION", domain=domain.name, parent=mohsw) district = make_loc(code="dis1", name="Test District 1", type="DISTRICT", domain=domain.name, parent=region) facility = make_loc(code="loc1", name="Test Facility 1", type="FACILITY", domain=domain.name, parent=district) facility2 = make_loc(code="loc2", name="Test Facility 2", type="FACILITY", domain=domain.name, parent=district) test.bootstrap(TEST_BACKEND, to_console=True) bootstrap_user(facility, username='******', domain=domain.name, home_loc='loc1', phone_number='5551234', first_name='stella', last_name='Test') bootstrap_user(facility2, username='******', domain=domain.name, home_loc='loc2', phone_number='5555678', first_name='bella', last_name='Test') bootstrap_user(district, username='******', domain=domain.name, home_loc='dis1', phone_number='555', first_name='trella', last_name='Test') bootstrap_user(district, username='******', domain=domain.name, phone_number='111', first_name='MSD', last_name='Person', user_data={'role': 'MSD'}) p = Product(domain=domain.name, name='Jadelle', code='jd', unit='each') p.save() p2 = Product(domain=domain.name, name='Mc', code='mc', unit='each') p2.save()
def create_test_products(domain): program = Program(domain=domain, name='HIV/AIDS', code='hiv') program.save() abacavir = Product( domain=domain, name="Abacavir 300mg", code_="abc", program_id=program.get_id, ) abacavir.save() ali = Product( domain=domain, name="AL 20mg/120mg 1X6", code_="ali", program_id=program.get_id, ) ali.save() al = Product(domain=domain, name="AL 20mg/120mg 4x6", code_="alk") al.save() ad = Product(domain=domain, name="A-L Dispersible", code_="ad") ad.save() al = Product(domain=domain, name="A-L Suspension", code_="al") al.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() 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 make_product(domain, name, code): p = Product() p.domain = domain p.name = name p.code = code.lower() p.save() return p
def test_product_type_filter(self): """User can recieve missing notifications for only certain product type.""" bootstrap_web_user(username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district, password='******', email='*****@*****.**', user_data={}, program_id=self.program.get_id) other_product = Product(domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each') other_product2 = Product(domain=self.TEST_DOMAIN, name='Test Product3', code_='tp3', unit='each') other_product.save() other_product2.save() assign_products_to_location( self.facility, [self.product, other_product, other_product2]) generated = list( OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
def _create_data(self, domain_name, i): product = Product(domain=domain_name, name='test-{}'.format(i)) product.save() location = Location( domain=domain_name, site_code='testcode-{}'.format(i), name='test-{}'.format(i), location_type='facility' ) location.save() SupplyPointCase.create_from_location(domain_name, location) report = StockReport.objects.create( type='balance', domain=domain_name, form_id='fake', 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 )
def make_product(domain, name, code, program_id): p = Product() p.domain = domain p.name = name p.code = code.lower() p.program_id = program_id p.save() return p
def make_product(domain, name, code, program_id): p = Product() p.domain = domain p.name = name p.code = code.lower() p.program_id = program_id p.save() return p
def create_products(cls, domain_name, codes): for code in codes: product = Product(domain=domain_name, name=code, code=code, unit='each') product.save() setattr(cls, code, product)
def _create_data(self, domain_name): product = Product(domain=domain_name, name='test-product') product.save() location = 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') SupplyPointWarehouseRecord.objects.create( supply_point=location.get_id, create_date=datetime.utcnow()) 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') HistoricalLocationGroup.objects.create( location_id=location.sql_location, group='A', date=datetime.utcnow().date()) 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')
class EWSTestReminders(TestCase): """Moved from EWS""" @classmethod def setUpClass(cls): cls.domain = prepare_domain(TEST_DOMAIN) cls.sms_backend_mapping, cls.backend = create_backend() def setUp(self): self.facility = make_loc('test-faciity', 'Test Facility', TEST_DOMAIN, 'Polyclinic') self.commodity = Product(domain=TEST_DOMAIN, name='Drug A', code_='ab', unit='cycle') self.commodity.save() self.commodity2 = Product(domain=TEST_DOMAIN, name='Drug B', code_='cd', unit='cycle') self.commodity2.save() self.sql_facility = self.facility.sql_location self.sql_facility.products = [] self.sql_facility.save() def test_reminders(self): products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertEqual(len(products_reported), 0) self.assertEqual(len(products_not_reported), 0) assign_products_to_location(self.facility, [self.commodity]) products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertEqual(len(products_reported), 0) sql_commodity = SQLProduct.objects.get(product_id=self.commodity.get_id) self.assertEqual(products_not_reported[0], sql_commodity) sql_commodity2 = SQLProduct.objects.get(product_id=self.commodity2.get_id) create_stock_report(self.facility, {'ab': 10}) products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertEqual(products_reported[0], sql_commodity) self.assertEqual(len(products_not_reported), 0) assign_products_to_location(self.facility, [self.commodity, self.commodity2]) products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertEqual(products_reported[0], sql_commodity) self.assertEqual(products_not_reported[0], sql_commodity2) create_stock_report(self.facility, {'cd': 10}) products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertTrue(sql_commodity in products_reported) self.assertTrue(sql_commodity2 in products_reported) self.assertEqual(len(products_not_reported), 0) @classmethod def tearDownClass(cls): cls.backend.delete() cls.sms_backend_mapping.delete()
def _create_data(self, domain_name): product = Product(domain=domain_name, name="test-product") product.save() location = 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 test_incomplete_report2(self): create_stock_report(self.facility, {'tp': 100}, date=datetime.utcnow()) self.product.program_id = self.program2.get_id self.product.save() other_product = Product( domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each', program_id=self.program.get_id ) other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0)
def setUpClass(cls): domain = prepare_domain(TEST_DOMAIN) p = Product(domain=domain.name, name='Jadelle', code='jd', unit='each') p.save() p2 = Product(domain=domain.name, name='Male Condom', code='mc', unit='each') p2.save() p3 = Product(domain=domain.name, name='Lofem', code='lf', unit='each') p3.save() p4 = Product(domain=domain.name, name='Ng', code='ng', unit='each') p4.save() p5 = Product(domain=domain.name, name='Micro-G', code='mg', unit='each') p5.save() loc = make_loc(code="garms", name="Test RMS", type="Regional Medical Store", domain=domain.name) test.bootstrap(TEST_BACKEND, to_console=True) cls.user1 = bootstrap_user(username='******', first_name='test1', last_name='test1', domain=domain.name, home_loc=loc) cls.user2 = bootstrap_user(username='******', domain=domain.name, home_loc=loc, first_name='test2', last_name='test2', phone_number='222222', user_data={'role': 'In Charge'}) try: XFormInstance.get(docid='test-xform') except ResourceNotFound: xform = XFormInstance(_id='test-xform') xform.save() sql_location = loc.sql_location sql_location.products = SQLProduct.objects.filter(product_id=p5.get_id) sql_location.save() config = CommtrackConfig.for_domain(domain.name) config.actions.append( CommtrackActionConfig(action='receipts', keyword='rec', caption='receipts')) config.consumption_config = ConsumptionConfig(min_transactions=0, min_window=0, optimal_window=60) config.save()
def test_incomplete_report2(self): create_stock_report(self.facility, {'tp': 100}, date=datetime.utcnow()) self.product.program_id = self.program2.get_id self.product.save() other_product = Product( domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each', program_id=self.program.get_id ) other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0)
def test_partial_product_stockout(self): """Multiple products but only one is stocked out. Should be reported.""" other_product = Product(domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each') other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.facility, {'tp2': 10}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
def test_partial_product_stockout(self): """Multiple products but only one is stocked out. Should be reported.""" other_product = Product(domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each') other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.facility, {'tp2': 10}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
class EWSTestReminders(EWSTestCase): """Moved from EWS""" @classmethod def setUpClass(cls): super(EWSTestReminders, cls).setUpClass() cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend() cls.domain = prepare_domain(TEST_DOMAIN) def setUp(self): super(EWSTestReminders, self).setUp() self.facility = make_loc('test-faciity', 'Test Facility', TEST_DOMAIN, 'Polyclinic') self.commodity = Product(domain=TEST_DOMAIN, name='Drug A', code_='ab', unit='cycle') self.commodity.save() self.commodity2 = Product(domain=TEST_DOMAIN, name='Drug B', code_='cd', unit='cycle') self.commodity2.save() self.sql_facility = self.facility.sql_location self.sql_facility.products = [] self.sql_facility.save() def test_reminders(self): products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertEqual(len(products_reported), 0) self.assertEqual(len(products_not_reported), 0) assign_products_to_location(self.facility, [self.commodity]) products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertEqual(len(products_reported), 0) sql_commodity = SQLProduct.objects.get(product_id=self.commodity.get_id) self.assertEqual(products_not_reported[0], sql_commodity) sql_commodity2 = SQLProduct.objects.get(product_id=self.commodity2.get_id) create_stock_report(self.facility, {'ab': 10}) products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertEqual(products_reported[0], sql_commodity) self.assertEqual(len(products_not_reported), 0) assign_products_to_location(self.facility, [self.commodity, self.commodity2]) products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertEqual(products_reported[0], sql_commodity) self.assertEqual(products_not_reported[0], sql_commodity2) create_stock_report(self.facility, {'cd': 10}) products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertTrue(sql_commodity in products_reported) self.assertTrue(sql_commodity2 in products_reported) self.assertEqual(len(products_not_reported), 0)
def product_sync(self, ilsgateway_product): product = Product.get_by_code(self.domain, ilsgateway_product.sms_code) product_dict = { 'domain': self.domain, 'name': ilsgateway_product.name, 'code': ilsgateway_product.sms_code, 'unit': str(ilsgateway_product.units), 'description': ilsgateway_product.description, } if product is None: product = Product(**product_dict) product.save() else: if apply_updates(product, product_dict): product.save() return product
def product_sync(self, ilsgateway_product): product = Product.get_by_code(self.domain, ilsgateway_product.sms_code) product_dict = { "domain": self.domain, "name": ilsgateway_product.name, "code": ilsgateway_product.sms_code, "unit": str(ilsgateway_product.units), "description": ilsgateway_product.description, } if product is None: product = Product(**product_dict) product.save() else: if apply_updates(product, product_dict): product.save() return product
def product_sync(self, ilsgateway_product): product = Product.get_by_code(self.domain, ilsgateway_product.sms_code) product_dict = { 'domain': self.domain, 'name': ilsgateway_product.name, 'code': ilsgateway_product.sms_code, 'unit': str(ilsgateway_product.units), 'description': ilsgateway_product.description, } if product is None: product = Product(**product_dict) product.save() else: if apply_updates(product, product_dict): product.save() return product
def test_product_type_filter(self): """User can recieve missing notifications for only certain product type.""" bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district, password='******', email='*****@*****.**', user_data={}, program_id=self.program.get_id ) other_product = Product(domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each') other_product2 = Product(domain=self.TEST_DOMAIN, name='Test Product3', code_='tp3', unit='each') other_product.save() other_product2.save() assign_products_to_location(self.facility, [self.product, other_product, other_product2]) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
def _create_data(self, domain_name): product = Product(domain=domain_name, name='test-product') product.save() location = 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 createProducts(self): with open(os.path.join(self.datapath, "sample_product_1.json")) as f: lmis_product_1 = json.loads(f.read()) with open(os.path.join(self.datapath, "sample_product_2.json")) as f: lmis_product_2 = json.loads(f.read()) lmis_product_1["program_id"] = self.program._id lmis_product_2["program_id"] = self.program._id product_1 = Product(lmis_product_1) product_2 = Product(lmis_product_2) product_1.save() product_2.save() self.products = [] self.products.append(product_1) self.products.append(product_2)
def sync_openlmis_product(domain, program, lmis_product): product = get_product(domain, lmis_product) product_dict = { 'domain': domain, 'name': lmis_product.name, 'code': lmis_product.code, 'unit': str(lmis_product.unit), 'description': lmis_product.description, 'category': lmis_product.category, 'program_id': program._id, } if product is None: product = Product(**product_dict) product.save() else: if apply_updates(product, product_dict): product.save() return product
def sync_openlmis_product(domain, program, lmis_product): product = get_product(domain, lmis_product) product_dict = { 'domain': domain, 'name': lmis_product.name, 'code': lmis_product.code, 'unit': str(lmis_product.unit), 'description': lmis_product.description, 'category': lmis_product.category, 'program_id': program._id, } if product is None: product = Product(**product_dict) product.save() else: if apply_updates(product, product_dict): product.save() return product
def create_product(cls, code, schedule, valid, expires, predecessor_id='', days_after_previous='', schedule_flag=''): p = Product(domain=cls.domain, name=code, code=code, product_data={ 'schedule': schedule, 'valid': valid, 'expires': expires, 'predecessor_id': predecessor_id, 'days_after_previous': days_after_previous, 'schedule_flag': schedule_flag, }) p.save() return p
def create_test_products(domain): program = Program(domain=domain, name='HIV/AIDS', code='hiv') program.save() abacavir = Product( domain=domain, name="Abacavir 300mg", code_="abc", program_id=program.get_id, ) abacavir.save() ali = Product( domain=domain, name="AL 20mg/120mg 1X6", code_="ali", program_id=program.get_id, ) ali.save() al = Product( domain=domain, name="AL 20mg/120mg 4x6", code_="alk" ) al.save() ad = Product( domain=domain, name="A-L Dispersible", code_="ad" ) ad.save() al = Product( domain=domain, name="A-L Suspension", code_="al" ) al.save()
def test_incomplete_with_filter(self): """ User with product type filter will get notification all products of that type are missing reports. """ self.user.get_domain_membership(self.TEST_DOMAIN).program_id = self.program.get_id self.user.save() self.product.program_id = self.program.get_id self.product.save() create_stock_report(self.facility, {'tp': 100}, date=datetime.utcnow() - timedelta(days=365)) other_product = Product( domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each', program_id=self.program.get_id ) other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
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 setUpClass(cls): domain = prepare_domain(TEST_DOMAIN) p = Product(domain=domain.name, name='Jadelle', code='jd', unit='each') p.save() p2 = Product(domain=domain.name, name='Male Condom', code='mc', unit='each') p2.save() p3 = Product(domain=domain.name, name='Lofem', code='lf', unit='each') p3.save() p4 = Product(domain=domain.name, name='Ng', code='ng', unit='each') p4.save() p5 = Product(domain=domain.name, name='Micro-G', code='mg', unit='each') p5.save() loc = make_loc(code="garms", name="Test RMS", type="Regional Medical Store", domain=domain.name) test.bootstrap(TEST_BACKEND, to_console=True) cls.user1 = bootstrap_user(username='******', first_name='test1', last_name='test1', domain=domain.name, home_loc=loc) cls.user2 = bootstrap_user(username='******', domain=domain.name, home_loc=loc, first_name='test2', last_name='test2', phone_number='222222', user_data={'role': 'In Charge'}) try: XFormInstance.get(docid='test-xform') except ResourceNotFound: xform = XFormInstance(_id='test-xform') xform.save() sql_location = loc.sql_location sql_location.products = SQLProduct.objects.filter(product_id=p5.get_id) sql_location.save() config = CommtrackConfig.for_domain(domain.name) config.actions.append( CommtrackActionConfig( action='receipts', keyword='rec', caption='receipts' ) ) config.consumption_config = ConsumptionConfig(min_transactions=0, min_window=0, optimal_window=60) config.save()
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_data(self, domain_name, i): product = Product(domain=domain_name, name='test-{}'.format(i)) product.save() location = Location(domain=domain_name, site_code='testcode-{}'.format(i), name='test-{}'.format(i), location_type='facility') location.save() SupplyPointCase.create_from_location(domain_name, location) report = StockReport.objects.create(type='balance', domain=domain_name, form_id='fake', 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)
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 setUpClass(cls): super(EWSScriptTest, cls).setUpClass() cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend() domain = prepare_domain(TEST_DOMAIN) p = Product(domain=domain.name, name='Jadelle', code='jd', unit='each') p.save() p2 = Product(domain=domain.name, name='Male Condom', code='mc', unit='each') p2.save() p3 = Product(domain=domain.name, name='Lofem', code='lf', unit='each') p3.save() p4 = Product(domain=domain.name, name='Ng', code='ng', unit='each') p4.save() p5 = Product(domain=domain.name, name='Micro-G', code='mg', unit='each') p5.save() Product(domain=domain.name, name='Ad', code='ad', unit='each').save() Product(domain=domain.name, name='Al', code='al', unit='each').save() Product(domain=domain.name, name='Qu', code='qu', unit='each').save() Product(domain=domain.name, name='Sp', code='sp', unit='each').save() Product(domain=domain.name, name='Rd', code='rd', unit='each').save() Product(domain=domain.name, name='Ov', code='ov', unit='each').save() Product(domain=domain.name, name='Ml', code='ml', unit='each').save() national = make_loc(code='country', name='Test national', type='country', domain=domain.name) region = make_loc(code='region', name='Test region', type='region', domain=domain.name, parent=national) loc = make_loc(code="garms", name="Test RMS", type="Regional Medical Store", domain=domain.name, parent=national) loc.save() rms2 = make_loc(code="wrms", name="Test RMS 2", type="Regional Medical Store", domain=domain.name, parent=region) rms2.save() cms = make_loc(code="cms", name="Central Medical Stores", type="Central Medical Store", domain=domain.name, parent=national) cms.save() loc2 = make_loc(code="tf", name="Test Facility", type="CHPS Facility", domain=domain.name, parent=region) loc2.save() supply_point_id = loc.linked_supply_point().get_id supply_point_id2 = loc2.linked_supply_point().get_id cls.user1 = bootstrap_user(username='******', first_name='test1', last_name='test1', domain=domain.name, home_loc=loc) cls.user2 = bootstrap_user(username='******', domain=domain.name, home_loc=loc2, first_name='test2', last_name='test2', phone_number='222222', user_data={'role': ['In Charge']}) FacilityInCharge.objects.create(user_id=cls.user2.get_id, location=loc2.sql_location) cls.user3 = bootstrap_user(username='******', domain=domain.name, home_loc=loc2, first_name='test3', last_name='test3', phone_number='333333') cls.rms_user = bootstrap_user(username='******', domain=domain.name, home_loc=rms2, first_name='test4', last_name='test4', phone_number='44444') cls.cms_user = bootstrap_user(username='******', domain=domain.name, home_loc=cms, first_name='test5', last_name='test5', phone_number='55555') cls.region_user = bootstrap_user(username='******', domain=domain.name, home_loc=region, first_name='test6', last_name='test6', phone_number='66666') cls.without_location = bootstrap_user(username='******', domain=domain.name, first_name='test7', last_name='test7', phone_number='77777') try: XFormInstance.get(docid='test-xform') except ResourceNotFound: xform = XFormInstance(_id='test-xform') xform.save() sql_location = loc.sql_location sql_location.products = [] sql_location.save() sql_location = loc2.sql_location sql_location.products = [] sql_location.save() sql_location = rms2.sql_location sql_location.products = [] sql_location.save() sql_location = cms.sql_location sql_location.products = [] sql_location.save() config = CommtrackConfig.for_domain(domain.name) config.use_auto_consumption = False config.individual_consumption_defaults = True config.actions.append( CommtrackActionConfig(action='receipts', keyword='rec', caption='receipts')) config.consumption_config = ConsumptionConfig( use_supply_point_type_default_consumption=True, exclude_invalid_periods=True) config.save() set_default_consumption_for_supply_point(TEST_DOMAIN, p2.get_id, supply_point_id, 8) set_default_consumption_for_supply_point(TEST_DOMAIN, p3.get_id, supply_point_id, 5) set_default_consumption_for_supply_point(TEST_DOMAIN, p2.get_id, supply_point_id2, 10) set_default_consumption_for_supply_point(TEST_DOMAIN, p3.get_id, supply_point_id2, 10) set_default_consumption_for_supply_point(TEST_DOMAIN, p5.get_id, supply_point_id2, 10)
class StockoutReportNotificationTestCase(TestCase): TEST_DOMAIN = 'notifications-test-ews2' @classmethod def setUpClass(cls): cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend() cls.domain = prepare_domain(cls.TEST_DOMAIN) cls.program = Program(domain=cls.TEST_DOMAIN, name='Test Program') cls.program.save() def setUp(self): self.district = make_loc('test-district', 'Test District', self.TEST_DOMAIN, 'district') self.facility = make_loc('test-faciity', 'Test Facility', self.TEST_DOMAIN, 'Polyclinic', self.district) self.user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+4444', location=self.district, email='*****@*****.**', password='******', user_data={} ) self.product = Product(domain=self.TEST_DOMAIN, name='Test Product', code_='tp', unit='each') self.product.save() def tearDown(self): for location in Location.by_domain(self.TEST_DOMAIN): location.delete() for user in WebUser.by_domain(self.TEST_DOMAIN): user.delete() for vn in VerifiedNumber.by_domain(self.TEST_DOMAIN): vn.delete() for product in Product.by_domain(self.TEST_DOMAIN): product.delete() @classmethod def tearDownClass(cls): cls.sms_backend_mapping.delete() cls.backend.delete() def test_missing_notification(self): """No notification if there were no reports. Covered by missing report.""" generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0) def test_all_products_stocked(self): """No notification if all products are stocked.""" assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 10}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0) def test_simple_stockout(self): """Single product, single report with 0 quantity.""" assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_multi_report_stockout(self): """Single product, mutliple reports with 0 quantity.""" assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.facility, {'tp': 0}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_partial_duration_stockout(self): """Some reports indicate a stockout but did not last the entire period. No notification.""" assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.facility, {'tp': 1}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0) def test_partial_product_stockout(self): """Multiple products but only one is stocked out. Should be reported.""" other_product = Product(domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each') other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.facility, {'tp2': 10}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_multiple_users(self): """Each user will get their own notification.""" assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district, password='******', email='*****@*****.**', user_data={} ) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 2) self.assertEqual({generated[0].user.get_id, generated[1].user.get_id}, {self.user.get_id, other_user.get_id}) def test_product_type_filter(self): """User can recieve notifications for only certain product type.""" bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district, password='******', email='*****@*****.**', user_data={}, program_id=self.program.get_id ) create_stock_report(self.facility, {'tp': 0}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1)
class MissingReportNotificationTestCase(TestCase): TEST_DOMAIN = 'notifications-test-ews' @classmethod def setUpClass(cls): cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend() cls.domain = prepare_domain(cls.TEST_DOMAIN) cls.program = Program(domain=cls.TEST_DOMAIN, name='Test Program') cls.program.save() cls.program2 = Program(domain=cls.TEST_DOMAIN, name='Test Program2') cls.program2.save() def setUp(self): self.district = make_loc('test-district', 'Test District', self.TEST_DOMAIN, 'district') self.facility = make_loc('test-faciity', 'Test Facility', self.TEST_DOMAIN, 'Polyclinic', self.district) self.user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+4444', location=self.district, email='*****@*****.**', password='******', user_data={} ) self.product = Product(domain=self.TEST_DOMAIN, name='Test Product', code_='tp', unit='each') self.product.save() def tearDown(self): for location in Location.by_domain(self.TEST_DOMAIN): location.delete() for user in WebUser.by_domain(self.TEST_DOMAIN): user.delete() for vn in VerifiedNumber.by_domain(self.TEST_DOMAIN): vn.delete() for product in Product.by_domain(self.TEST_DOMAIN): product.delete() @classmethod def tearDownClass(cls): cls.sms_backend_mapping.delete() cls.backend.delete() def test_all_facilities_reported(self): """No notifications generated if all have reported.""" create_stock_report(self.facility, {'tp': 5}) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0) def test_missing_notification(self): """Inspect the generated notifcation for a non-reporting facility.""" generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_facility_in_district(self): """Facility location can be any child of the district.""" make_loc('test-faciity2', 'Test Facility2', self.TEST_DOMAIN, 'Polyclinic', self.district) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_multiple_users(self): """Each user will get their own notification.""" other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district, password='******', email='*****@*****.**', user_data={} ) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 2) self.assertEqual( {notification.user.get_id for notification in generated}, {other_user.get_id, self.user.get_id} ) def test_product_type_filter(self): """User can recieve missing notifications for only certain product type.""" bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district, password='******', email='*****@*****.**', user_data={}, program_id=self.program.get_id ) other_product = Product(domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each') other_product2 = Product(domain=self.TEST_DOMAIN, name='Test Product3', code_='tp3', unit='each') other_product.save() other_product2.save() assign_products_to_location(self.facility, [self.product, other_product, other_product2]) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_incomplete_with_filter(self): """ User with product type filter will get notification all products of that type are missing reports. """ self.user.get_domain_membership(self.TEST_DOMAIN).program_id = self.program.get_id self.user.save() self.product.program_id = self.program.get_id self.product.save() create_stock_report(self.facility, {'tp': 100}, date=datetime.utcnow() - timedelta(days=365)) other_product = Product( domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each', program_id=self.program.get_id ) other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_incomplete_report(self): create_stock_report(self.facility, {'tp': 100}, date=datetime.utcnow()) self.product.program_id = self.program.get_id self.product.save() other_product = Product( domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each', program_id=self.program.get_id ) other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0) def test_incomplete_report2(self): create_stock_report(self.facility, {'tp': 100}, date=datetime.utcnow()) self.product.program_id = self.program2.get_id self.product.save() other_product = Product( domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each', program_id=self.program.get_id ) other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0)
def setUpClass(cls): cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend() domain = prepare_domain(TEST_DOMAIN) p = Product(domain=domain.name, name="Jadelle", code="jd", unit="each") p.save() p2 = Product(domain=domain.name, name="Male Condom", code="mc", unit="each") p2.save() p3 = Product(domain=domain.name, name="Lofem", code="lf", unit="each") p3.save() p4 = Product(domain=domain.name, name="Ng", code="ng", unit="each") p4.save() p5 = Product(domain=domain.name, name="Micro-G", code="mg", unit="each") p5.save() Product(domain=domain.name, name="Ad", code="ad", unit="each").save() Product(domain=domain.name, name="Al", code="al", unit="each").save() Product(domain=domain.name, name="Qu", code="qu", unit="each").save() Product(domain=domain.name, name="Sp", code="sp", unit="each").save() Product(domain=domain.name, name="Rd", code="rd", unit="each").save() Product(domain=domain.name, name="Ov", code="ov", unit="each").save() Product(domain=domain.name, name="Ml", code="ml", unit="each").save() national = make_loc(code="country", name="Test national", type="country", domain=domain.name) region = make_loc(code="region", name="Test region", type="region", domain=domain.name, parent=national) loc = make_loc( code="garms", name="Test RMS", type="Regional Medical Store", domain=domain.name, parent=national ) loc.save() rms2 = make_loc( code="wrms", name="Test RMS 2", type="Regional Medical Store", domain=domain.name, parent=region ) rms2.save() cms = make_loc( code="cms", name="Central Medical Stores", type="Central Medical Store", domain=domain.name, parent=national ) cms.save() loc2 = make_loc(code="tf", name="Test Facility", type="CHPS Facility", domain=domain.name, parent=region) loc2.save() supply_point_id = loc.linked_supply_point().get_id supply_point_id2 = loc2.linked_supply_point().get_id cls.user1 = bootstrap_user( username="******", first_name="test1", last_name="test1", domain=domain.name, home_loc=loc ) cls.user2 = bootstrap_user( username="******", domain=domain.name, home_loc=loc2, first_name="test2", last_name="test2", phone_number="222222", user_data={"role": ["In Charge"]}, ) FacilityInCharge.objects.create(user_id=cls.user2.get_id, location=loc2.sql_location) cls.user3 = bootstrap_user( username="******", domain=domain.name, home_loc=loc2, first_name="test3", last_name="test3", phone_number="333333", ) cls.rms_user = bootstrap_user( username="******", domain=domain.name, home_loc=rms2, first_name="test4", last_name="test4", phone_number="44444", ) cls.cms_user = bootstrap_user( username="******", domain=domain.name, home_loc=cms, first_name="test5", last_name="test5", phone_number="55555", ) cls.region_user = bootstrap_user( username="******", domain=domain.name, home_loc=region, first_name="test6", last_name="test6", phone_number="66666", ) cls.without_location = bootstrap_user( username="******", domain=domain.name, first_name="test7", last_name="test7", phone_number="77777" ) try: XFormInstance.get(docid="test-xform") except ResourceNotFound: xform = XFormInstance(_id="test-xform") xform.save() sql_location = loc.sql_location sql_location.products = [] sql_location.save() sql_location = loc2.sql_location sql_location.products = [] sql_location.save() sql_location = rms2.sql_location sql_location.products = [] sql_location.save() sql_location = cms.sql_location sql_location.products = [] sql_location.save() config = CommtrackConfig.for_domain(domain.name) config.use_auto_consumption = False config.individual_consumption_defaults = True config.actions.append(CommtrackActionConfig(action="receipts", keyword="rec", caption="receipts")) config.consumption_config = ConsumptionConfig( use_supply_point_type_default_consumption=True, exclude_invalid_periods=True ) config.save() set_default_consumption_for_supply_point(TEST_DOMAIN, p2.get_id, supply_point_id, 8) set_default_consumption_for_supply_point(TEST_DOMAIN, p3.get_id, supply_point_id, 5) set_default_consumption_for_supply_point(TEST_DOMAIN, p2.get_id, supply_point_id2, 10) set_default_consumption_for_supply_point(TEST_DOMAIN, p3.get_id, supply_point_id2, 10) set_default_consumption_for_supply_point(TEST_DOMAIN, p5.get_id, supply_point_id2, 10)
def create_products(cls, domain_name, codes): for code in codes: product = Product(domain=domain_name, name=code, code=code, unit='each') product.save() setattr(cls, code, product)
class StockoutReportNotificationTestCase(EWSTestCase): TEST_DOMAIN = 'notifications-test-ews2' @classmethod def setUpClass(cls): super(StockoutReportNotificationTestCase, cls).setUpClass() cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend() cls.domain = prepare_domain(cls.TEST_DOMAIN) cls.program = Program(domain=cls.TEST_DOMAIN, name='Test Program') cls.program.save() def setUp(self): super(StockoutReportNotificationTestCase, self).setUp() self.district = make_loc('test-district', 'Test District', self.TEST_DOMAIN, 'district') self.facility = make_loc('test-faciity', 'Test Facility', self.TEST_DOMAIN, 'Polyclinic', self.district) self.user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+4444', location=self.district, email='*****@*****.**', password='******', user_data={} ) self.product = Product(domain=self.TEST_DOMAIN, name='Test Product', code_='tp', unit='each') self.product.save() def tearDown(self): delete_all_locations() for user in WebUser.by_domain(self.TEST_DOMAIN): user.delete() delete_domain_phone_numbers(self.TEST_DOMAIN) for product in Product.by_domain(self.TEST_DOMAIN): product.delete() super(StockoutReportNotificationTestCase, self).tearDown() def test_missing_notification(self): """No notification if there were no reports. Covered by missing report.""" generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0) def test_all_products_stocked(self): """No notification if all products are stocked.""" assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 10}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0) def test_simple_stockout(self): """Single product, single report with 0 quantity.""" assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_multi_report_stockout(self): """Single product, mutliple reports with 0 quantity.""" assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.facility, {'tp': 0}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_partial_duration_stockout(self): """Some reports indicate a stockout but did not last the entire period. No notification.""" assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.facility, {'tp': 1}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0) def test_partial_product_stockout(self): """Multiple products but only one is stocked out. Should be reported.""" other_product = Product(domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each') other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.facility, {'tp2': 10}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_multiple_users(self): """Each user will get their own notification.""" assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district, password='******', email='*****@*****.**', user_data={} ) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 2) self.assertEqual({generated[0].user.get_id, generated[1].user.get_id}, {self.user.get_id, other_user.get_id}) def test_product_type_filter(self): """User can recieve notifications for only certain product type.""" bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district, password='******', email='*****@*****.**', user_data={}, program_id=self.program.get_id ) create_stock_report(self.facility, {'tp': 0}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1)
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' )
class UrgentNonReportingNotificationTestCase(EWSTestCase): """Trigger notifications for regions with urgent stockouts.""" TEST_DOMAIN = 'notifications-test-ews4' @classmethod def setUpClass(cls): super(UrgentNonReportingNotificationTestCase, cls).setUpClass() cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend() cls.domain = prepare_domain(cls.TEST_DOMAIN) cls.program = Program(domain=cls.TEST_DOMAIN, name='Test Program') cls.program.save() def setUp(self): super(UrgentNonReportingNotificationTestCase, self).setUp() self.product = Product(domain=self.TEST_DOMAIN, name='Test Product', code_='tp', unit='each', program_id=self.program.get_id) self.product.save() self.country = make_loc('test-country', 'Test country', self.TEST_DOMAIN, 'country') self.region = make_loc('test-region', 'Test Region', self.TEST_DOMAIN, 'region', parent=self.country) self.district = make_loc('test-district', 'Test District', self.TEST_DOMAIN, 'district', parent=self.region) self.facility = make_loc('test-facility', 'Test Facility', self.TEST_DOMAIN, 'Polyclinic', self.district) self.other_facility = make_loc('test-facility2', 'Test Facility 2', self.TEST_DOMAIN, 'Polyclinic', self.district) self.last_facility = make_loc('test-facility3', 'Test Facility 3', self.TEST_DOMAIN, 'Polyclinic', self.district) self.user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+4444', location=self.region, email='*****@*****.**', password='******', user_data={} ) def tearDown(self): delete_all_locations() for user in WebUser.by_domain(self.TEST_DOMAIN): user.delete() delete_domain_phone_numbers(self.TEST_DOMAIN) for product in Product.by_domain(self.TEST_DOMAIN): product.delete() super(UrgentNonReportingNotificationTestCase, self).tearDown() def test_all_facility_not_report(self): """Send a notification because all facilities don't send report.""" assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) generated = list(UrgentNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_majority_facility_not_report(self): """Send a notification because > 50% of the facilities don't send report.""" assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.last_facility, {'tp': 10}) generated = list(UrgentNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_minority_facility_stockout(self): """No notification because < 50% of the facilities don't send report.""" assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.other_facility, {'tp': 10}) create_stock_report(self.last_facility, {'tp': 10}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0) def test_multiple_users(self): """Each user will get their own urgent stockout notification.""" other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.region, password='******', email='*****@*****.**', user_data={} ) assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) generated = list(UrgentNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 2) self.assertEqual({generated[0].user.get_id, generated[1].user.get_id}, {self.user.get_id, other_user.get_id}) def test_country_user(self): """Country as well as region users should get notifications.""" other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.country, password='******', email='*****@*****.**', user_data={} ) assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) generated = list(UrgentNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 2) self.assertEqual( {generated[0].user.get_id, generated[1].user.get_id}, {self.user.get_id, other_user.get_id} ) def test_product_type_filter(self): """ Notifications will not be sent if the stockout is a product type does not interest the user. """ self.user.get_domain_membership(self.TEST_DOMAIN).program_id = self.program.get_id self.user.save() program = Program(domain=self.TEST_DOMAIN, name='Test Program 2') program.save() other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.region, password='******', email='*****@*****.**', user_data={} ) assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) generated = list(UrgentNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 2) self.assertEqual({generated[0].user.get_id, generated[1].user.get_id}, {self.user.get_id, other_user.get_id})
class UrgentNonReportingNotificationTestCase(TestCase): """Trigger notifications for regions with urgent stockouts.""" TEST_DOMAIN = 'notifications-test-ews4' @classmethod def setUpClass(cls): cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend() cls.domain = prepare_domain(cls.TEST_DOMAIN) cls.program = Program(domain=cls.TEST_DOMAIN, name='Test Program') cls.program.save() def setUp(self): self.product = Product(domain=self.TEST_DOMAIN, name='Test Product', code_='tp', unit='each', program_id=self.program.get_id) self.product.save() self.country = make_loc('test-country', 'Test country', self.TEST_DOMAIN, 'country') self.region = make_loc('test-region', 'Test Region', self.TEST_DOMAIN, 'region', parent=self.country) self.district = make_loc('test-district', 'Test District', self.TEST_DOMAIN, 'district', parent=self.region) self.facility = make_loc('test-facility', 'Test Facility', self.TEST_DOMAIN, 'Polyclinic', self.district) self.other_facility = make_loc('test-facility2', 'Test Facility 2', self.TEST_DOMAIN, 'Polyclinic', self.district) self.last_facility = make_loc('test-facility3', 'Test Facility 3', self.TEST_DOMAIN, 'Polyclinic', self.district) self.user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+4444', location=self.region, email='*****@*****.**', password='******', user_data={} ) @classmethod def tearDownClass(cls): cls.sms_backend_mapping.delete() cls.backend.delete() def tearDown(self): for location in Location.by_domain(self.TEST_DOMAIN): location.delete() for user in WebUser.by_domain(self.TEST_DOMAIN): user.delete() for vn in VerifiedNumber.by_domain(self.TEST_DOMAIN): vn.delete() for product in Product.by_domain(self.TEST_DOMAIN): product.delete() def test_all_facility_not_report(self): """Send a notification because all facilities don't send report.""" assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) generated = list(UrgentNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_majority_facility_not_report(self): """Send a notification because > 50% of the facilities don't send report.""" assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.last_facility, {'tp': 10}) generated = list(UrgentNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_minority_facility_stockout(self): """No notification because < 50% of the facilities don't send report.""" assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.other_facility, {'tp': 10}) create_stock_report(self.last_facility, {'tp': 10}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0) def test_multiple_users(self): """Each user will get their own urgent stockout notification.""" other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.region, password='******', email='*****@*****.**', user_data={} ) assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) generated = list(UrgentNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 2) self.assertEqual({generated[0].user.get_id, generated[1].user.get_id}, {self.user.get_id, other_user.get_id}) def test_country_user(self): """Country as well as region users should get notifications.""" other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.country, password='******', email='*****@*****.**', user_data={} ) assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) generated = list(UrgentNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 2) self.assertEqual( {generated[0].user.get_id, generated[1].user.get_id}, {self.user.get_id, other_user.get_id} ) def test_product_type_filter(self): """ Notifications will not be sent if the stockout is a product type does not interest the user. """ self.user.get_domain_membership(self.TEST_DOMAIN).program_id = self.program.get_id self.user.save() program = Program(domain=self.TEST_DOMAIN, name='Test Program 2') program.save() other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.region, password='******', email='*****@*****.**', user_data={} ) assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) generated = list(UrgentNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 2) self.assertEqual({generated[0].user.get_id, generated[1].user.get_id}, {self.user.get_id, other_user.get_id})
class UrgentStockoutNotificationTestCase(EWSTestCase): TEST_DOMAIN = 'notifications-test-ews3' @classmethod def setUpClass(cls): super(UrgentStockoutNotificationTestCase, cls).setUpClass() delete_all_users() cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend() cls.domain = prepare_domain(cls.TEST_DOMAIN) cls.program = Program(domain=cls.TEST_DOMAIN, name='Test Program') cls.program.save() def setUp(self): super(UrgentStockoutNotificationTestCase, self).setUp() self.product = Product(domain=self.TEST_DOMAIN, name='Test Product', code_='tp', unit='each', program_id=self.program.get_id) self.product.save() self.country = make_loc('test-country', 'Test country', self.TEST_DOMAIN, 'country') self.region = make_loc('test-region', 'Test Region', self.TEST_DOMAIN, 'region', parent=self.country) self.district = make_loc('test-district', 'Test District', self.TEST_DOMAIN, 'district', parent=self.region) self.facility = make_loc('test-facility', 'Test Facility', self.TEST_DOMAIN, 'Polyclinic', self.district) self.other_facility = make_loc('test-facility2', 'Test Facility 2', self.TEST_DOMAIN, 'Polyclinic', self.district) self.last_facility = make_loc('test-facility3', 'Test Facility 3', self.TEST_DOMAIN, 'Polyclinic', self.district) self.user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+4444', location=self.region, email='*****@*****.**', password='******', user_data={} ) def tearDown(self): delete_all_locations() delete_all_users() delete_domain_phone_numbers(self.TEST_DOMAIN) for product in Product.by_domain(self.TEST_DOMAIN): product.delete() super(UrgentStockoutNotificationTestCase, self).tearDown() def test_all_facility_stockout(self): """Send a notification because all facilities are stocked out of a product.""" assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.other_facility, {'tp': 0}) create_stock_report(self.last_facility, {'tp': 0}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_majority_facility_stockout(self): """Send a notification because > 50% of the facilities are stocked out of a product.""" assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.other_facility, {'tp': 0}) create_stock_report(self.last_facility, {'tp': 10}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_minority_facility_stockout(self): """No notification because < 50% of the facilities are stocked out of a product.""" assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.other_facility, {'tp': 10}) create_stock_report(self.last_facility, {'tp': 10}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0) def test_partial_stock_coverage(self): """ Handle the case when not all facilities are expected to have stocked a given product. i.e. if only one facility is expected to have a certain product and it is stocked out then that is an urgent stockout. """ assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_multiple_users(self): """Each user will get their own urgent stockout notification.""" other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.region, password='******', email='*****@*****.**', user_data={} ) assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.other_facility, {'tp': 0}) create_stock_report(self.last_facility, {'tp': 0}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 2) self.assertEqual({generated[0].user.get_id, generated[1].user.get_id}, {self.user.get_id, other_user.get_id}) def test_country_user(self): """Country as well as region users should get notifications.""" other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.country, password='******', email='*****@*****.**', user_data={} ) assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.other_facility, {'tp': 0}) create_stock_report(self.last_facility, {'tp': 0}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 2) self.assertEqual({generated[0].user.get_id, generated[1].user.get_id}, {self.user.get_id, other_user.get_id}) def test_product_type_filter(self): """ Notifications will not be sent if the stockout is a product type does not interest the user. """ self.user.get_domain_membership(self.TEST_DOMAIN).program_id = self.program.get_id self.user.save() program = Program(domain=self.TEST_DOMAIN, name='Test Program 2') program.save() bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district, password='******', email='*****@*****.**', user_data={}, program_id=program.get_id ) assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.other_facility, {'tp': 0}) create_stock_report(self.last_facility, {'tp': 0}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
class MissingReportNotificationTestCase(EWSTestCase): TEST_DOMAIN = 'notifications-test-ews' @classmethod def setUpClass(cls): super(MissingReportNotificationTestCase, cls).setUpClass() cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend() cls.domain = prepare_domain(cls.TEST_DOMAIN) cls.program = Program(domain=cls.TEST_DOMAIN, name='Test Program') cls.program.save() cls.program2 = Program(domain=cls.TEST_DOMAIN, name='Test Program2') cls.program2.save() def setUp(self): super(MissingReportNotificationTestCase, self).setUp() self.district = make_loc('test-district', 'Test District', self.TEST_DOMAIN, 'district') self.facility = make_loc('test-faciity', 'Test Facility', self.TEST_DOMAIN, 'Polyclinic', self.district) self.user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+4444', location=self.district, email='*****@*****.**', password='******', user_data={} ) self.product = Product(domain=self.TEST_DOMAIN, name='Test Product', code_='tp', unit='each') self.product.save() def tearDown(self): delete_all_locations() for user in WebUser.by_domain(self.TEST_DOMAIN): user.delete() delete_domain_phone_numbers(self.TEST_DOMAIN) for product in Product.by_domain(self.TEST_DOMAIN): product.delete() super(MissingReportNotificationTestCase, self).tearDown() def test_all_facilities_reported(self): """No notifications generated if all have reported.""" create_stock_report(self.facility, {'tp': 5}) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0) def test_missing_notification(self): """Inspect the generated notifcation for a non-reporting facility.""" generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_facility_in_district(self): """Facility location can be any child of the district.""" make_loc('test-faciity2', 'Test Facility2', self.TEST_DOMAIN, 'Polyclinic', self.district) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_multiple_users(self): """Each user will get their own notification.""" other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district, password='******', email='*****@*****.**', user_data={} ) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 2) self.assertEqual( {notification.user.get_id for notification in generated}, {other_user.get_id, self.user.get_id} ) def test_product_type_filter(self): """User can recieve missing notifications for only certain product type.""" bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district, password='******', email='*****@*****.**', user_data={}, program_id=self.program.get_id ) other_product = Product(domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each') other_product2 = Product(domain=self.TEST_DOMAIN, name='Test Product3', code_='tp3', unit='each') other_product.save() other_product2.save() assign_products_to_location(self.facility, [self.product, other_product, other_product2]) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_incomplete_with_filter(self): """ User with product type filter will get notification all products of that type are missing reports. """ self.user.get_domain_membership(self.TEST_DOMAIN).program_id = self.program.get_id self.user.save() self.product.program_id = self.program.get_id self.product.save() create_stock_report(self.facility, {'tp': 100}, date=datetime.utcnow() - timedelta(days=365)) other_product = Product( domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each', program_id=self.program.get_id ) other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id) def test_incomplete_report(self): create_stock_report(self.facility, {'tp': 100}, date=datetime.utcnow()) self.product.program_id = self.program.get_id self.product.save() other_product = Product( domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each', program_id=self.program.get_id ) other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0) def test_incomplete_report2(self): create_stock_report(self.facility, {'tp': 100}, date=datetime.utcnow()) self.product.program_id = self.program2.get_id self.product.save() other_product = Product( domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each', program_id=self.program.get_id ) other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0)
def setUpClass(cls): domain = prepare_domain(TEST_DOMAIN) cls.sms_backend_mapping, cls.backend = create_backend() p = Product(domain=domain.name, name='Jadelle', code='jd', unit='each') p.save() p2 = Product(domain=domain.name, name='Male Condom', code='mc', unit='each') p2.save() p3 = Product(domain=domain.name, name='Lofem', code='lf', unit='each') p3.save() p4 = Product(domain=domain.name, name='Ng', code='ng', unit='each') p4.save() p5 = Product(domain=domain.name, name='Micro-G', code='mg', unit='each') p5.save() Product(domain=domain.name, name='Ad', code='ad', unit='each').save() Product(domain=domain.name, name='Al', code='al', unit='each').save() Product(domain=domain.name, name='Qu', code='qu', unit='each').save() Product(domain=domain.name, name='Sp', code='sp', unit='each').save() Product(domain=domain.name, name='Rd', code='rd', unit='each').save() Product(domain=domain.name, name='Ov', code='ov', unit='each').save() Product(domain=domain.name, name='Ml', code='ml', unit='each').save() national = make_loc(code='country', name='Test national', type='country', domain=domain.name) region = make_loc(code='region', name='Test region', type='region', domain=domain.name, parent=national) loc = make_loc(code="garms", name="Test RMS", type="Regional Medical Store", domain=domain.name, parent=national) SupplyPointCase.create_from_location(TEST_DOMAIN, loc) loc.save() rms2 = make_loc(code="wrms", name="Test RMS 2", type="Regional Medical Store", domain=domain.name, parent=region) SupplyPointCase.create_from_location(TEST_DOMAIN, rms2) rms2.save() cms = make_loc(code="cms", name="Central Medical Stores", type="Central Medical Store", domain=domain.name, parent=national) SupplyPointCase.create_from_location(TEST_DOMAIN, cms) cms.save() loc2 = make_loc(code="tf", name="Test Facility", type="CHPS Facility", domain=domain.name, parent=region) SupplyPointCase.create_from_location(TEST_DOMAIN, loc2) loc2.save() supply_point_id = loc.linked_supply_point().get_id supply_point_id2 = loc2.linked_supply_point().get_id test.bootstrap(TEST_BACKEND, to_console=True) cls.user1 = bootstrap_user(username='******', first_name='test1', last_name='test1', domain=domain.name, home_loc=loc) cls.user2 = bootstrap_user(username='******', domain=domain.name, home_loc=loc2, first_name='test2', last_name='test2', phone_number='222222', user_data={'role': ['In Charge']}) cls.user3 = bootstrap_user(username='******', domain=domain.name, home_loc=loc2, first_name='test3', last_name='test3', phone_number='333333') cls.rms_user = bootstrap_user(username='******', domain=domain.name, home_loc=rms2, first_name='test4', last_name='test4', phone_number='44444') cls.cms_user = bootstrap_user(username='******', domain=domain.name, home_loc=cms, first_name='test5', last_name='test5', phone_number='55555') cls.region_user = bootstrap_user(username='******', domain=domain.name, home_loc=region, first_name='test6', last_name='test6', phone_number='66666') cls.without_location = bootstrap_user(username='******', domain=domain.name, first_name='test7', last_name='test7', phone_number='77777') try: XFormInstance.get(docid='test-xform') except ResourceNotFound: xform = XFormInstance(_id='test-xform') xform.save() sql_location = loc.sql_location sql_location.products = [] sql_location.save() sql_location = loc2.sql_location sql_location.products = [] sql_location.save() sql_location = rms2.sql_location sql_location.products = [] sql_location.save() sql_location = cms.sql_location sql_location.products = [] sql_location.save() config = CommtrackConfig.for_domain(domain.name) config.use_auto_consumption = False config.individual_consumption_defaults = True config.actions.append( CommtrackActionConfig( action='receipts', keyword='rec', caption='receipts' ) ) config.consumption_config = ConsumptionConfig( use_supply_point_type_default_consumption=True, exclude_invalid_periods=True ) config.save() set_default_consumption_for_supply_point(TEST_DOMAIN, p2.get_id, supply_point_id, 8) set_default_consumption_for_supply_point(TEST_DOMAIN, p3.get_id, supply_point_id, 5) set_default_consumption_for_supply_point(TEST_DOMAIN, p2.get_id, supply_point_id2, 10) set_default_consumption_for_supply_point(TEST_DOMAIN, p3.get_id, supply_point_id2, 10) set_default_consumption_for_supply_point(TEST_DOMAIN, p5.get_id, supply_point_id2, 10)