Exemplo n.º 1
0
    def test_create_facility_location(self):
        with open(os.path.join(self.datapath, 'sample_locations.json')) as f:
            location = Location(json.loads(f.read())[1])

        with open(os.path.join(self.datapath, 'sample_products.json')) as f:
            for p in json.loads(f.read()):
                self.api_object.product_sync(Product(p))
        self.assertEqual(8, SQLProduct.objects.filter(domain=TEST_DOMAIN).count())
        ewsghana_location = self.api_object.location_sync(location)
        self.assertEqual(ewsghana_location.name, location.supply_points[0].name)
        self.assertEqual(ewsghana_location.site_code, location.supply_points[0].code)
        self.assertEqual("Hospital", ewsghana_location.location_type)
        self.assertEqual(ewsghana_location.longitude, float(location.longitude))
        self.assertEqual(ewsghana_location.latitude, float(location.latitude))
        self.assertFalse(ewsghana_location.is_archived)

        sql_location = ewsghana_location.sql_location
        self.assertEqual(ewsghana_location.get_id, sql_location.location_id)
        self.assertEqual(int(sql_location.parent.external_id), location.parent_id)
        self.assertIsNotNone(sql_location.id)
        self.assertIsNotNone(sql_location.supply_point_id)
        supply_point = get_supply_point_case_by_location_id(
            TEST_DOMAIN, sql_location.location_id)
        self.assertIsNotNone(supply_point)
        self.assertEqual(supply_point.location, ewsghana_location)
        self.assertEqual(location.supply_points[0].id, int(supply_point.external_id))
        self.assertEqual(location.supply_points[0].name, supply_point.name)
        self.assertSetEqual(set(location.supply_points[0].products),
                            {product.code for product in ewsghana_location.sql_location.products})
Exemplo n.º 2
0
    def test_create_facility_location(self):
        with open(os.path.join(self.datapath, 'sample_locations.json')) as f:
            location = Location(json.loads(f.read())[1])

        with open(os.path.join(self.datapath, 'sample_products.json')) as f:
            for p in json.loads(f.read()):
                self.api_object.product_sync(Product(p))
        self.assertEqual(8,
                         SQLProduct.objects.filter(domain=TEST_DOMAIN).count())
        ewsghana_location = self.api_object.location_sync(location)
        self.assertEqual(ewsghana_location.name,
                         location.supply_points[0].name)
        self.assertEqual(ewsghana_location.site_code,
                         location.supply_points[0].code)
        self.assertEqual("Hospital", ewsghana_location.location_type)
        self.assertEqual(ewsghana_location.longitude,
                         float(location.longitude))
        self.assertEqual(ewsghana_location.latitude, float(location.latitude))
        self.assertFalse(ewsghana_location.is_archived)

        sql_location = ewsghana_location.sql_location
        self.assertEqual(ewsghana_location.get_id, sql_location.location_id)
        self.assertEqual(int(sql_location.parent.external_id),
                         location.parent_id)
        self.assertIsNotNone(sql_location.id)
        self.assertIsNotNone(sql_location.supply_point_id)
        supply_point = get_supply_point_case_by_location_id(
            TEST_DOMAIN, sql_location.location_id)
        self.assertIsNotNone(supply_point)
        self.assertEqual(supply_point.location, ewsghana_location)
        self.assertEqual(location.supply_points[0].id,
                         int(supply_point.external_id))
        self.assertEqual(location.supply_points[0].name, supply_point.name)
        self.assertSetEqual(set(location.supply_points[0].products), {
            product.code
            for product in ewsghana_location.sql_location.products
        })
Exemplo n.º 3
0
 def test_get_supply_point_case_by_location_id(self):
     actual = get_supply_point_case_by_location_id(self.domain,
                                                   self.locations[0]._id)
     expected = SupplyPointCase.wrap(self.supply_points[0].to_json())
     self.assertEqual(type(actual), type(expected))
     self.assertEqual(actual.to_json(), expected.to_json())
Exemplo n.º 4
0
 def test_get_supply_point_case_by_location_id(self):
     actual = get_supply_point_case_by_location_id(
         self.domain, self.locations[0]._id)
     expected = SupplyPointCase.wrap(self.supply_points[0].to_json())
     self.assertEqual(type(actual), type(expected))
     self.assertEqual(actual.to_json(), expected.to_json())
Exemplo n.º 5
0
 def get_last_processed_location(self, checkpoint):
     supply_point = get_supply_point_case_by_location_id(
         self.domain, checkpoint.location.location_id)
     external_id = supply_point.external_id if supply_point else None
     return external_id
Exemplo n.º 6
0
 def get_last_processed_location(self, checkpoint):
     supply_point = get_supply_point_case_by_location_id(
         self.domain, checkpoint.location.location_id)
     external_id = supply_point.external_id if supply_point else None
     return external_id