예제 #1
0
def test_delete_album(app, json_albums):
    # if data_albums.name.isspace() or not data_albums.name:
    if json_albums.name.isspace() or not json_albums.name:
        return
    albums = [json_albums]
    # albums = [data_albums]

    list_missing_items = app.album.missing_albums(albums)

    if len(list_missing_items) > 0:
        for item in list_missing_items:
            app.album.create(
                Album(name=item.name,
                      privacy="private_but_link",
                      description="album for delete"))
    list_albums_for_delete = app.album.info_about_albums_by_name(albums)
    list_files_in_random_albums = app.file.get_images_in_albums(
        list_albums_for_delete)

    if list_files_in_random_albums:
        files_for_move = File(
            list_name=list([x.name for x in list_files_in_random_albums]))
        app.album.move_to_album([Album(name="")], files_for_move)

    app.album.delete(list_albums_for_delete)
    new_list_albums = app.album.get_album_list()
    diff_items = app.album.difference_in_lists_album(albums, new_list_albums)
    assert diff_items == albums
    assert len(new_list_albums) == app.album.count_ui_albums()
예제 #2
0
    def update(*, artist_name: str, album: AlbumModel) -> None:
        album_result = Albums.read(artist_name=artist_name, name=album.name)
        if not album_result:
            raise NotFoundException(
                f"Artist '{artist_name}', Album '{album.name}' not found in Library."
            )

        album_result.year = album.year
        album.update()
예제 #3
0
    def create(*,
               album: AlbumModel,
               artist: ArtistModel = None,
               artist_name: str = None) -> None:
        assert artist or artist_name

        if not artist:
            artist = ArtistModel.read(name=artist_name)

        artist.albums.append(album)
        album.save()
예제 #4
0
    def put(self, artist_name, album_name):
        req_data = Albums.req_parser.parse_args()

        album = AlbumModel(name=album_name, year=req_data["year"])
        with session_scope():
            try:
                self._library.albums.update(artist_name=artist_name,
                                            album=album)
                return album.json(), 201
            except NotFoundException as e:
                return {"message": str(e)}, 404
예제 #5
0
 def img_list(cls, user_name, album_id):
     album = Album.select().get(album_id)
     assert album is not None
     imgs = []
     if album.is_public or album.user_name == user_name:
         imgs = Image.select().filter(Image.album_id == album_id).order_by(Image.id.desc()).all()
     layout = []
     img_data = []
     row_height = [0] * 4
     for index, img in enumerate(imgs):
         img_data.append(img.get_json())
         row_num = math.floor(index / 4)
         col_num = index % 4
         log.info(f'{row_num}, {col_num}')
         layout.append({
             'x': 6 * (index % 4),
             'y': sum([lo.get('h', 0) if (i % 6) == col_num else 0 for i, lo in enumerate(layout)]),
             'w': 6,
             'h': math.floor(img.height / img.width * 9),
             'i': img.key,
             'index': index
         })
     for i in range(4):
         row_height[i] = sum([lo.get('h', 0) if index % 4 == i else 0 for index, lo in enumerate(layout)])
     return {
         'imgs': img_data,
         'layout': layout,
         'row_height': max(row_height)
     }
예제 #6
0
 def album_list(cls, user_name, is_public=True):
     if is_public:
         albums = Album.select().filter(Album.is_public).all()
     else:
         albums = Album.select().filter(Album.user_name == user_name).all()
     user_names = [album.user_name for album in albums]
     users = User.select().filter(User.name.in_(user_names)).all()
     user_map = {}
     for user in users:
         user_map[user.name] = user
     results = []
     for album in albums:
         result = album.get_json()
         result['user'] = user_map.get(album.user_name).get_json()
         results.append(result)
     return results
예제 #7
0
def library_one_artist_one_album(library_one_artist, first_artist, first_album):
    album = Album(name=first_album["name"], year=first_album["year"])

    with session_scope():
        library_one_artist.albums.create(artist_name=first_artist.name, album=album)

    return library_one_artist
예제 #8
0
def test_add_misssing_album(library, first_artist, first_album):
    # given
    album = Album(name=first_album["name"], year=first_album["year"])

    # execute / expect
    with pytest.raises(NotFoundException):
        with session_scope():
            library.albums.create(artist_name=first_artist["name"], album=album)
def select_all():
    albums = []
    sql = 'SELECT * FROM albums'
    results = run_sql(sql)
    for row in results:
        album = Album(row['title'], row['genre'], row['artist_id'], row['id'])
        albums.append(album)
    return albums
예제 #10
0
def test_init():
    # given

    # execute
    album = Album(name="album", year=2000)

    # expect
    assert "album" == album.name
    assert 2000 == album.year
def albums_by_artist(artist):
    albums = []
    sql = 'SELECT * FROM albums WHERE artist_id = %s'
    values = [artist.id]
    results = run_sql(sql, values)
    for row in results:
        album = Album(row['title'], row['genre'], row['artist_id'], row['id'])
        albums.append(album)
    return albums
예제 #12
0
 def delete_album(cls, id):
     album = Album.select().get(id)
     assert album is not None
     images = Image.select().filter(Image.album_id == id).all()
     for image in images:
         QiniuService.delete_file(config.QI_NIU.get('img_bucket_name'), image.key)
         image.delete()
     album.delete()
     return True
예제 #13
0
def library_one_artist_one_album(library_one_artist, first_artist, first_album):
    # Copy the album so that it isn't added to the session twice.

    album = Album(name=first_album.name, year=first_album.year)

    with session_scope():
        library_one_artist.albums.create(artist_name=first_artist.name, album=album)

    return library_one_artist
예제 #14
0
def test_add_existing_album(library_one_artist_one_album, first_artist, first_album):
    # given
    library = library_one_artist_one_album
    album = Album(name=first_album["name"], year=first_album["year"])

    # execute / expect
    with pytest.raises(AlreadyExistsException):
        with session_scope():
            library.albums.create(artist_name=first_artist["name"], album=album)
예제 #15
0
def populate_db():
    with session_scope():
        for artist_data in test_data:
            artist = Artist(name=artist_data["name"])

            for album_data in artist_data["albums"]:
                album = Album(**album_data)
                artist.albums.append(album)

            artist.save()
예제 #16
0
def test_add_existing_album(library_one_artist_one_album, first_artist,
                            first_album):
    # given
    library = library_one_artist_one_album
    artist_name = first_artist["name"]
    album = Album(name=first_album["name"], year=first_album["year"])

    # execute / expect
    with pytest.raises(ValueError):
        library.albums.create(artist_name=artist_name, album=album)
예제 #17
0
def random_album(len_name=10, len_description=150, list_privacy=None):
    if list_privacy is None:
        list_privacy = ["public", "private", "private_but_link", "password"]
    name = random_string(len_name)
    description = random_string(len_description)
    privacy = random_existing_item(list_privacy)
    password = None
    if privacy == "password":
        password = random_string(8, item="pass")
    return Album(name=name, description=description, privacy=privacy, album_pass=password)
예제 #18
0
 def get_album_list(self):
     if self.album_cache is None:
         wd = self.app.wd
         self.app.navigation.open_albums_page()
         self.album_cache = []
         list_albums = wd.find_elements_by_css_selector(".list-item")
         for item in list_albums:
             id_album = item.get_attribute("data-id")
             name = item.get_attribute("data-name")
             privacy = item.get_attribute("data-privacy")
             self.album_cache.append(Album(name=name, privacy=privacy, id_album=id_album))
     return list(self.album_cache)
예제 #19
0
    def info_about_albums_by_name(self, album_list):
        info = []
        list_album = self.get_album_list()

        for album in album_list:
            if album.name == "":
                info.append(Album(name="", id_album=""))
            else:
                for i in list_album:
                    if i.name == album.name:
                        info.append(i)
        return info
예제 #20
0
    def missing_albums(self, list_albums):
        self.app.navigation.open_albums_page()

        list_info_albums = self.info_about_albums_by_name(list_albums)
        missing_list = []
        if not list_info_albums:
            missing_list = list_albums
        elif len(list_albums) > len(list_info_albums):
            for album in list_albums:
                for item in list_info_albums:
                    if album.name != item.name:
                        missing_list.append(Album(name=album.name))

        return missing_list
예제 #21
0
def test_init(first_artist):
    # given
    albums = []
    for album in first_artist["albums"]:
        albums.append(Album(**album))

    artist_name = first_artist["name"]

    # execute
    artist = Artist(name=artist_name, albums=albums)

    # expect
    assert artist_name == artist.name
    assert len(first_artist["albums"]) == len(artist.albums)
예제 #22
0
def test_add_album(library_one_artist, first_artist, first_album):
    # given
    library = library_one_artist
    album = Album(name=first_album["name"], year=first_album["year"])

    # execute
    with session_scope():
        library.albums.create(artist_name=first_artist["name"], album=album)

        # expect
        album_result = library.albums.read(artist_name=first_artist["name"], name=first_album["name"])

        assert album_result
        assert album.name == album_result.name
        assert album.year == album_result.year
예제 #23
0
def test_delete_random_album(app):
    random_albums = app.random_existing_items(item="album", random_number=2)

    if not random_albums:
        app.album.create(
            Album(name=random_string(10),
                  description=random_string(50),
                  privacy=random_existing_item(["public",
                                                "private_but_link"])))

    list_files_in_random_albums = app.file.get_images_in_albums(random_albums)

    if list_files_in_random_albums:
        files_for_move = File(
            list_name=list([x.name for x in list_files_in_random_albums]))
        app.album.move_to_album([Album(name="")], files_for_move)

    app.album.delete(random_albums)
    new_list_albums = app.album.get_album_list()
    diff_items = app.album.difference_in_lists_album(random_albums,
                                                     new_list_albums)
    # assert sorted(diff_items, key=lambda albums: albums.name) == sorted(random_albums, key=lambda albums: albums.name)
    assert diff_items == random_albums
    assert len(new_list_albums) == app.album.count_ui_albums()
예제 #24
0
def test_move_random(app):
    files = app.random_existing_items(item="file", random_number=3)
    files_name = File(list_name=[x.name for x in files])
    album = app.random_existing_items(item="album", random_number=1)

    if not album:
        new_album = Album(name=random_string(max_len_str=10),
                          privacy=random_existing_item(
                              ["public", "private_but_link"]))
        app.album.create(new_album)
        album = app.album.info_about_albums_by_name([new_album])
    app.album.move_to_album(album=album, file=files_name)
    new_info_about_files = app.file.get_info_about_file(files_name)

    for item in new_info_about_files:
        assert item.id_album == album[0].id_album
예제 #25
0
def test_no_albums_init(data):
    """Check to make sure that two different empty artists don't have the same list of albums."""
    # given
    artist_name_1 = data[0]["name"]
    artist_name_2 = data[1]["name"]

    # execute
    artist_1 = Artist(name=artist_name_1)
    artist_2 = Artist(name=artist_name_2)

    # expect
    assert artist_1.albums is not artist_2.albums

    artist_1.albums.append(Album(name="abc", year=2000))
    assert 1 == len(artist_1.albums)
    assert 0 == len(artist_2.albums)
def test_move_file_to_the_album(app, data_move_to_album):
    files_name = data_move_to_album[0]
    album = app.album.info_about_albums_by_name([data_move_to_album[1]])
    params = data_move_to_album[2]
    if not album:
        album = Album(name=data_move_to_album[1].name,
                      description=random_string(max_len_str=20),
                      privacy=random_existing_item(
                          ["public", "private_but_link", "private"]))
        app.album.create(album)
        album = app.album.info_about_albums_by_name([data_move_to_album[1]])

    if params is not None:
        app.album.move_to_album(album=album, param=data_move_to_album[2])
    else:
        app.album.move_to_album(album=album, file=files_name)
    if files_name is None:
        new_info_about_files = app.file.get_file_list()
    else:
        new_info_about_files = app.file.get_info_about_file(files_name)
    for item in new_info_about_files:
        assert item.id_album == album[0].id_album
예제 #27
0
 def create_album(cls, user_name, id, title, cover_url, description):
     if id is not None:
         album = Album.select().get(id)
         assert album is not None
         album.title = title
         album.cover_url = cover_url
         album.description = description
         album.update()
         return id
     else:
         existed = Album.select().filter(Album.title == title, Album.user_name == user_name).first() is not None
         if existed:
             raise ServerException(msg='相册已存在')
         album = Album(
             title=title,
             cover_url=cover_url,
             description=description,
             user_name=user_name,
         )
         album.insert()
     return Album.select().filter(Album.title == title, Album.user_name == user_name).one().id
예제 #28
0
 def image_list(cls, user_name, album_id):
     album = Album.select().get(album_id)
     if album.is_public or album.user_name == user_name:
         return Image.select().filter(Image.album_id == album_id).all()
     return []
예제 #29
0
from model.file import File
from model.album import Album

testdata = [[
    File(list_name=["atom", "ae", "179px"]),
    Album(name="random albums name"), None
], [File(list_name=["ledy", "639px", "atom"]),
    Album(name=""), None], [None,
                            Album(name="2 album for move files"), "all"],
            [None, Album(name=""), "all"]]
예제 #30
0
 def list() -> List[AlbumModel]:
     return AlbumModel.list()