def create_attributes(self, count: int) -> None: """ Create Attributes for SubThemes :param count: Number of Attributes per SubTheme """ number_attributes = len(self.sub_themes) * count try: index = 0 sub_theme = self.sub_themes[index] for num in range(0, number_attributes): unit = self.create_unit(num) attr = Attributes( "attribute_id_{}".format(num), "attribute_name_{}".format(num), "b3_heat_value_bffc4e56_20e2_41a5_84d8_de725a3f875b", sub_theme.id, unit.id, "_test_description_{}".format(num), "1") attr.save() attr.commit() self.attributes.append(attr) if num % count: index += 1 if index >= len(self.sub_themes): return sub_theme = self.sub_themes[index] except Exception as exp: logger.error(exp) self.fail()
def stage_attributes(self, attribute: str, unit_value: str, bespoke_unit_tag: int, bespoke_sub_theme: int, description: str) -> db.Model: """ Stage Attributes :param attribute: Attribute :param unit_value: Unit Value :param bespoke_unit_tag: Unit Id :param bespoke_sub_theme: SubTheme Id :param description: Attributes Description :return: Attribute instance """ _a = Attributes._get_by_name_unit_unitvalue(attribute, bespoke_unit_tag, unit_value) if _a: logger.info( '{} attribute with Unit ID: {} and Unit Value: {} already exists' .format(attribute, str(bespoke_unit_tag), unit_value)) return _a a = Attributes(id=str(uuid.uuid4()), name=attribute, table_name=(attribute + '_' + str(uuid.uuid4()).replace('-', '_')), sub_theme=bespoke_sub_theme, unit=bespoke_unit_tag, unit_value=str(unit_value), description=description) a = a.save() return a
def test_return_attribute_of_subtheme(self): """ Adding a theme and subtheme to the database and then testing to see if it's data is retrieved correctly """ theme = Theme("Test_Theme") theme.save() theme.commit() sub_theme = SubTheme(theme.id, "Test_Sub_Theme") sub_theme.save() sub_theme.commit() attributes = Attributes("1234567890-123456789-123456789", "_test_attribute_", "_table_name_", sub_theme.id, 1) attributes.save() attributes.commit() response = self.testing_client.get('/data', data=dict(subtheme=theme.id)) self.assertEqual(theme.json(), response.get_json()) attributes.delete() attributes.commit() sub_theme.delete() sub_theme.commit() theme.delete() theme.commit()
def attribute_to_commit(self, attribute_data): # Stage Attribute commit for attr in attribute_data: a = Attributes(name=attr.attribute, sub_theme=attr.sub_theme, table_name=str(uuid.uuid4()), unit_value=attr.unit_value, description=attr.description, unit=attr.unit_type) a.save() attr.id = a.id self._print_in_middle('Saved Attributes')
def setUp(self) -> None: """ Setup FlaskClient for tests, create an admin user and create the authorization header for requests to the FlaskClient """ self.clean_up = [] self.client, self.app_context = self.create_test_client() self.user = self.create_admin_user() self.theme = self.create_dummy_theme() self.subtheme = self.create_dummy_subtheme() self.unit = self.get_dummy_unit() self.attribute = Attributes("A_TEST_ATTRIBUTE_ID_", "_TEST_ATTR_NAME_", "_A_TABLE_NAME", self.subtheme.id, self.unit.id, description="_A_CUSTOM_DESCRIPTION_") self.attribute.save() self.attribute.commit() self.clean_up.append(self.attribute)
def setUp(self): """ Setup a FlaskClient, AppContext, Admin user, Authorization header for requests to the Flask Client and a dummy Theme """ self.client, self.app_context = self.create_test_client() self.user = self.create_admin_user() self.auth_header = self.get_auth_header() self.unit = Unit("_test_unit_type_", "A test unit") self.unit.save() self.unit.commit() self.attribute = Attributes.get_by_name("_test_attribute_") self.theme = self.create_dummy_theme() self.subtheme = self.create_dummy_subtheme() if not self.attribute: self.attribute = Attributes("1234567890-123456789-123456789", "_test_attribute_", "_table_name_", self.subtheme.id, self.unit.id) self.attribute.save() self.attribute.commit() self.clean_up = [self.user, self.attribute, self.theme, self.subtheme, self.theme, self.unit]
def stage_attributes(self, attribute: str, unit_value: str, bespoke_unit_tag: int, bespoke_sub_theme: int, description: str): _a = Attributes._get_by_name_unit_unitvalue(attribute, bespoke_unit_tag, unit_value) if _a: print(attribute, 'attribute with Unit ID:', str(bespoke_unit_tag), 'and Unit Value:', unit_value, 'already exists') return _a a = Attributes(id=str(uuid.uuid4()), name=attribute, table_name=(attribute + '_' + str(uuid.uuid4()).replace('-', '_')), sub_theme=bespoke_sub_theme, unit=bespoke_unit_tag, unit_value=str(unit_value), description=description) a = a.save() return a