def test_add_artist_empty_database(self): self.remake_tables() ats1 = Artist(name='ats1', email_address='*****@*****.**') add_artist(ats1) fetch_artist = Artist.select().where(Artist.name == 'ats1') self.assertTrue(ats1 == fetch_artist[0])
def test_add_artist_with_duplicate_name(self): self.remake_tables() ats1 = Artist(name='ats1', email_address='*****@*****.**') add_artist(ats1) ats2 = Artist(name='ats1', email_address='*****@*****.**') with self.assertRaises(ArtistError): add_artist(ats2)
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 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 create_artist_submission(): # called upon submitting the new artist listing form # TODO: insert form data as a new Venue record in the db, instead form = ArtistForm() error = False try: artist = Artist() form.populate_obj(artist) db.session.add(artist) db.session.commit() except: error = True db.session.rollback() flash('An error occurred. Artist ' + artist.name + ' could not be listed.') finally: db.session.close() if not error: flash('Artist ' + request.form['name'] + ' was successfully listed!') # TODO: modify data to be the data object returned from db insertion # on successful db insert, flash success # TODO: on unsuccessful db insert, flash an error instead. return render_template('pages/home.html')
def test_get_artist_by_nonexistant_id(self): self.remake_tables() ats1 = Artist(name='ats1', email_address='*****@*****.**') add_artist(ats1) self.assertEqual(get_artist_id('ats1'), 1)
def test_add_artist(self): response = self.test_app.post('/artists', data={ 'name': 'cheese', 'email_address': '*****@*****.**' }, follow_redirects=True) # response is a stream of bytes, decode into a string response_text = response.data.decode('utf-8') # Is data on page? Could also assert data is in specific HTML elements with a little more work # A HTML parser like Beautiful Soup could help https://www.crummy.com/software/BeautifulSoup/bs4/doc/ self.assertIn('cheese', response_text) self.assertIn('*****@*****.**', response_text) # Flash message shown? self.assertIn('The new artist has been added!', response_text) # new artist in DB? new_artist = Artist.get_or_none( Artist.name == 'cheese' and Artist.email_address == '*****@*****.**') self.assertIsNotNone(new_artist)
def get_artist_id(artist_name): try: query = Artist.select().where(Artist.name == artist_name) artist_id = list(query) return artist_id[0].id except: raise ArtistNotFound(f'There is no artist named {artist_name}.')
def test_get_artist_by_id(self): self.remake_tables() ats1 = Artist(name='ats1', email_address='*****@*****.**') add_artist(ats1) fetch_artist = get_artist_id('ats1') self.assertEqual(ats1.id, fetch_artist)
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_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_no_duplicate_artist(self): self.ats1 = Artist.create(name='ats1', email_address='*****@*****.**').save() response = self.test_app.post('/artists', data={ 'name': 'ats1', 'email_address': '*****@*****.**' }) response_text = response.data.decode('utf-8') # Flash message? self.assertIn('Artist ats1 has already been added.', response_text) # Still only one artist in DB? artist_count = Artist.select().count() self.assertEqual(1, artist_count) # artist with duplicate name not added new_artist = Artist.get_or_none( Artist.name == 'ats1' and Artist.email_address == '*****@*****.**') self.assertIsNone(new_artist)
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 get_all_artists(): query = Artist.select() return list(query)
def test_add_artist_missing_data(self): self.remake_tables() ats1 = Artist(name='ats1') with self.assertRaises(ArtistError): add_artist(ats1)