Exemplo n.º 1
0
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}.')
Exemplo n.º 2
0
    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_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)
Exemplo n.º 4
0
def get_all_artists():
    query = Artist.select()
    return list(query)