Exemplo n.º 1
0
 def setUp(self):
     self.endpoint = MockEndpoint('http://test-api.com/', 'dummy', 'dummy')
     self.api_object = EWSApi(TEST_DOMAIN, self.endpoint)
     self.datapath = os.path.join(os.path.dirname(__file__), 'data')
     initial_bootstrap(TEST_DOMAIN)
     for product in Prod.by_domain(TEST_DOMAIN):
         product.delete()
Exemplo n.º 2
0
def migration_task():
    for config in EWSGhanaConfig.get_all_steady_sync_configs():
        if config.enabled:
            endpoint = GhanaEndpoint.from_config(config)
            ews_bootstrap_domain(EWSApi(config.domain, endpoint))
            stock_data_task.delay(
                EWSStockDataSynchronization(config.domain, endpoint))
Exemplo n.º 3
0
 def setUpClass(cls):
     cls.endpoint = MockEndpoint('http://test-api.com/', 'dummy', 'dummy')
     cls.api_object = EWSApi(TEST_DOMAIN, cls.endpoint)
     cls.datapath = os.path.join(os.path.dirname(__file__), 'data')
     initial_bootstrap(TEST_DOMAIN)
     bootstrap_products(TEST_DOMAIN)
     cls.api_object.prepare_commtrack_config()
     with open(os.path.join(cls.datapath, 'sample_products.json')) as f:
         for p in json.loads(f.read()):
             cls.api_object.product_sync(Product(p))
Exemplo n.º 4
0
    def setUp(self):
        self.endpoint = MockEndpoint('http://test-api.com/', 'dummy', 'dummy')
        self.api_object = EWSApi(TEST_DOMAIN, self.endpoint)
        self.datapath = os.path.join(os.path.dirname(__file__), 'data')
        initial_bootstrap(TEST_DOMAIN)
        self.api_object.prepare_commtrack_config()
        self.api_object.create_or_edit_roles()
        for user in CommCareUser.by_domain(TEST_DOMAIN):
            user.delete()

        for verified_number in VerifiedNumber.by_domain(TEST_DOMAIN):
            verified_number.delete()
Exemplo n.º 5
0
    def setUp(self):
        self.endpoint = MockEndpoint('http://test-api.com/', 'dummy', 'dummy')
        self.stock_api_object = MockEWSStockDataSynchronization(
            TEST_DOMAIN, self.endpoint)
        self.datapath = os.path.join(os.path.dirname(__file__), 'data')
        initial_bootstrap(TEST_DOMAIN)
        self.api_object = EWSApi(TEST_DOMAIN, self.endpoint)
        self.api_object.prepare_commtrack_config()
        config = EWSGhanaConfig()
        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='Hospital',
                      domain=TEST_DOMAIN)

        l2 = Location(name='Test location 2',
                      external_id='4407',
                      location_type='Hospital',
                      domain=TEST_DOMAIN)

        l1.save()
        l2.save()

        SupplyPointCase.create_from_location(TEST_DOMAIN, l1)
        SupplyPointCase.create_from_location(TEST_DOMAIN, l2)

        l1.save()
        l2.save()

        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))
Exemplo n.º 6
0
def ews_bootstrap_domain_task(domain):
    ews_config = EWSGhanaConfig.for_domain(domain)
    return bootstrap_domain(
        EWSApi(domain, GhanaEndpoint.from_config(ews_config)))
Exemplo n.º 7
0
    def setUpClass(cls):
        cls.domain = initial_bootstrap(TEST_DOMAIN)
        db = get_db()
        if db.doc_exist(DOMAIN_MODULE_KEY):
            module_config = db.open_doc(DOMAIN_MODULE_KEY)
            module_map = module_config.get('module_map')
            if module_map:
                module_map[TEST_DOMAIN] = 'custom.ewsghana'
            else:
                module_config['module_map'][TEST_DOMAIN] = 'custom.ewsghana'
        else:
            module_config = db.save_doc({
                '_id': DOMAIN_MODULE_KEY,
                'module_map': {
                    'ewsghana-test-input-stock': 'custom.ewsghana'
                }
            })
        db.save_doc(module_config)
        generator.instantiate_accounting_for_tests()
        account = BillingAccount.get_or_create_account_by_domain(
            cls.domain.name,
            created_by="automated-test",
        )[0]
        plan = DefaultProductPlan.get_default_plan_by_domain(
            cls.domain, edition=SoftwarePlanEdition.ENTERPRISE)
        subscription = Subscription.new_domain_subscription(
            account, cls.domain.name, plan)
        subscription.is_active = True
        subscription.save()
        cls.endpoint = MockEndpoint('http://test-api.com/', 'dummy', 'dummy')
        cls.api_object = EWSApi(TEST_DOMAIN, cls.endpoint)
        cls.api_object.prepare_commtrack_config()
        cls.api_object.prepare_custom_fields()
        cls.datapath = os.path.join(os.path.dirname(__file__), 'data')

        with open(os.path.join(cls.datapath, 'sample_products.json')) as f:
            for p in json.loads(f.read()):
                cls.api_object.product_sync(Product(p))

        with open(os.path.join(cls.datapath, 'sample_locations.json')) as f:
            for loc in json.loads(f.read()):
                cls.api_object.location_sync(Location(loc))

        cls.test_facility3 = SQLLocation.objects.get(domain=TEST_DOMAIN,
                                                     site_code='tsactive')
        cls.testregion2 = SQLLocation.objects.get(domain=TEST_DOMAIN,
                                                  site_code='testregion2')
        cls.rsp = SQLLocation.objects.get(domain=TEST_DOMAIN, site_code='rsp')
        cls.test_district = SQLLocation.objects.get(domain=TEST_DOMAIN,
                                                    site_code='testdistrict')

        cls.username1 = 'ews_user1'
        cls.password1 = 'dummy'
        cls.web_user1 = WebUser.create(TEST_DOMAIN, cls.username1,
                                       cls.password1)

        cls.web_user1.eula.signed = True
        cls.web_user1.save()

        cls.username2 = 'ews_user2'
        cls.password2 = 'dummy'
        cls.web_user2 = WebUser.create(TEST_DOMAIN, cls.username2,
                                       cls.password2)
        cls.web_user2.get_domain_membership(
            TEST_DOMAIN).location_id = cls.test_facility3.location_id

        cls.web_user2.eula.signed = True
        cls.web_user2.save()

        cls.username3 = 'ews_user3'
        cls.password3 = 'dummy'
        cls.web_user3 = WebUser.create(TEST_DOMAIN, cls.username3,
                                       cls.password3)
        cls.web_user3.get_domain_membership(
            TEST_DOMAIN).location_id = cls.testregion2.location_id

        cls.web_user3.eula.signed = True
        cls.web_user3.save()

        cls.username4 = 'ews_user4'
        cls.password4 = 'dummy'
        cls.web_user4 = WebUser.create(TEST_DOMAIN, cls.username4,
                                       cls.password4)
        cls.web_user4.get_domain_membership(
            TEST_DOMAIN).location_id = cls.rsp.location_id

        cls.web_user4.eula.signed = True
        cls.web_user4.save()

        cls.username5 = 'ews_user5'
        cls.password5 = 'dummy'
        cls.web_user5 = WebUser.create(TEST_DOMAIN, cls.username5,
                                       cls.password5)
        domain_membership = cls.web_user5.get_domain_membership(TEST_DOMAIN)
        domain_membership.location_id = cls.test_district.location_id
        domain_membership.role_id = UserRole.get_read_only_role_by_domain(
            cls.domain.name).get_id

        cls.web_user5.eula.signed = True
        cls.web_user5.save()

        cls.ad = SQLProduct.objects.get(domain=TEST_DOMAIN, code='ad')
        cls.al = SQLProduct.objects.get(domain=TEST_DOMAIN, code='al')

        cls.client = Client()
Exemplo n.º 8
0
def ews_add_products_to_locs(request, domain):
    config = EWSGhanaConfig.for_domain(domain)
    endpoint = GhanaEndpoint.from_config(config)
    add_products_to_loc.delay(EWSApi(domain=domain, endpoint=endpoint))
    return HttpResponse('OK')
Exemplo n.º 9
0
def ews_resync_web_users(request, domain):
    config = EWSGhanaConfig.for_domain(domain)
    endpoint = GhanaEndpoint.from_config(config)
    resync_web_users.delay(EWSApi(domain=domain, endpoint=endpoint))
    return HttpResponse('OK')