本文整理汇总了Python中tests.testutils.TestUtils._connect_db方法的典型用法代码示例。如果您正苦于以下问题:Python TestUtils._connect_db方法的具体用法?Python TestUtils._connect_db怎么用?Python TestUtils._connect_db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.testutils.TestUtils
的用法示例。
在下文中一共展示了TestUtils._connect_db方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sanity
# 需要导入模块: from tests.testutils import TestUtils [as 别名]
# 或者: from tests.testutils.TestUtils import _connect_db [as 别名]
def test_sanity(self):
# load album
tu = TestUtils()
assert tu.is_env_clean(tu.conf['lycheepath']), "env not clean"
# launch lycheesync
src = tu.conf['testphotopath']
lych = tu.conf['lycheepath']
conf = tu.conf['conf']
lib = tu.conf['testlib']
# album will be remove
album3_path = os.path.join(lib, "album3")
album_3_copy = os.path.join(lib, "album3_tmp")
if os.path.isdir(album_3_copy):
shutil.rmtree(album_3_copy)
shutil.copytree(album3_path, album_3_copy)
tu.load_photoset("album3_tmp")
# insert garbage files
lychee_photo_path = os.path.join(lych, "uploads", "big")
lib_photo_1 = os.path.join(lib, "album1", "large.1.jpg")
lib_photo_2 = os.path.join(lib, "real_date", "fruit-lychee.jpg")
lib_photo_3 = os.path.join(lib, "real_date", "fruit-lychee2.jpg")
lib_photo_4 = os.path.join(lib, "album2", "one-cut-lychee.jpg")
a_photo_1 = os.path.join(lychee_photo_path, "large.1.jpg")
a_photo_2 = os.path.join(lychee_photo_path, "link_src.jpg")
a_photo_3 = os.path.join(lychee_photo_path, "broken_link_src.jpg")
a_photo_4 = os.path.join(lychee_photo_path, "orphan_in_db.jpg")
a_link_1 = os.path.join(lychee_photo_path, "link_1.jpg")
a_link_2 = os.path.join(lychee_photo_path, "link_2.jpg")
a_link_3 = os.path.join(lychee_photo_path, "broken_link_3.jpg")
# FS orphan photo
shutil.copy(lib_photo_1, a_photo_1)
shutil.copy(lib_photo_2, a_photo_2)
shutil.copy(lib_photo_3, a_photo_3)
shutil.copy(lib_photo_4, a_photo_4)
# FS orphan os.link
os.link(a_photo_2, a_link_1)
# FS orphan os.symlink
os.symlink(a_photo_2, a_link_2)
# FS orphan broken link
os.symlink(a_photo_3, a_link_3)
os.remove(a_photo_3)
assert os.path.islink(a_link_3), "{} should be a link".format(a_link_3)
assert not(os.path.exists(a_link_3)), "{} should be a broken link".format(a_link_3)
try:
db = tu._connect_db()
# DB empty album in db
tu._exec_sql(
db,
"insert into lychee_albums (id, title, sysstamp, public, visible, downloadable) values (25, 'orphan', 123, 1, 1 ,1)")
# DB orphan photo in db
tu._exec_sql(
db,
"insert into lychee_photos (id, title, url, tags, public, type, width, height, size, iso, aperture, model, shutter, focal, star, thumbUrl,album, medium) values (2525, 'orphan', 'one-cut-lychee.jpg', '', 1, 'jpg', 500, 500, '2323px', '100', 'F5.5', 'FZ5', '1s', 'F2', 0, 'thumburl.jpg', 666, 0)")
finally:
db.close()
# test if well created
assert tu.photo_exists_in_db(2525), "orphan photo exists"
assert tu.album_exists_in_db('orphan'), "orphan album should exists"
# launch with link and sanity option
runner = CliRunner()
result = runner.invoke(main, [src, lych, conf, '-v', '-l', '--sanitycheck'])
# no crash
assert result.exit_code == 0, "process result is ok"
# garbage is gone
# DB
# no empty album
assert not tu.album_exists_in_db('orphan'), "orphan album should have been deleted"
# no orphan photo
assert not tu.photo_exists_in_db(2525), "orphan photo should have been deleted"
# FS
# no broken symlink
assert not(os.path.lexists(a_link_3)), "{} should have been deleted as a broken link".format(a_link_3)
assert not(os.path.islink(a_link_3)), "{} should have been deleted".format(a_link_3)
# no orphan link
assert not(os.path.lexists(a_link_1)), "{} should have been deleted as a broken link".format(a_link_1)
assert not(os.path.lexists(a_link_2)), "{} should have been deleted as a broken link".format(a_link_2)
# no orphan photo
assert not(os.path.exists(a_photo_1)), "{} should have been deleted as a orphan".format(a_photo_1)
assert not(os.path.exists(a_photo_2)), "{} should have been deleted as an orphan".format(a_photo_2)
assert not(os.path.exists(a_photo_3)), "{} should have been deleted as an orphan".format(a_photo_3)
assert not(os.path.exists(a_photo_4)), "{} should have been deleted as an orphan".format(a_photo_4)