def test_stress_list(library_all): # given library = library_all # execute with session_scope(): artists = library.artists.list() # excpect assert 3 == len(artists) artists = library.artists.list() # excpect assert 3 == len(artists) with session_scope(): artists = library.artists.list() # excpect assert 3 == len(artists) artists = library.artists.list() # excpect assert 3 == len(artists)
def test_session(): Db.config_db(db_uri="sqlite:///:memory:", echo=False, create_db=True) with session_scope(): session_outer_id = id(Db.session) with session_scope(): session_inner_id = id(Db.session) assert session_outer_id == session_inner_id
def test_update_album(library_one_artist_one_album, first_artist, first_album): # given library = library_one_artist_one_album first_album.year += 100 # execute with session_scope(): library.albums.update(artist_name=first_artist.name, album=first_album) with session_scope(): #expect album_result = library.albums.read(artist_name=first_artist.name, name=first_album.name) assert album_result assert album_result.name == first_album.name assert album_result.year == first_album.year
def get(self, artist_name): with session_scope(): try: artist = self._library.artists.read(name=artist_name) return artist.json() except NotFoundException as e: return {"message": str(e)}, 404
def library_one_artist(library, first_artist): artist = Artist(name=first_artist.name) with session_scope(): library.artists.create(artist=artist) return library
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
def test_add_misssing_album(library, first_artist, first_album): # given # execute / expect with pytest.raises(NotFoundException): with session_scope(): library.albums.create(artist_name=first_artist.name, album=first_album)
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 post(self, artist_name): with session_scope(): artist = ArtistModel(name=artist_name) try: self._library.artists.create(artist=artist) except AlreadyExistsException as e: return {"message": str(e)}, 500
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
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)
def test_read_nonexisting_artist(library, first_artist): # given # execute with session_scope(): artist = library.artists.read(name=first_artist["name"]) # expect assert not artist
def test_delete_missing_artist(library, first_artist): # given # execute with pytest.raises(NotFoundException) as e: with session_scope(): library.artists.delete(name=first_artist.name) assert first_artist.name in str(e.value)
def test_add_existing_album_artist(library_one_artist_one_album, first_artist, first_album): # given library = library_one_artist_one_album # execute / expect with pytest.raises(AlreadyExistsException): with session_scope(): library.albums.create(artist=first_artist, album=first_album)
def test_add_existing_artist(library_one_artist, first_artist): # given library = library_one_artist # execute / expect with pytest.raises(AlreadyExistsException) as e: with session_scope(): library.artists.create(artist=first_artist) assert first_artist.name in str(e.value)
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()
def test_list_artist(library_one_artist): # given library = library_one_artist # execute with session_scope(): artists_result = library.artists.list() # expect assert 1 == len(artists_result)
def test_update_missing_album(library_one_artist, first_artist, first_album): # given library = library_one_artist first_album.year += 100 # execute with pytest.raises(NotFoundException): with session_scope(): library.albums.update(artist_name=first_artist.name, album=first_album)
def test_add_existing_artist(library_all): # given library = library_all # execute with session_scope(): artists = library.artists.list() # excpect assert 3 == len(artists)
def test_read_nonexisting_artist(library, first_artist): # given # execute with pytest.raises(NotFoundException): with session_scope(): artist = library.artists.read(name=first_artist.name) # expect assert not artist
def test_read_existing_artist(library_one_artist, first_artist): # given library = library_one_artist # execute with session_scope(): artist = library.artists.read(name=first_artist["name"]) # expect assert artist assert first_artist["name"] == artist.name
def test_list_album(library_one_artist_one_album, first_artist): # given library = library_one_artist_one_album artist_name = first_artist["name"] # execute with session_scope(): albums_result = library.albums.list(artist_name=artist_name) # expect assert 1 == len(albums_result)
def test_delete_artist(library_one_artist, first_artist): # given library = library_one_artist # execute with session_scope(): library.artists.delete(name=first_artist["name"]) # expect artist = library.artists.read(name=first_artist["name"]) assert not artist
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
def test_list_album(library_one_artist_one_album, first_artist): # given library = library_one_artist_one_album artist_name = first_artist.name # execute with session_scope(): albums = library.albums.list() # expect assert 1 == len(albums)
def test_add_artist(library, first_artist): # given # execute with session_scope(): library.artists.create(artist=first_artist) # expect artist_result = library.artists.read(name=first_artist.name) assert artist_result assert first_artist == artist_result
def test_read_nonexisting_album(library_one_artist, first_artist, first_album): # given library = library_one_artist artist_name = first_artist["name"] album_name = first_album["name"] # execute with session_scope(): album_result = library.albums.read(artist_name=artist_name, name=album_name) # except assert not album_result
def test_delete_artist(library_one_artist, first_artist): # given library = library_one_artist # execute with session_scope(): artist = library.artists.read(name=first_artist.name) library.artists.delete(artist=artist) # expect with pytest.raises(NotFoundException): artist = library.artists.read(name=first_artist.name)
def test_delete_album(library_one_artist_one_album, first_artist, first_album): # given library = library_one_artist_one_album artist_name = first_artist["name"] album_name = first_album["name"] # execute with session_scope(): library.albums.delete(artist_name=artist_name, name=album_name) # expect album_result = library.albums.read(artist_name=artist_name, name=album_name) assert not album_result
def test_read_existing_album(library_one_artist_one_album, first_artist, first_album): # given library = library_one_artist_one_album artist_name = first_artist["name"] album_name = first_album["name"] # execute with session_scope(): album_result = library.albums.read(artist_name=artist_name, name=album_name) # expect assert album_result assert album_name == album_result.name assert first_album["year"] == album_result.year