def prepare_domain(domain_name): from corehq.apps.commtrack.tests import bootstrap_domain domain = bootstrap_domain(domain_name) previous = None for name, administrative in [("MOHSW", True), ("MSDZONE", True), ("REGION", True), ("DISTRICT", True), ("FACILITY", False)]: previous, _ = LocationType.objects.get_or_create( domain=domain_name, name=name, parent_type=previous, administrative=administrative, ) generator.instantiate_accounting_for_tests() account = BillingAccount.get_or_create_account_by_domain( domain.name, created_by="automated-test", )[0] plan = DefaultProductPlan.get_default_plan_by_domain( domain, edition=SoftwarePlanEdition.ADVANCED) commtrack = domain.commtrack_settings commtrack.actions.append( CommtrackActionConfig(action='receipts', keyword='delivered', caption='Delivered')) commtrack.save() subscription = Subscription.new_domain_subscription( account, domain.name, plan) subscription.is_active = True subscription.save() ils_config = ILSGatewayConfig(enabled=True, domain=domain.name) ils_config.save() return domain
def setUp(self): self.endpoint = MockEndpoint("http://test-api.com/", "dummy", "dummy") self.stock_api_object = MockILSStockDataSynchronization(TEST_DOMAIN, self.endpoint) self.datapath = os.path.join(os.path.dirname(__file__), "data") initial_bootstrap(TEST_DOMAIN) self.api_object = ILSGatewayAPI(TEST_DOMAIN, self.endpoint) self.api_object.prepare_commtrack_config() config = ILSGatewayConfig() config.domain = TEST_DOMAIN config.enabled = True config.all_stock_data = True config.password = "******" config.username = "******" config.url = "http://test-api.com/" config.save() l1 = Location(name="Test location 1", external_id="3445", location_type="FACILITY", domain=TEST_DOMAIN) l2 = Location(name="Test location 2", external_id="4407", location_type="FACILITY", domain=TEST_DOMAIN) l1.save() l2.save() SupplyPointCase.create_from_location(TEST_DOMAIN, l1) SupplyPointCase.create_from_location(TEST_DOMAIN, l2) with open(os.path.join(self.datapath, "sample_products.json")) as f: for product_json in json.loads(f.read()): self.api_object.product_sync(Product(product_json)) StockTransaction.objects.all().delete()
def setUp(self): self.datapath = os.path.join(os.path.dirname(__file__), 'data') initial_bootstrap(TEST_DOMAIN) config = ILSGatewayConfig() config.domain = TEST_DOMAIN config.enabled = True config.password = '******' config.username = '******' config.url = 'http://test-api.com/' config.save() for product in Product.by_domain(TEST_DOMAIN): product.delete()
def prepare_domain(domain_name): from corehq.apps.commtrack.tests.util import bootstrap_domain domain = bootstrap_domain(domain_name) previous = None for name, administrative in [ ("MOHSW", True), ("MSDZONE", True), ("REGION", True), ("DISTRICT", True), ("FACILITY", False) ]: previous, _ = LocationType.objects.get_or_create( domain=domain_name, name=name, parent_type=previous, administrative=administrative, ) generator.instantiate_accounting_for_tests() account = BillingAccount.get_or_create_account_by_domain( domain.name, created_by="automated-test", )[0] plan = DefaultProductPlan.get_default_plan_by_domain( domain, edition=SoftwarePlanEdition.ADVANCED ) commtrack = domain.commtrack_settings commtrack.actions.append( CommtrackActionConfig(action='receipts', keyword='delivered', caption='Delivered') ) commtrack.save() subscription = Subscription.new_domain_subscription( account, domain.name, plan ) subscription.is_active = True subscription.save() ils_config = ILSGatewayConfig(enabled=True, domain=domain.name, all_stock_data=True) ils_config.save() fields_definition = CustomDataFieldsDefinition.get_or_create(domain.name, 'LocationFields') fields_definition.fields.append(CustomDataField( slug='group', label='Group', is_required=False, choices=['A', 'B', 'C'], is_multiple_choice=False )) fields_definition.save() return domain
def prepare_domain(domain_name): from corehq.apps.commtrack.tests.util import bootstrap_domain domain = bootstrap_domain(domain_name) previous = None for name, administrative in [ ("MOHSW", True), ("MSDZONE", True), ("REGION", True), ("DISTRICT", True), ("FACILITY", False) ]: previous, _ = LocationType.objects.get_or_create( domain=domain_name, name=name, parent_type=previous, administrative=administrative, ) generator.instantiate_accounting() account = BillingAccount.get_or_create_account_by_domain( domain.name, created_by="automated-test", )[0] plan = DefaultProductPlan.get_default_plan( edition=SoftwarePlanEdition.ADVANCED ) commtrack = domain.commtrack_settings commtrack.actions.append( CommtrackActionConfig(action='receipts', keyword='delivered', caption='Delivered') ) commtrack.save() subscription = Subscription.new_domain_subscription( account, domain.name, plan ) subscription.is_active = True subscription.save() ils_config = ILSGatewayConfig(enabled=True, domain=domain.name, all_stock_data=True) ils_config.save() fields_definition = CustomDataFieldsDefinition.get_or_create(domain.name, 'LocationFields') fields_definition.fields.append(CustomDataField( slug='group', label='Group', is_required=False, choices=['A', 'B', 'C'], is_multiple_choice=False )) fields_definition.save() return domain
def post(self, request, *args, **kwargs): ils_config = ILSGatewayConfig.for_domain(self.domain) ils_config_form = ILSConfigForm(request.POST) if not ils_config_form.is_valid(): return self.get(request, *args, **kwargs) enabled = ils_config_form.cleaned_data['enabled'] if not ils_config and enabled: ils_config = ILSGatewayConfig(enabled=True, domain=self.domain) ils_config.save() elif ils_config and ils_config.enabled != enabled: ils_config.enabled = enabled ils_config.save() return self.get(request, *args, **kwargs)
def setUpClass(cls): cls.datapath = os.path.join(os.path.dirname(__file__), 'data') cls.sms_backend, cls.sms_backend_mapping = setup_default_sms_test_backend() initial_bootstrap(TEST_DOMAIN) config = ILSGatewayConfig() config.domain = TEST_DOMAIN config.enabled = True config.password = '******' config.username = '******' config.url = 'http://test-api.com/' config.save() for product in Product.by_domain(TEST_DOMAIN): product.delete()
def setUp(self): self.datapath = os.path.join(os.path.dirname(__file__), 'data') initial_bootstrap(TEST_DOMAIN) self.sms_backend = TestSMSBackend(name="MOBILE_BACKEND_TEST", is_global=True) self.sms_backend._id = self.sms_backend.name self.sms_backend.save() config = ILSGatewayConfig() config.domain = TEST_DOMAIN config.enabled = True config.password = '******' config.username = '******' config.url = 'http://test-api.com/' config.save() for product in Product.by_domain(TEST_DOMAIN): product.delete()
def setUp(self): self.datapath = os.path.join(os.path.dirname(__file__), 'data') initial_bootstrap(TEST_DOMAIN) sms_backend = TestSMSBackend(name="MOBILE_BACKEND_TEST", is_global=True) sms_backend._id = sms_backend.name sms_backend.save() config = ILSGatewayConfig() config.domain = TEST_DOMAIN config.enabled = True config.password = '******' config.username = '******' config.url = 'http://test-api.com/' config.save() for product in Product.by_domain(TEST_DOMAIN): product.delete()
def setUp(self): self.endpoint = MockEndpoint('http://test-api.com/', 'dummy', 'dummy') self.api_object = ILSGatewayAPI(TEST_DOMAIN, self.endpoint) self.datapath = os.path.join(os.path.dirname(__file__), 'data') initial_bootstrap(TEST_DOMAIN) config = ILSGatewayConfig( domain=TEST_DOMAIN, enabled=True, all_stock_data=True, password='******', username='******', url='http//test-api.com/' ) config.save() with open(os.path.join(self.datapath, 'sample_locations.json')) as f: location = Loc(**json.loads(f.read())[1]) self.api_object.prepare_commtrack_config() self.api_object.location_sync(location) for user in WebUser.by_domain(TEST_DOMAIN): user.delete()
def prepare_domain(domain_name): from corehq.apps.commtrack.tests import bootstrap_domain domain = bootstrap_domain(domain_name) previous = None for name, administrative in [ ("MOHSW", True), ("REGION", True), ("DISTRICT", True), ("FACILITY", False) ]: previous, _ = LocationType.objects.get_or_create( domain=domain_name, name=name, parent_type=previous, administrative=administrative, ) generator.instantiate_accounting_for_tests() account = BillingAccount.get_or_create_account_by_domain( domain.name, created_by="automated-test", )[0] plan = DefaultProductPlan.get_default_plan_by_domain( domain, edition=SoftwarePlanEdition.ADVANCED ) commtrack = domain.commtrack_settings commtrack.actions.append( CommtrackActionConfig(action='receipts', keyword='delivered', caption='Delivered') ) commtrack.save() subscription = Subscription.new_domain_subscription( account, domain.name, plan ) subscription.is_active = True subscription.save() ils_config = ILSGatewayConfig(enabled=True, domain=domain.name) ils_config.save() return domain
def setUp(self): self.endpoint = MockEndpoint('http://test-api.com/', 'dummy', 'dummy') self.stock_api_object = MockILSStockDataSynchronization( TEST_DOMAIN, self.endpoint) self.datapath = os.path.join(os.path.dirname(__file__), 'data') initial_bootstrap(TEST_DOMAIN) self.api_object = ILSGatewayAPI(TEST_DOMAIN, self.endpoint) self.api_object.prepare_commtrack_config() config = ILSGatewayConfig() config.domain = TEST_DOMAIN config.enabled = True config.all_stock_data = True config.password = '******' config.username = '******' config.url = 'http://test-api.com/' config.save() l1 = Location(name='Test location 1', external_id='3445', location_type='FACILITY', domain=TEST_DOMAIN) l2 = Location(name='Test location 2', external_id='4407', location_type='FACILITY', domain=TEST_DOMAIN) l1.save() l2.save() SupplyPointCase.create_from_location(TEST_DOMAIN, l1) SupplyPointCase.create_from_location(TEST_DOMAIN, l2) with open(os.path.join(self.datapath, 'sample_products.json')) as f: for product_json in json.loads(f.read()): self.api_object.product_sync(Product(product_json)) StockTransaction.objects.all().delete()