示例#1
0
    def test_delete_artwork(self):
        artist_db.database_setup()
        artist1 = artist_db.Artist("Ulrich nelson", "*****@*****.**")
        artist2 = artist_db.Artist("Katherina", "*****@*****.**")

        artwork1 = artist_db.Artwork("Dark", 78, artist1.name)
        artwork2 = artist_db.Artwork("Glass", 25, artist2.name)

        artist_db.insert_artist(artist1)  # adding artists
        artist_db.insert_artist(artist2)
        artist_db.add_artwork(artwork1)  # adding artwork
        artist_db.add_artwork(artwork2)

        artist_db.delete_an_artwork(
            artwork1.artwork)  # deleting a artwork by artwork name

        connection = sqlite3.connect(artist_db.DATABASE_FILENAME)
        cursor = connection.cursor()
        cursor.execute(
            "SELECT * FROM artwork WHERE name = ?",
            (artwork1.artwork, ))  # Selecting artwork by artwork name

        artwork_details = cursor.fetchall()
        connection.close()
        # we deleted the artwork, means the artwork does not exists in our database if we search it we will get zero row
        self.assertEqual(len(artwork_details), 0)
示例#2
0
    def test_search_all_artworks(self):
        artist_db.database_setup()
        artist1 = artist_db.Artist("Ulrich nelson", "*****@*****.**")
        artist2 = artist_db.Artist("Katherina", "*****@*****.**")

        artwork1 = artist_db.Artwork("Dark", 78, artist1.name)
        artwork2 = artist_db.Artwork("Glass", 25, artist2.name)

        artist_db.insert_artist(artist1)
        artist_db.insert_artist(artist2)
        artist_db.add_artwork(artwork1)
        artist_db.add_artwork(artwork2)

        # searching artworks with name
        artwork_details1 = artist_db.search_artwork(artist1.name)
        artwork_details2 = artist_db.search_artwork(artist2.name)

        # Checking if artwork is present or not for an artist name
        self.assertTrue(any("Dark" in row for row in artwork_details1))
        self.assertTrue(any("Glass" in row for row in artwork_details2))

        self.assertEqual(
            len(artwork_details1),
            1)  # Checking the length of fetched artworks by an artist name
        self.assertEqual(len(artwork_details2), 1)
示例#3
0
def choice_4():
    artwork = input("Enter name of artwork: ").title()
    price = int(input("Enter price of artwork: "))
    print("Enter name for which artwork belong to: ")
    name = input("Name: ").title()
    # creating instance of Artwork for inserting a new artwork in @artwork table
    new_artwork = artist_db.Artwork(artwork, price, name)
    print(artist_db.add_artwork(new_artwork))
示例#4
0
    def test_artwork_to_artist_relation(self):
        artist_db.database_setup()
        artist1 = artist_db.Artist("Hannah", "*****@*****.**")

        artist_db.insert_artist(artist1)  # adding artists
        artwork1 = artist_db.Artwork("Dark", 78, artist1.name)
        artist_db.add_artwork(artwork1)  # adding artwork
        connection = sqlite3.connect(artist_db.DATABASE_FILENAME)
        cursor = connection.cursor()
        # Selecting name of artist by an artwork
        cursor.execute(
            "SELECT name FROM artist WHERE artistID = (SELECT artistID FROM artwork WHERE name = 'Dark')"
        )
        name = cursor.fetchone()
        self.assertEqual(
            name[0],
            "Hannah")  # checking if fetched name is equal to "Hannah" or not
        connection.close()
示例#5
0
    def test_adding_artwork_without_artist(self):
        artist_db.database_setup()
        artist1 = artist_db.Artist("Ulrich nelson", "*****@*****.**")
        artist2 = artist_db.Artist("Katherina", "*****@*****.**")

        artwork1 = artist_db.Artwork("Dark", 78, artist1.name)
        artwork2 = artist_db.Artwork("Glass", 25,
                                     "Ben")  # Adding a artwork with no artist

        artist_db.insert_artist(artist1)
        artist_db.insert_artist(artist2)
        artist_db.add_artwork(artwork1)
        artist_db.add_artwork(artwork2)

        connection = sqlite3.connect(artist_db.DATABASE_FILENAME)
        cursor = connection.cursor()
        cursor.execute("SELECT * FROM artwork")
        # artwork can't be added without artist. we are adding a artwork for "Ben" which is not in artist table
        # We added 2 artwork, but second artwork can't be added due to constraints
        # that means length of artwork table has to be 1
        self.assertTrue(len(cursor.fetchall()) == 1)
        connection.close()
示例#6
0
    def test_add_artwork(self):
        artist_db.database_setup()
        artist1 = artist_db.Artist("Ulrich nelson", "*****@*****.**")
        artist2 = artist_db.Artist("Katherina", "*****@*****.**")

        artwork1 = artist_db.Artwork("Dark", 78, artist1.name)
        artwork2 = artist_db.Artwork("Glass", 25, artist2.name)

        artist_db.insert_artist(artist1)  # adding artists
        artist_db.insert_artist(artist2)
        artist_db.add_artwork(artwork1)  # adding artworks
        artist_db.add_artwork(artwork2)

        connection = sqlite3.connect(artist_db.DATABASE_FILENAME)
        connection.row_factory = sqlite3.Row
        cursor = connection.cursor()

        cursor.execute("SELECT * FROM artwork"
                       )  # selecting all artworks from artwork table
        artworks = cursor.fetchall()
        connection.close()
        # Checking if artworks are added or not
        self.assertTrue("Dark" and 78 and "available" in artworks[0])
        self.assertTrue("Glass" and 25 and "available" in artworks[1])
示例#7
0
    def test_change_availability(self):
        artist_db.database_setup()
        artist1 = artist_db.Artist("Ulrich nelson", "*****@*****.**")
        artist2 = artist_db.Artist("Katherina", "*****@*****.**")

        artwork1 = artist_db.Artwork("Dark", 78, artist1.name)
        artwork2 = artist_db.Artwork("Glass", 25, artist2.name)

        artist_db.insert_artist(artist1)  # adding artist
        artist_db.insert_artist(artist2)
        artist_db.add_artwork(artwork1)  # adding artwork
        artist_db.add_artwork(artwork2)

        artist_db.change_availability(
            artwork1.artwork
        )  # changing availability of an artwork by an artwork name

        connection = sqlite3.connect(artist_db.DATABASE_FILENAME)
        connection.row_factory = sqlite3.Row
        cursor = connection.cursor()

        # Fetching artworks from artwork table by an artwork name
        cursor.execute("SELECT * FROM artwork WHERE name = ?",
                       (artwork1.artwork, ))
        details = cursor.fetchone()
        self.assertEqual(
            details["availability"],
            "sold")  # Checking if its availability is changed to "sold" or not

        # Repeating above process again
        artist_db.change_availability(artwork1.artwork)
        cursor.execute("SELECT * FROM artwork WHERE name = ?",
                       (artwork1.artwork, ))
        details = cursor.fetchone()
        self.assertEqual(details["availability"], "available")
        connection.close()
示例#8
0
    def test_only_available_artworks(self):
        artist_db.database_setup()
        artist1 = artist_db.Artist("Hannah", "*****@*****.**")

        artist_db.insert_artist(artist1)
        artwork1 = artist_db.Artwork("Dark", 78, artist1.name)
        artwork2 = artist_db.Artwork("Glass", 25, artist1.name)
        artwork3 = artist_db.Artwork("Mountains", 168, artist1.name)

        artist_db.add_artwork(artwork1)
        artist_db.add_artwork(artwork2)
        artist_db.add_artwork(artwork3)

        artist_db.change_availability(
            artwork2.artwork
        )  # Changing availability of an artwork, from available to sold
        available_artwork = artist_db.search_artwork(artist1.name, "available")

        connection = sqlite3.connect(artist_db.DATABASE_FILENAME)
        connection.row_factory = sqlite3.Row
        cursor = connection.cursor()

        # searching available artwork by an artist name
        cursor.execute("SELECT artistID FROM artist WHERE name = ?",
                       (artist1.name, ))
        artist = cursor.fetchall()
        cursor.execute(
            "SELECT * FROM artwork WHERE availability = 'available' AND artistID = ?",
            (artist[0]["artistID"], ))
        available_artwork_table = cursor.fetchall()

        # checking if available artworks fetched from database by queries
        # is equal to available artworks returned by @artist_db module or not
        self.assertEqual(available_artwork_table[0]["availability"],
                         available_artwork[0]["availability"])
        self.assertTrue(available_artwork_table[1]["availability"],
                        available_artwork[1]["availability"])

        # checking if length of only available artworks fetched from database by queries
        # is equal to available artwork returned by @artist_db module or not
        self.assertEqual(len(available_artwork), len(available_artwork_table))
        connection.close()
示例#9
0
    def test_adding_duplicate_artwork(self):
        artist_db.database_setup()
        artist1 = artist_db.Artist("Ulrich nelson", "*****@*****.**")
        artist2 = artist_db.Artist("Katherina", "*****@*****.**")

        artwork1 = artist_db.Artwork("Dark", 78, artist1.name)
        artwork2 = artist_db.Artwork("Glass", 25, artist2.name)
        artwork3 = artist_db.Artwork("Glass", 25, artist1.name)

        artist_db.insert_artist(artist1)
        artist_db.insert_artist(artist2)
        artist_db.add_artwork(artwork1)
        artist_db.add_artwork(artwork2)
        artist_db.add_artwork(artwork3)  # Adding a duplicate artwork

        connection = sqlite3.connect(artist_db.DATABASE_FILENAME)
        cursor = connection.cursor()
        cursor.execute("SELECT * FROM artwork")  # selecting all artworks
        # if no duplicate artwork is added the length will not increase.
        # We added only three artworks but third one is duplicate that means length has to be 2
        self.assertEqual(len(cursor.fetchall()), 2)
        connection.close()