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 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)
Пример #3
0
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)