Best Python code snippet using autotest_python
migrate_unittest.py
Source: migrate_unittest.py
...20 @classmethod21 def get_migrations_done(cls):22 return cls.migrations_done23 @classmethod24 def clear_migrations_done(cls):25 cls.migrations_done = []26 @classmethod27 def do_migration(cls, version, direction):28 cls.migrations_done.append((version, direction))29 def migrate_up(self, manager):30 self.do_migration(self.version, 'up')31 if self.version == 1:32 manager.create_migrate_table()33 def migrate_down(self, manager):34 self.do_migration(self.version, 'down')35MIGRATIONS = [DummyMigration(n) for n in xrange(1, NUM_MIGRATIONS + 1)]36class TestableMigrationManager(migrate.MigrationManager):37 def _set_migrations_dir(self, migrations_dir=None):38 pass39 def get_migrations(self, minimum_version=None, maximum_version=None):40 minimum_version = minimum_version or 141 maximum_version = maximum_version or len(MIGRATIONS)42 return MIGRATIONS[minimum_version-1:maximum_version]43class MigrateManagerTest(unittest.TestCase):44 def setUp(self):45 self._database = (46 database_connection.DatabaseConnection.get_test_database())47 self._database.connect()48 self.manager = TestableMigrationManager(self._database)49 DummyMigration.clear_migrations_done()50 def tearDown(self):51 self._database.disconnect()52 def test_sync(self):53 self.manager.do_sync_db()54 self.assertEquals(self.manager.get_db_version(), NUM_MIGRATIONS)55 self.assertEquals(DummyMigration.get_migrations_done(),56 [(1, 'up'), (2, 'up'), (3, 'up')])57 DummyMigration.clear_migrations_done()58 self.manager.do_sync_db(0)59 self.assertEquals(self.manager.get_db_version(), 0)60 self.assertEquals(DummyMigration.get_migrations_done(),61 [(3, 'down'), (2, 'down'), (1, 'down')])62 def test_sync_one_by_one(self):63 for version in xrange(1, NUM_MIGRATIONS + 1):64 self.manager.do_sync_db(version)65 self.assertEquals(self.manager.get_db_version(),66 version)67 self.assertEquals(68 DummyMigration.get_migrations_done()[-1],69 (version, 'up'))70 for version in xrange(NUM_MIGRATIONS - 1, -1, -1):71 self.manager.do_sync_db(version)72 self.assertEquals(self.manager.get_db_version(),73 version)74 self.assertEquals(75 DummyMigration.get_migrations_done()[-1],76 (version + 1, 'down'))77 def test_null_sync(self):78 self.manager.do_sync_db()79 DummyMigration.clear_migrations_done()80 self.manager.do_sync_db()81 self.assertEquals(DummyMigration.get_migrations_done(), [])82class DummyMigrationManager(object):83 def __init__(self):84 self.calls = []85 def execute_script(self, script):86 self.calls.append(script)87class MigrationTest(unittest.TestCase):88 def setUp(self):89 self.manager = DummyMigrationManager()90 def _do_migration(self, migration_module):91 migration = migrate.Migration('name', 1, migration_module)92 migration.migrate_up(self.manager)93 migration.migrate_down(self.manager)...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!