def create_test_data(self): self.clear_tables() Artists(artist='test', email='*****@*****.**').save() Artworks(artist=artist_db.artist_query('test'), artwork_name='test_art_1', price=123, available=False).save() Artworks(artist=artist_db.artist_query('test'), artwork_name='test_art_2', price=123).save() Artworks(artist=artist_db.artist_query('test'), artwork_name='test_art_3', price=123).save() Artists(artist='testNoArt', email='*****@*****.**').save()
def test_search_for_all_by_artist_no_art_in_db(self): self.clear_tables() self.create_test_data() artist_name = artist_db.artist_query('testNoArt').get() result = artist_db.search_all_by_artist(artist_name) art_count = result.count() self.assertEqual(art_count, 0)
def test_search_for_all_by_artist_in_db(self): self.clear_tables() self.create_test_data() index_count = 0 test_list = ['test_art_1', 'test_art_2', 'test_art_3'] artist_name = artist_db.artist_query('test').get() result = artist_db.search_all_by_artist(artist_name) for art in result: self.assertEqual(test_list[index_count], art.artwork_name) index_count += 1
def add_artist(): artist_name = ui.get_name() # artist query used to insure that the artist is not already in the database to avoid DB unique constraint error if artist_query(artist_name).count() == 0: email = ui.get_email() try: create_new_artist(artist_name, email) except EntryError: raise EntryError('Error adding artist\n') else: print('Artist already exists\n')
def add_art(): artist_name = artist_query(ui.get_name()) art_name = ui.get_art_name() value = ui.get_value() # if nothing is returnered from the artist query for the artist name, no attempt will be made to create the art in the db if artist_name.count() == 0: print('No artist in db\n') else: try: create_art_entry(artist_name, art_name, value) except IntegrityError as e: raise EntryError('No artist by that name in DB')
def test_artist_query_not_in_database(self): self.clear_tables() self.create_test_data() result = artist_db.artist_query('test_name_not_in_db') self.assertEqual(result, '')
def test_create_art_non_positive_float_price(self): self.clear_tables() with self.assertRaises(EntryError): artist_db.create_art_entry(artist_db.artist_query('test'), 'new_art', -500)
def test_art_name_already_exists(self): self.clear_tables() self.create_test_data() with self.assertRaises(EntryError): artist_db.create_art_entry(artist_db.artist_query('test'), 'test_art_2', 123)
def test_create_art_artist_exists(self): self.clear_tables() self.create_test_data() artist_db.create_art_entry(artist_db.artist_query('test'), 'new_art', 500) result = Artworks.select().where(Artworks.artwork_name == 'new_art').get() self.assertEqual(result.artwork_name, 'new_art')
def test_artist_query_in_database(self): self.clear_tables() self.create_test_data() result = artist_db.artist_query('test').get() self.assertEqual(result.artist, 'test')
def search_by_artist_available(): name = ui.get_name() artist_object = artist_query(name) artwork_objects = search_by_available(artist_object) utility.artwork_output(artwork_objects)