예제 #1
0
    def test_album_date(self):
        # album date should be equal to date/time original
        tu = TestUtils()
        assert tu.is_env_clean(tu.conf['lycheepath']), "env not clean"
        # load album x and y
        tu.load_photoset("real_date")

        src = tu.conf['testphotopath']
        lych = tu.conf['lycheepath']
        conf = tu.conf['conf']

        # run
        runner = CliRunner()
        result = runner.invoke(main, [src, lych, conf, '-v'])
        # no crash
        assert result.exit_code == 0, "process result is ok"

        assert tu.album_exists_in_db("real_date")
        # read album date for album1
        album1_date = tu.get_album_creation_date('real_date')

        real_date = datetime.datetime.fromtimestamp(album1_date)
        theorical_date = datetime.datetime(2011, 11, 11, 11, 11, 11)

        assert (real_date == theorical_date), "album date is 2011/11/11 11:11:11"
예제 #2
0
    def test_album_date(self):
        # album date should be equal to date/time original
        tu = TestUtils()
        assert tu.is_env_clean(tu.conf['lycheepath']), "env not clean"
        # load album x and y
        tu.load_photoset("real_date")

        src = tu.conf['testphotopath']
        lych = tu.conf['lycheepath']
        conf = tu.conf['conf']

        # run
        runner = CliRunner()
        result = runner.invoke(main, [src, lych, conf, '-v'])
        # no crash
        assert result.exit_code == 0, "process result is ok"

        assert tu.album_exists_in_db("real_date")
        # read album date for album1
        album1_date = tu.get_album_creation_date('real_date')

        real_date = datetime.datetime.fromtimestamp(album1_date)
        theorical_date = datetime.datetime(2011, 11, 11, 11, 11, 11)

        assert (
            real_date == theorical_date), "album date is 2011/11/11 11:11:11"
예제 #3
0
    def test_dash_d(self):
        try:
            # load album y
            tu = TestUtils()
            assert tu.is_env_clean(tu.conf['lycheepath']), "env not clean"
            # load album x and y
            tu.load_photoset("album1")
            # launch lycheesync
            src = tu.conf['testphotopath']
            lych = tu.conf['lycheepath']
            conf = tu.conf['conf']

            # run
            cmd = 'python main.py {} {} {} -r -v'.format(src, lych, conf)
            logger.info(cmd)
            retval = -1
            retval = subprocess.call(cmd, shell=True)
            # no crash
            assert (retval == 0), "process result is ok"

            assert tu.check_album_size(
                "album1") == 1, "album 1 not correctly loaded"

            # clean input pics content
            tu.delete_dir_content(src)
            # load album x
            tu.load_photoset("album3")

            # run
            cmd = 'python main.py {} {} {} -v -d'.format(src, lych, conf)
            logger.info(cmd)
            retval = -1
            retval = subprocess.call(cmd, shell=True)
            # no crash
            assert (retval == 0), "process result is ok"

            assert tu.check_album_size(
                "album3") == 4, "album 3 not correctly loaded"
            # album 1 has been deleted
            a1_check = tu.album_exists_in_db("album1")
            assert not (a1_check), "album 1  still exists"

            expected_albums = 1
            expected_photos = 4
            self.check_grand_total(expected_albums, expected_photos)

        except AssertionError:
            raise
        except Exception as e:
            logger.exception(e)
            assert False
예제 #4
0
    def test_dash_d(self):
        try:
            # load album y
            tu = TestUtils()
            assert tu.is_env_clean(tu.conf['lycheepath']), "env not clean"
            # load album x and y
            tu.load_photoset("album1")
            # launch lycheesync
            src = tu.conf['testphotopath']
            lych = tu.conf['lycheepath']
            conf = tu.conf['conf']

            # run
            cmd = 'python main.py {} {} {} -r -v'.format(src, lych, conf)
            logger.info(cmd)
            retval = -1
            retval = subprocess.call(cmd, shell=True)
            # no crash
            assert (retval == 0), "process result is ok"

            assert tu.check_album_size("album1") == 1, "album 1 not correctly loaded"

            # clean input pics content
            tu.delete_dir_content(src)
            # load album x
            tu.load_photoset("album3")

            # run
            cmd = 'python main.py {} {} {} -v -d'.format(src, lych, conf)
            logger.info(cmd)
            retval = -1
            retval = subprocess.call(cmd, shell=True)
            # no crash
            assert (retval == 0), "process result is ok"

            assert tu.check_album_size("album3") == 4, "album 3 not correctly loaded"
            # album 1 has been deleted
            a1_check = tu.album_exists_in_db("album1")
            assert not(a1_check), "album 1  still exists"

            expected_albums = 1
            expected_photos = 4
            self.check_grand_total(expected_albums, expected_photos)

        except AssertionError:
            raise
        except Exception as e:
            logger.exception(e)
            assert False
예제 #5
0
    def test_empty_album(self):
        # load 1 empty album
        tu = TestUtils()
        assert tu.is_env_clean(tu.conf['lycheepath']), "env not clean"
        # load unicode album name
        tu.load_photoset("empty_album")
        # launch lycheesync
        src = tu.conf['testphotopath']
        lych = tu.conf['lycheepath']
        conf = tu.conf['conf']

        # run
        runner = CliRunner()
        result = runner.invoke(main, [src, lych, conf, '-v'])
        # no crash
        assert result.exit_code == 0, "process result is ok"

        # no import
        assert tu.count_fs_photos() == 0, "there are photos are in fs"
        assert tu.count_db_photos() == 0, "there are photos are in db"
        assert not (tu.album_exists_in_db("empty_album")), "empty_album in db"
예제 #6
0
    def test_unicode(self):
        # there is a unicode album
        # there is a unicode photo
        tu = TestUtils()
        assert tu.is_env_clean(tu.conf['lycheepath']), "env not clean"
        # load unicode album name
        tu.load_photoset("FußÄ-Füße")
        # launch lycheesync
        src = tu.conf['testphotopath']
        lych = tu.conf['lycheepath']
        conf = tu.conf['conf']

        # run
        runner = CliRunner()
        result = runner.invoke(main, [src, lych, conf, '-v'])
        # no crash
        assert result.exit_code == 0, "process result is ok"

        assert tu.count_fs_photos() == 2, "photos are missing in fs"
        assert tu.count_db_photos() == 2, "photos are missing in db"
        assert tu.album_exists_in_db("FußÄ-Füße"), "unicode album is not in db"
예제 #7
0
    def test_empty_album(self):
        # load 1 empty album
        tu = TestUtils()
        assert tu.is_env_clean(tu.conf['lycheepath']), "env not clean"
        # load unicode album name
        tu.load_photoset("empty_album")
        # launch lycheesync
        src = tu.conf['testphotopath']
        lych = tu.conf['lycheepath']
        conf = tu.conf['conf']

        # run
        runner = CliRunner()
        result = runner.invoke(main, [src, lych, conf, '-v'])
        # no crash
        assert result.exit_code == 0, "process result is ok"

        # no import
        assert tu.count_fs_photos() == 0, "there are photos are in fs"
        assert tu.count_db_photos() == 0, "there are photos are in db"
        assert not(tu.album_exists_in_db("empty_album")), "empty_album in db"
예제 #8
0
    def test_unicode(self):
        # there is a unicode album
        # there is a unicode photo
        tu = TestUtils()
        assert tu.is_env_clean(tu.conf['lycheepath']), "env not clean"
        # load unicode album name
        tu.load_photoset("FußÄ-Füße")
        # launch lycheesync
        src = tu.conf['testphotopath']
        lych = tu.conf['lycheepath']
        conf = tu.conf['conf']

        # run
        runner = CliRunner()
        result = runner.invoke(main, [src, lych, conf, '-v'])
        # no crash
        assert result.exit_code == 0, "process result is ok"

        assert tu.count_fs_photos() == 2, "photos are missing in fs"
        assert tu.count_db_photos() == 2, "photos are missing in db"
        assert tu.album_exists_in_db("FußÄ-Füße"), "unicode album is not in db"
예제 #9
0
    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)
예제 #10
0
    def test_dash_r(self):
        try:
            tu = TestUtils()
            assert tu.is_env_clean(tu.conf['lycheepath']), "env not clean"
            # load album x and y
            tu.load_photoset("album1")
            tu.load_photoset("album3")

            # launch lycheesync
            src = tu.conf['testphotopath']
            lych = tu.conf['lycheepath']
            conf = tu.conf['conf']

            # run
            cmd = 'python main.py {} {} {} -r -v'.format(src, lych, conf)
            logger.info(cmd)
            retval = -1
            retval = subprocess.call(cmd, shell=True)
            # no crash
            assert (retval == 0), "process result is ok"

            assert tu.album_exists_in_db("album1")
            # read album date for album1
            album1_date = tu.get_album_creation_date('album1')
            # read album date for album3
            album3_date = tu.get_album_creation_date('album3')

            # empty tmp pictures folder
            tu.delete_dir_content(src)

            tu.dump_table('lychee_albums')
            # sleep 1 s to make time album signature different
            time.sleep(2)

            # load album3
            tu.load_photoset("album3")

            # run
            cmd = 'python main.py {} {} {} -r -v'.format(src, lych, conf)
            logger.info(cmd)
            retval = -1
            retval = subprocess.call(cmd, shell=True)
            # no crash
            assert (retval == 0), "process result is ok"

            album1_date_2 = tu.get_album_creation_date('album1')
            album3_date_2 = tu.get_album_creation_date('album3')
            tu.dump_table('lychee_albums')
            # y date < time
            assert album1_date == album1_date_2, 'album 1 is untouched'
            assert tu.check_album_size('album1') == 1

            # x date > time
            assert album3_date < album3_date_2, 'album 3 has been modified'
            assert tu.check_album_size('album3') == 4

            expected_albums = 2
            expected_photos = 5
            self.check_grand_total(expected_albums, expected_photos)

        except AssertionError:
            raise
        except Exception as e:
            logger.exception(e)
            assert False
예제 #11
0
    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)
예제 #12
0
    def test_dash_r(self):
        try:
            tu = TestUtils()
            assert tu.is_env_clean(tu.conf['lycheepath']), "env not clean"
            # load album x and y
            tu.load_photoset("album1")
            tu.load_photoset("album3")

            # launch lycheesync
            src = tu.conf['testphotopath']
            lych = tu.conf['lycheepath']
            conf = tu.conf['conf']

            # run
            cmd = 'python main.py {} {} {} -r -v'.format(src, lych, conf)
            logger.info(cmd)
            retval = -1
            retval = subprocess.call(cmd, shell=True)
            # no crash
            assert (retval == 0), "process result is ok"

            assert tu.album_exists_in_db("album1")
            # read album date for album1
            album1_date = tu.get_album_creation_date('album1')
            # read album date for album3
            album3_date = tu.get_album_creation_date('album3')

            # empty tmp pictures folder
            tu.delete_dir_content(src)

            tu.dump_table('lychee_albums')
            # sleep 1 s to make time album signature different
            time.sleep(2)

            # load album3
            tu.load_photoset("album3")

            # run
            cmd = 'python main.py {} {} {} -r -v'.format(src, lych, conf)
            logger.info(cmd)
            retval = -1
            retval = subprocess.call(cmd, shell=True)
            # no crash
            assert (retval == 0), "process result is ok"

            album1_date_2 = tu.get_album_creation_date('album1')
            album3_date_2 = tu.get_album_creation_date('album3')
            tu.dump_table('lychee_albums')
            # y date < time
            assert album1_date == album1_date_2, 'album 1 is untouched'
            assert tu.check_album_size('album1') == 1

            # x date > time
            assert album3_date < album3_date_2, 'album 3 has been modified'
            assert tu.check_album_size('album3') == 4

            expected_albums = 2
            expected_photos = 5
            self.check_grand_total(expected_albums, expected_photos)

        except AssertionError:
            raise
        except Exception as e:
            logger.exception(e)
            assert False