예제 #1
0
    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}')
예제 #2
0
    def test_add_art_with_missing_data(self):
        self.remake_tables()

        art1 = Art(artist=1, name='art1')

        with self.assertRaises(ArtError):
            add_art(art1)
예제 #3
0
    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)
예제 #4
0
    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])
예제 #5
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)
예제 #6
0
    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)
예제 #7
0
    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 == [])
예제 #8
0
    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 == [])
예제 #9
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)
예제 #10
0
 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)
예제 #11
0
def get_art_by_availability():
    query = Art.select().where(Art.available == True)
    return list(query)
예제 #12
0
def get_art_by_id(art_id):
    return Art.get_or_none(Art.id == art_id)
예제 #13
0
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.')
예제 #14
0
def get_all_art():
    query = Art.select()
    return list(query)