Exemplo n.º 1
0
 def test_raw_cases_location(self):
     location = self.districts['A-b']._id
     config = {'domain': TEST_DOMAIN, 'location_id': location}
     data = list(StockStatusDataSource(config).get_data())
     self.assertEqual(len(data), 1)
     self.assertEqual(data[0][LOCATION_ID], self.sites['A-b-1'][0]._id)
     self.assertEqual(data[0][PRODUCT_ID], self.products['pA']._id)
     self.assertEqual(data[0][CURRENT_STOCK], 2)
Exemplo n.º 2
0
 def product_data(self):
     config = {
         'domain': self.domain,
         'location_id': self.request.GET.get('location_id'),
         'program_id': self.request.GET.get('program'),
         'aggregate': True,
         'advanced_columns': self.showing_advanced_columns(),
     }
     return list(StockStatusDataSource(config).get_data())
Exemplo n.º 3
0
 def test_aggregate_level2(self):
     location = self.districts['A-b']._id
     config = {
         'domain': TEST_DOMAIN,
         'location_id': location,
         'aggregate': True
     }
     data = list(StockStatusDataSource(config).get_data())
     self.assertEqual(len(data), 1)
     self.assertEqual(data[0][CURRENT_STOCK], 2)
Exemplo n.º 4
0
 def product_data(self):
     if getattr(self, 'prod_data', None) is None:
         self.prod_data = []
         config = {
             'domain': self.domain,
             'location_id': self.request.GET.get('location_id'),
             'program_id': self.request.GET.get('program'),
             'startdate': self.datespan.startdate_utc,
             'enddate': self.datespan.enddate_utc,
             'aggregate': True
         }
         self.prod_data = self.prod_data + list(StockStatusDataSource(config).get_data())
     return self.prod_data
Exemplo n.º 5
0
    def test_raw_cases(self):
        config = {'domain': TEST_DOMAIN}
        data = list(StockStatusDataSource(config).get_data())
        self.assertEqual(len(data), 6)
        by_location = map_reduce(lambda row: [(row[LOCATION_ID], )],
                                 data=data,
                                 include_docs=True)

        for site, products in self.sites.values():
            site_id = site._id
            rows = by_location[site_id]
            by_product = dict((row[PRODUCT_ID], row) for row in rows)
            for code, level in products.items():
                product_id = self.products[code]._id
                self.assertEqual(by_product[product_id][CURRENT_STOCK], level)
Exemplo n.º 6
0
    def test_aggregate_level1(self):
        location = self.regions['A']._id
        config = {
            'domain': TEST_DOMAIN,
            'location_id': location,
            'aggregate': True
        }
        data = list(StockStatusDataSource(config).get_data())
        self.assertEqual(len(data), 2)
        by_product = dict((row[PRODUCT_ID], row) for row in data)
        pA_id = self.products['pA']._id
        pB_id = self.products['pB']._id

        self.assertEqual(by_product[pA_id][CURRENT_STOCK], 6)
        self.assertEqual(by_product[pB_id][CURRENT_STOCK], 3)
Exemplo n.º 7
0
 def test_stock_status_data_source_single_location(self):
     config = {
         'domain': self.domain,
         'location_id': self.location.location_id,
         'advanced_columns': True,
     }
     self.assertEqual(
         list(StockStatusDataSource(config).get_data()),
         [{
             'category': 'nodata',
             'consumption': None,
             'current_stock': 50,
             'location_id': self.location.location_id,
             'months_remaining': None,
             'product_id': self.product._id,
             'product_name': self.product.name,
             'resupply_quantity_needed': None
         }]
     )
Exemplo n.º 8
0
    def test_stock_status_data_source_raw(self):
        ledger_value = LedgerAccessors(self.domain).get_ledger_value(
            self.supply_point.case_id, "stock", self.product._id
        )

        config = {
            'domain': self.domain,
            'aggregate': False,
            'advanced_columns': True,
        }
        self.assertEqual(
            list(StockStatusDataSource(config).get_data()),
            [{
                'category': 'nodata',
                'consumption': None,
                'current_stock': 50,
                'last_reported': ledger_value.last_modified,
                'location_id': self.location.location_id,
                'months_remaining': None,
                'product_id': self.product._id,
                'product_name': self.product.name,
                'resupply_quantity_needed': None}]
        )