Esempio n. 1
0
 def test_get_daily_date_skeleton(self):
     test_scope = {
         "startDate":"01/01/2019",
         "endDate":"12/31/2019",
         "scope_type": "hierarchy",
         "scope_field":"loc_id",
         "scope_field_value":6,
         "control_type_name":"Is Grocery Service",
     }
     ds = DataService(test_scope)
     d_skeleton = ds.get_daily_date_skeleton()
     self.assertTrue(len(d_skeleton) == 365)
Esempio n. 2
0
 def test_get_weekly_date_skeleton(self):
     test_scope = {
         "startDate":"01/01/2019",
         "endDate":"12/31/2019",
         "scope_type": "hierarchy",
         "scope_field":"loc_id",
         "scope_field_value":6,
         "control_type_name":"Is Grocery Service",
     }
     ds = DataService(test_scope)
     w_skeleton = ds.get_weekly_date_skeleton()
     #52 * 7 = 364; +1  day means +1 extra row in the dataframe
     self.assertTrue(len(w_skeleton) == 53)
Esempio n. 3
0
#How 'off' the value returned by a data def can be before it is considered wrong
#.005 = .5% of expected
REL_TOL = .01

base_services_scope = {
    "startDate": "01/01/2020",
    "endDate": "12/31/2020",
    "scope_type": "hierarchy",
    "scope_field": "fb_id",
    "scope_field_value": 21,
    "control_type_name": "Is Grocery Service"
}

#shared test data service so you don't have to make a db call for every test
#not gonna work with multithreaded tests
TEST_DATA_SERVICE = DataService(base_services_scope)


class CalculationsTestCase(unittest.TestCase):
    def test_get_frequency_visits(self):
        expected = {
            "n_families": {
                "1": 75530,
                "2": 29221,
                "3": 17037,
                "4": 11730,
                "5": 8713,
                "6": 6931,
                "7": 5698,
                "8": 4898,
                "9": 4115,
              newline='') as csvfile:
        rownum = 0
        reader = csv.reader(csvfile, dialect='excel')
        for row in reader:
            if rownum != 0:
                expected[row[0]] = {
                    "mofc_value":
                    float(row[1]) if row[1].find(".") != -1 else int(row[1]),
                    "franklin_value":
                    float(row[2]) if row[2].find(".") != -1 else int(row[2])
                }
            rownum += 1
    return expected


TEST_DATA_SERVICE = DataService(sample_scope_2)
EXPECTED_INT_RESULTS = read_expected_int()


class CalculationsTestCase(unittest.TestCase):
    def test_get_services_total(self):
        #how to avoid repeatedly making database requests in calculation tests?
        #might want to instantiate the data service object
        #might want to pass a connection to mock database in data_service.get_fact_service
        #make data service a singleton
        data = TEST_DATA_SERVICE.get_data_for_definition(1)
        func = calc.data_calc_function_switcher[1]
        result = func(data)
        self.assertTrue(
            math.isclose(
                result,