def test_model_structure(self): df = make_df() tables = [{"table_name": "employee", "data_frame": df}] DATASETNAME = "Employees" DESCRIPTION = "Table of employee data." model = Model(tables=tables, name=DATASETNAME, description=DESCRIPTION) model_dict = model.get_model() # check that model is a dictionary self.assertIsInstance(model_dict, dict) # check that dictionary keys are as expected self.assertCountEqual(list(model_dict.keys()), ["name", "description", "folderId", "tables", "metrics", "attributes"]) # check that these elements of the dictionary are lists self.assertIsInstance(model.tables, list) self.assertIsInstance(model.metrics, list) self.assertIsInstance(model.attributes, list) # check that name and description match self.assertEqual(model.name, DATASETNAME) self.assertEqual(model.description, DESCRIPTION) # check that column names are unaffected and match the original data frame ch = [i['name'] for i in model.tables[0]['columnHeaders']] self.assertCountEqual(list(df.columns), ch)
def __build_model(self): """Create json representation of the dataset.""" # generate model model = Model(tables=self._tables, name=self._name, description=self._desc, folder_id=self._folder_id) self.__model = model.get_model()
def test_folder_id_none(self): df = make_df() tables = [{"table_name": "employee", "data_frame": df}] DATASETNAME = "Employees" DESCRIPTION = "Table of employee data." model = Model(tables=tables, name=DATASETNAME, description=DESCRIPTION) self.assertEqual(model.folder_id, "")
def test_metric_override(self): df = make_df() tables = [{"table_name": "employee", "data_frame": df, "to_metric": ["id_str"]}] DATASETNAME = "Employees" DESCRIPTION = "Table of employee data." model = Model(tables=tables, name=DATASETNAME, description=DESCRIPTION) self.assertEqual(len(model.attributes), 3) self.assertEqual(len(model.metrics), 5)
def test_single_table(self): df = make_df() tables = [{"table_name": "employee", "data_frame": df}] DATASETNAME = "Employees" DESCRIPTION = "Table of employee data." model = Model(tables=tables, name=DATASETNAME, description=DESCRIPTION) self.assertEqual(len(model.tables), 1) self.assertEqual(len(model.attributes), 4) self.assertEqual(len(model.metrics), 4)
def test_attribute_override(self): df = make_df() tables = [{"table_name": "employee1", "data_frame": df, "to_attribute": ["id_int"]}, {"table_name": "employee2", "data_frame": df, "to_attribute": ["id_int", "salary", "age"]}] DATASETNAME = "Employees" DESCRIPTION = "Table of employee data." model = Model(tables=tables, name=DATASETNAME, description=DESCRIPTION) self.assertEqual(len(model.attributes), 12) self.assertEqual(len(model.metrics), 4)