def test_update_on_new_import(self): """ Test whether a AttributeRange entry is updated when new values are imported """ o3 = Attributes.get_by_name("O3")[0] o3_attr_range = AttributeRange.get_by_attr_id(o3.id) before_import_latest_update = o3_attr_range.latest_update self.sess.execute( "INSERT INTO {} VALUES('A','99999999','{}','{}')".format( o3.table_name.lower(), datetime.now(), datetime.now())) self.sess.commit() response = self.testing_client.post('/importer_retry', data=dict( api_id=1), headers=self.access_token_header) self.assertEqual(response.status_code, 200) time.sleep(1) new_o3_attr_range = AttributeRange.get_by_attr_id(o3.id) self.assertEqual(new_o3_attr_range.maximum, 99999999) after_import_latest_update = new_o3_attr_range.latest_update self.assertGreater(after_import_latest_update, before_import_latest_update) self.sess.execute( "delete from {} where s_id='A'".format(o3.table_name.lower())) self.sess.commit()
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]