Exemplo n.º 1
0
class TestDataLoader(TestCase):
    def setUp(self):
        user_data_path = "consumption/tests/resource/user_data.csv"
        consumption_data_path = "consumption/tests/resource/consumption/"
        file_paths = (user_data_path, consumption_data_path)
        self.dataloader = DataLoader(file_paths=file_paths)

    def test_register_consumption(self):
        self.dataloader.register_user()
        self.dataloader.register_consumption()

    def test_load_user_data(self):
        df = self.dataloader.load_user_data()
        self.assertTrue(isinstance(df, pd.DataFrame))

    def test_load_consumption_data(self):
        df = self.dataloader.load_consumption_data()
        self.assertTrue(isinstance(df, pd.DataFrame))

    def test_register_user(self):
        self.assertTrue(self.dataloader.register_user())

    def test_register_consumption(self):
        self.dataloader.register_user()
        self.assertTrue(self.dataloader.register_consumption())
Exemplo n.º 2
0
class TestAggregator(TestCase):
    def setUp(self):
        user_data_path = "consumption/tests/resource/user_data.csv"
        consumption_data_path = "consumption/tests/resource/consumption/"
        file_paths = (user_data_path, consumption_data_path)
        self.dataloader = DataLoader(file_paths=file_paths)
        self.dataloader.register_user()
        self.dataloader.register_consumption()
        self.aggregator = Aggregater()

    def test_mean(self):
        mean_yearly = self.aggregator.mean("Y")
        mean_monthly = self.aggregator.mean("M")
        mean_weekly = self.aggregator.mean("W")
        mean_daily = self.aggregator.mean("D")

        self.assertTrue(isinstance(mean_yearly, pd.DataFrame))
        self.assertTrue(isinstance(mean_monthly, pd.DataFrame))
        self.assertTrue(isinstance(mean_weekly, pd.DataFrame))
        self.assertTrue(isinstance(mean_daily, pd.DataFrame))

    def test_total(self):
        total_yearly = self.aggregator.total("Y")
        total_monthly = self.aggregator.total("M")
        total_weekly = self.aggregator.total("W")
        total_daily = self.aggregator.total("D")

        self.assertTrue(isinstance(total_yearly, pd.DataFrame))
        self.assertTrue(isinstance(total_monthly, pd.DataFrame))
        self.assertTrue(isinstance(total_weekly, pd.DataFrame))
        self.assertTrue(isinstance(total_daily, pd.DataFrame))
Exemplo n.º 3
0
 def setUp(self):
     user_data_path = "consumption/tests/resource/user_data.csv"
     consumption_data_path = "consumption/tests/resource/consumption/"
     file_paths = (user_data_path, consumption_data_path)
     self.dataloader = DataLoader(file_paths=file_paths)
     self.dataloader.register_user()
     self.dataloader.register_consumption()
     self.aggregator = Aggregater()
class TestViews(TestCase):
    def setUp(self):
        user_data_path = "consumption/tests/resource/user_data.csv"
        consumption_data_path = "consumption/tests/resource/consumption/"
        self.file_paths = (user_data_path, consumption_data_path)
        self.dataloader = DataLoader(file_paths=self.file_paths)
    
    
    def test_summary(self):
        self.dataloader.register_user()
        self.dataloader.register_consumption()
        rf = RequestFactory()
        request = rf.get("/summary/")
        respnose = summary(request)
        
Exemplo n.º 5
0
 def handle(self, *args, **options):
     is_valid = True
     user_validator = UserValidator(user_data_path)
     consumption_files = glob.glob(consumption_data_path + "/*.csv")
     for consumption_file in consumption_files:
         consumption_validator = ConsumptionValidator(consumption_file)
         if not consumption_validator.is_valid():
             is_valid = False
     
     if is_valid:
         print(f"All data is valid.")
         dataloader = DataLoader(file_paths=file_paths)
         dataloader.register_user()
         dataloader.register_consumption()
 def setUp(self):
     user_data_path = "consumption/tests/resource/user_data.csv"
     consumption_data_path = "consumption/tests/resource/consumption/"
     self.file_paths = (user_data_path, consumption_data_path)
     self.dataloader = DataLoader(file_paths=self.file_paths)