def test_add_art_with_existing_artist(self): self.remake_tables() Sethany = Artist.create(name='ats1', email_address='*****@*****.**') art1 = Art(artist=1, name='art1', price=0.50) add_art(art1) fetch_art = Art.select().where(Art.name == 'art1') self.assertTrue(art1 == fetch_art[0], msg=f'{art1} is not the same as {fetch_art}')
def test_add_art_with_missing_data(self): self.remake_tables() art1 = Art(artist=1, name='art1') with self.assertRaises(ArtError): add_art(art1)
def test_add_art_with_ununique_name(self): self.remake_tables() self.add_test_data() art1 = Art(artist=1, name='art1', price=0.50) with self.assertRaises(ArtError): add_art(art1)
def test_new_art_available_true(self): self.remake_tables() Artist.create(name='ats1', email_address='*****@*****.**') art1 = Art(artist=1, name='art1', price=5) add_art(art1) available_true = get_art_by_availability() self.assertEqual(art1, available_true[0])
def test_get_art_by_id(self): self.remake_tables() Artist.create(name='ats1', email_address='*****@*****.**') art1 = Art(artist=1, name='art1', price=5) add_art(art1) art1 = get_art_by_id(1) self.assertIsNotNone(art1)
def add_test_data(self): self.ats1 = Artist.create(name='ats1', email_address='*****@*****.**') self.ats2 = Artist.create(name='ats2', email_address='*****@*****.**') self.ats3 = Artist.create(name='ats3', email_address='*****@*****.**') self.art1 = Art.create(artist=1, name='art1', price=0.50, available=True) self.art2 = Art.create(artist=1, name='art2', price=50.00, available=True) self.art3 = Art.create(artist=1, name='art3', price=19.99, available=False)
def test_change_available_to_false_from_true(self): self.remake_tables() Artist.create(name='ats1', email_address='*****@*****.**') art1 = Art(artist=1, name='art1', price=5, available=True) add_art(art1) art1 = get_art_by_availability() self.assertTrue(art1[0].available) change_available(1) art1 = get_art_by_availability() self.assertTrue(art1 == [])
def test_delete_art(self): self.remake_tables() Artist.create(name='ats1', email_address='*****@*****.**') art1 = Art(artist=1, name='art1', price=5) add_art(art1) all_art = get_all_art() self.assertTrue(all_art != []) delete_art(1) all_art = get_all_art() self.assertTrue(all_art == [])
def show_artists_art(artist_id): artist = Artist.get_or_none(Artist.id == artist_id) query = Art.select().join( Artist, on=(Artist.id == Art.artist)).where(Artist.id == artist.id) return list(query)
def test_add_art_with_empty_artist_table(self): self.remake_tables() with self.assertRaises(ArtError): art1 = Art(artist=1, name='art1', price=0.50) add_art(art1)
def get_art_by_availability(): query = Art.select().where(Art.available == True) return list(query)
def get_art_by_id(art_id): return Art.get_or_none(Art.id == art_id)
def delete_art(art_id): rows_deleted = Art.delete().where(Art.id == art_id).execute() if rows_deleted == 0: raise ArtError('Error deleting art piece.')
def get_all_art(): query = Art.select() return list(query)