def test_create_db_1(self): """Verify new database is created.""" before = test_db_utils.check_if_exists(db=DB2) result = mysqldb_basic.create_db(self.engine, DB2) after = test_db_utils.check_if_exists(db=DB2) with self.subTest(): self.assertFalse(before) with self.subTest(): self.assertTrue(after) with self.subTest(): self.assertEqual(result, 0)
def test_drop_db_1(self): """Verify existing database is dropped.""" before = test_db_utils.check_if_exists() result = mysqldb_basic.drop_db(self.engine, DB) after = test_db_utils.check_if_exists() with self.subTest(): self.assertTrue(before) with self.subTest(): self.assertFalse(after) with self.subTest(): self.assertEqual(result, 0)
def test_drop_db_2(self): """Verify non-existing database is not dropped.""" before = test_db_utils.check_if_exists(db=DB2) result = mysqldb_basic.drop_db(self.engine, DB2) after = test_db_utils.check_if_exists(db=DB2) with self.subTest(): self.assertFalse(before) with self.subTest(): self.assertFalse(after) with self.subTest(): self.assertEqual(result, 1)
def tearDown(self): self.engine.dispose() # Remove 'pdm_test_db' exists = test_db_utils.check_if_exists() if exists: test_db_utils.remove_db() # Remove 'pdm_test_2' exists = test_db_utils.check_if_exists(db=DB2) if exists: test_db_utils.remove_db(db=DB2)
def test_create_db_2(self): """Verify already-existing database is not created.""" before = test_db_utils.check_if_exists() result = mysqldb_basic.create_db(self.engine, DB) after = test_db_utils.check_if_exists() with self.subTest(): self.assertTrue(before) with self.subTest(): self.assertTrue(after) with self.subTest(): self.assertEqual(result, 1)
def test_drop_create_db_2(self): """Verify non-existing database is not dropped but is created.""" before = test_db_utils.check_if_exists(DB2) result = mysqldb_basic.drop_create_db(self.engine, DB2) after = test_db_utils.check_if_exists(DB2) after_tables = test_db_utils.execute(TABLES_QUERY.format(DB2), db=DB2) with self.subTest(): self.assertFalse(before) with self.subTest(): self.assertTrue(after) with self.subTest(): self.assertEqual(result, 0) with self.subTest(): self.assertTrue(len(after_tables) == 0)
def setUp(self): if not test_db_utils.check_if_exists(): test_db_utils.create_empty_test_db() alchemist = AlchemyHandler(username=USER, password=PWD, database=DB) alchemist.connect() self.engine = alchemist.engine
def test_drop_create_db_1(self): """Verify already-existing database is dropped and created.""" before = test_db_utils.check_if_exists() before_tables = test_db_utils.execute(TABLES_QUERY.format(DB)) result = mysqldb_basic.drop_create_db(self.engine, DB) after = test_db_utils.check_if_exists() after_tables = test_db_utils.execute(TABLES_QUERY.format(DB)) with self.subTest(): self.assertTrue(before) with self.subTest(): self.assertTrue(after) with self.subTest(): self.assertEqual(result, 0) with self.subTest(): self.assertTrue(len(before_tables) > 0) with self.subTest(): self.assertTrue(len(after_tables) == 0)
def tearDown(self): shutil.rmtree(results_path) # Remove 'pdm_test_db' test_db_utils.remove_db() # Remove 'pdm_test_2' exists = test_db_utils.check_if_exists(db=DB2) if exists: test_db_utils.remove_db(db=DB2)
def setUp(self): if not test_db_utils.check_if_exists(): test_db_utils.create_empty_test_db() else: if len(test_db_utils.execute(TABLES_QUERY.format(DB))) == 0: test_db_utils.install_db(test_db_utils.SCHEMA_FILEPATH) self.alchemist = AlchemyHandler(username=USER, password=PWD) self.alchemist.build_engine() self.engine = self.alchemist.engine
def test_drop_create_db_3(self, drop_mock): """Verify database is not created if there is an error during drop.""" drop_mock.return_value = 1 before = test_db_utils.check_if_exists() before_tables = test_db_utils.execute(TABLES_QUERY.format(DB)) result = mysqldb_basic.drop_create_db(self.engine, DB) after = test_db_utils.check_if_exists() after_tables = test_db_utils.execute(TABLES_QUERY.format(DB)) with self.subTest(): self.assertTrue(before) with self.subTest(): self.assertTrue(after) with self.subTest(): self.assertEqual(result, 1) with self.subTest(): self.assertTrue(len(before_tables) > 0) with self.subTest(): self.assertTrue(len(after_tables) > 0) with self.subTest(): self.assertEqual(len(before_tables), len(after_tables)) with self.subTest(): drop_mock.assert_called()
def tearDown(self): if test_db_utils.check_if_exists(db=DB2): test_db_utils.remove_db(db=DB2) self.engine.dispose()
def tearDownClass(self): if test_db_utils.check_if_exists(): test_db_utils.remove_db() if test_db_utils.check_if_exists(db=DB2): test_db_utils.remove_db(db=DB2)
def tearDown(self): shutil.rmtree(output_path) exists = test_db_utils.check_if_exists() if exists: test_db_utils.remove_db()
# TODO: There are two test files staged on the server for testing purposes. # pdm_test_db.sql and pdm_test_db.version. If get_db pipeline is revamped # to utilize urllib3, these two test files could be removed, and the tests # would only need to confirm the download request status attribute = 200. DB2 = "pdm_test_db" # Create the main test directory in which all files will be # created and managed. Gets created once for all tests. test_root_dir = Path("/tmp", "pdm_utils_tests_get_db") if test_root_dir.exists() == True: shutil.rmtree(test_root_dir) test_root_dir.mkdir() # Since these tests involve creating new databases, be sure to # remove the existing test database if it is already present. exists = test_db_utils.check_if_exists() if exists: test_db_utils.remove_db() # Within main test folder, this new folder will be created/removed # for each test. Within the output_folder, get_db will dynamically create # a new folder, but only if files are downloaded. output_path = Path(test_root_dir, "output") results_path = Path(output_path, get_db.RESULTS_FOLDER) def get_unparsed_args(db=DB, option=None, download=False, output_folder=None, version=False,
def tearDown(self): # Remove 'pdm_test_2' exists = test_db_utils.check_if_exists(db=DB2) if exists: test_db_utils.remove_db(db=DB2)