def test_properly_logs_first_creation(self): obj = create_object(self.factory) obj.record_changes(changed_by=self.factory.user) change = Change.last_change(obj) self.assertIsNotNone(change) self.assertEqual(change.object_version, 1)
def test_properly_logs_first_creation(self): obj = create_object(self.factory) obj.save(changed_by=self.factory.user) change = Change.last_change(obj) self.assertIsNotNone(change) self.assertEqual(change.object_version, 1)
def test_logs_create_method(self): q = Query(name='Query', description='', query_text='', user=self.factory.user, data_source=self.factory.data_source, org=self.factory.org) change = Change.last_change(q) self.assertIsNotNone(change) self.assertEqual(q.user, change.user)
def test_logs_create_method(self): q = Query.create(name='Query', description='', query='', user=self.factory.user, data_source=self.factory.data_source, org=self.factory.org) change = Change.last_change(q) self.assertIsNotNone(change) self.assertEqual(q.user, change.user)
def test_skips_unnecessary_fields(self): obj = create_object(self.factory) obj.record_changes(changed_by=self.factory.user) change = Change.last_change(obj) self.assertIsNotNone(change) self.assertEqual(change.object_version, 1) for field in ChangeTrackingMixin.skipped_fields: self.assertNotIn(field, change.change)
def test_skips_unnecessary_fields(self): obj = create_object(self.factory) obj.save(changed_by=self.factory.user) change = Change.last_change(obj) self.assertIsNotNone(change) self.assertEqual(change.object_version, 1) for field in ChangeTrackingMixin.skipped_fields: self.assertNotIn(field, change.change)
def test_properly_log_modification(self): obj = create_object(self.factory) obj.save(changed_by=self.factory.user) obj.update_instance(name='Query 2', description='description', changed_by=self.factory.user) change = Change.last_change(obj) self.assertIsNotNone(change) self.assertEqual(change.object_version, 2) self.assertEqual(change.object_version, obj.version) self.assertIn('name', change.change) self.assertIn('description', change.change)
def test_properly_log_modification(self): obj = create_object(self.factory) obj.record_changes(changed_by=self.factory.user) obj.name = 'Query 2' obj.description = 'description' obj.record_changes(changed_by=self.factory.user) change = Change.last_change(obj) self.assertIsNotNone(change) self.assertEqual(change.object_version, 2) self.assertEqual(change.object_version, obj.version) self.assertIn('name', change.change) self.assertIn('description', change.change)
def test_properly_log_modification(self): obj = create_object(self.factory) obj.record_changes(changed_by=self.factory.user) obj.name = 'Query 2' obj.description = 'description' db.session.flush() obj.record_changes(changed_by=self.factory.user) change = Change.last_change(obj) self.assertIsNotNone(change) # TODO: https://github.com/getredash/redash/issues/1550 # self.assertEqual(change.object_version, 2) self.assertEqual(change.object_version, obj.version) self.assertIn('name', change.change) self.assertIn('description', change.change)
from __future__ import print_function from redash.models import db, Change, AccessPermission, Query, Dashboard from playhouse.migrate import PostgresqlMigrator, migrate if __name__ == '__main__': if not Change.table_exists(): Change.create_table() if not AccessPermission.table_exists(): AccessPermission.create_table() migrator = PostgresqlMigrator(db.database) try: migrate( migrator.add_column('queries', 'version', Query.version), migrator.add_column('dashboards', 'version', Dashboard.version) ) except Exception as ex: print("Error while adding version column to queries/dashboards. Maybe it already exists?") print(ex)
from redash.models import db, Change, AccessPermission, Query, Dashboard from playhouse.migrate import PostgresqlMigrator, migrate if __name__ == '__main__': if not Change.table_exists(): Change.create_table() if not AccessPermission.table_exists(): AccessPermission.create_table() migrator = PostgresqlMigrator(db.database) try: migrate( migrator.add_column('queries', 'version', Query.version), migrator.add_column('dashboards', 'version', Dashboard.version)) except Exception as ex: print "Error while adding version column to queries/dashboards. Maybe it already exists?" print ex