def test_add_artwork_with_artworks_in(self): self.add_test_data() artwork_count = artworkstore.artwork_count() aw = Artwork(artwork_name='aa') aw.save() self.assertTrue(artworkstore.exact_match(aw)) self.assertEqual(artwork_count + 1, artworkstore.artwork_count())
def add_artwork(artist, name, price):#adding new artwork try: artist_id = find_artist(artist) if artist_id: Artwork.create(artist = artist_id ,name = name, price = price).save print('art work added succesfully') else: print("not found") #except IntegrityError as e: # raise ArtError('error adding artwork because' + str(e)) except: print("art work not add")
def get_available_art_by_artist(artist): """ Get a list of art by artist that matches search term and art is aviailable :param term(the user input) :returns list of art by artist that is available """ available_art = Artwork.select().where( (Artwork.art_available == True) & (Artwork.artist == artist)) return available_art
def get_artwork_info(): """ Create a new Artwork from artist,name,price,availability provided by user :returns: a Artwork created from the info. """ art_name = input('Enter name of artwork: ') artist = input('Enter artist of artwork: ') art_price = input('Enter price of artwork: ') return Artwork(artist=artist, art_name=art_name, art_price=art_price)
def setUp(self): DB.drop_all() DB.create_all() artwork = Artwork( '1', 'Statue of David', 'statue', 'Statue', '1000', 'http://a5.files.biography.com/image/upload/c_fit,cs_srgb,dpr_1.0,h_1200,q_80,w_1200/MTE5NDg0MDU1MTYxNzY3NDM5.jpg' ) DB.session.add(artwork) DB.session.commit()
def artwork(key): """Get or update artwork.""" a = Artwork.get(key).to_dict_repr() if not a: exceptions.NotFound() return a
def change_availibility_status_to_available_or_sold( available, art_id):# gets artwork by ID and updates it's availibility status. art = Artwork.update(is_available = available).where(Artwork.id == art_id) updated_row = art.execute() return updated_row
def test_add_duplicate_errors(self): at = Artist(artist_name='cc', artist_email='*****@*****.**') at.save() with self.assertRaises(peewee.IntegrityError): at_dup = Artist(artist_name='cc', artist_email='hbgmail.com') at_dup.save() aw = Artwork(artwork_name='ccc') aw.save() with self.assertRaises(peewee.IntegrityError): aw_dup = Artwork(artwork_name='cc') aw_dup.save()
def get_all_artwork_of_artist(name):#returning all artwork by artist try: artwork_list = [] for art in Artwork.select().join(Artist).where(Artist.name == Artwork.artist): artwork_list.append(Artwork.name) return ', '.join(artwork_list) except: print('no found an art')
def get_available_artwork_of_artist(name):#returnig all available artwork by artist artwork_list = [] for art in Artwork.select().join(Artist).where( (Artist.name == artist) & (Artwork.available == True)): artwork_list.append(art.Artwork.name) return ', '.join(artwork_list)
def test_addition_deletion(self): """ Test adding and deleting """ artwork = Artwork( '2', 'Mona Lisa', 'paint', 'oil', '1800', 'http://a5.files.biography.com/image/upload/c_fit,cs_srgb,dpr_1.0,h_1200,q_80,w_1200/MTE5NDg0MDU1MTYxNzY3NDM5.jpg' ) DB.session.add(artwork) DB.session.commit() self.assertEqual(len(Artwork.query.all()), 2) Artwork.query.filter_by(title='Mona Lisa').delete() DB.session.commit() self.assertEqual(len(Artwork.query.all()), 1)
def add_art(): """Add new art site.""" if request.method == 'POST': # add new art! title = request.form['title'] artist = request.form['artist'] artist_desc = request.form['artist_desc'] address = request.form['address'] medium = request.form['medium'] art_desc = request.form['art_desc'] hint = request.form['hint'] latitude = geocode(address)[0]['geometry']['location']['lat'] longitude = geocode(address)[0]['geometry']['location']['lng'] file = request.files['image'] image_resize = process_image(file) img_filename = handle_img_upload(file) # create art instance art = Artwork(title = title, artist = artist, artist_desc = art_desc, location = from_shape(Point(latitude, longitude)), latitude = latitude, longitude = longitude, source='user', medium = medium, art_desc = art_desc, hint = hint, img_filename=img_filename) # add art to database db.session.add(art) db.session.commit() # add to the add table add = Add(user_id=current_user.user_id, art_id=art.art_id) db.session.add(add) db.session.commit() s3_resource.put_object(Bucket=bucket_name, Key=img_filename, Body=image_resize) return redirect('/') return render_template('add_art.html')
def get_artists_artwork(): while True: try: artist_name = input( 'Which artist\'s artwork work do you want to see? ') artwork_name = input( 'What is the name of the art piece you wish to see? ') if artist_name.length() and artwork_name.length() > 0: return Artwork(artwork_name) else: print( f'Could not find an art piece with the name of {artwork_name} by {artist_name}.' ) except EOFError: print('Please enter the artist name and artwork name.')
def add_art_db(): """add artwork to database""" artist = request.form.get('artist') title = request.form.get('title') medium = request.form.get('medium') substrate = request.form.get('substrate') genre = request.form.get('genre') year = request.form.get('year') url = request.form.get('url') # add artwork to db artwork = Artwork(artist_id=1, title=title, year_created=year, url=url) # add artwork to database db.session.add(artwork) db.session.commit() return render_template("welcome.html")
def add_test_artists(self): self.clear_database() self.artist1 = Artwork(artist_name='test artist1', artist_email='test email1') self.artist2 = Artwork(artist_name='test artist2', artist_email='test email2') self.artist3 = Artwork(artist_name='test artist3', artist_email='test email3') self.artist1.save() self.artist2.save() self.artist3.save()
def load_civic(): """Load Civic data.""" print("Civic Artwork") r = requests.get("https://data.sfgov.org/resource/7rjr-9n9w.json") civic = r.json() for item in civic: try: title = item["display_title"] artist = item["artist"] creation_date = item["creation_date"] #location = from_shape(Point(float(item["point"].get("latitude",0)), float(item["point"].get("longitude",0)))), latitude = item.get("latitude", 0) longitude = item.get("longitude", 0) # neighborhood_id=map_neighborhood(longitude, latitude) medium = item["medium"] art_desc = item["facility"] + item["current_location"] hint = item["location_description"] except KeyError as error: print("Key Error") art = Artwork( title=title, artist=artist, creation_date=creation_date, #location = from_shape(Point(float(item["point"].get("latitude",0)), float(item["point"].get("longitude",0)))), latitude=latitude, longitude=longitude, # neighborhood_id=neighborhood_id, source='civic', medium=medium, art_desc=art_desc, hint=hint) # add the data objects to the session db.session.add(art) # commit the changes to the db db.session.commit()
def load_artworks(data): """Load the jpg images location from the Met Museum APi to database""" art_title = data.get("title") obj_date = data.get("objectDate") # url from the Met API art_image_url = data.get("primaryImage") # rename the image as the base id given # i.e. DT1494.jpg art_image = os.path.basename(art_image_url) # get the content from the art_image_url img_data = requests.get(art_image_url).content art_piece = f"static/images/{art_image}" # write and save the image file into the folder with the basename with open(art_piece, 'wb') as handler: handler.write(img_data) artist_id = load_artists(data) type_code = load_art_types(data) medium_code = load_medium(data) art_thumb = load_thumbnail(art_image) artwork = Artwork(art_title=art_title, art_image=art_piece, art_thumb=art_thumb, artist_id=artist_id, type_code=type_code, medium_code=medium_code, obj_date=obj_date) db.session.add(artwork) db.session.commit() tag_mark = load_tag(data, artwork) full_pal = display_haishoku(art_image, artwork.artwork_id)
def add_test_art(self): self.clear_database() self.art1 = Artwork(art_name='test art1', art_price=50, artist='test artist1', art_available=True) self.art2 = Artwork(art_name='test art1', art_price=50, artist='test artist1', art_available=True) self.art3 = Artwork(art_name='test art1', art_price=50, artist='test artist1', art_available=True) self.art1.save() self.art2.save() self.art3.save()
def add_test_data(self): self.clear_artworkstore() self.at1 = Artist(artist_name='Very Nice Portrait', artist_email='*****@*****.**') self.aw1 = Artwork(artwork_name='Nicely Nice Nice', artwork_price=-100000, sold_artwork=True) self.at2 = Artist(artist_name='Biggy Portrait', artist_email='*****@*****.**') self.aw2 = Artwork(artwork_name='Artworks Artwork Artwork', artwork_price=100000, sold_artwork=False) self.at3 = Artist(artist_name='Long Sentences', artist_email='[email protected]') self.aw3 = Artwork(artwork_name='Collections of words', artwork_price=-0.10980) self.at1.save() self.at2.save() self.aw1.save() self.aw2.save() self.at3.save() self.aw3.save()
def test_is_artwork_in_store_not_present(self): not_in_store = Artwork(artwork_name='aaaa') self.add_test_data() self.assertFalse(artworkstore.exact_match(not_in_store))
def test_delete_artwork_not_in_store_errors(self): self.add_test_data() at = Artwork(artwork_name='Not in store') with self.assertRaises(ArtworkError): artworkstore.delete_artwork(at)
class TestArtworkstore(TestCase): def setUp(self): database_config.database_path = 'artworks.db' self.clear_artworkstore() def add_test_data(self): self.clear_artworkstore() self.at1 = Artist(artist_name='Very Nice Portrait', artist_email='*****@*****.**') self.aw1 = Artwork(artwork_name='Nicely Nice Nice', artwork_price=-100000, sold_artwork=True) self.at2 = Artist(artist_name='Biggy Portrait', artist_email='*****@*****.**') self.aw2 = Artwork(artwork_name='Artworks Artwork Artwork', artwork_price=100000, sold_artwork=False) self.at3 = Artist(artist_name='Long Sentences', artist_email='[email protected]') self.aw3 = Artwork(artwork_name='Collections of words', artwork_price=-0.10980) self.at1.save() self.at2.save() self.aw1.save() self.aw2.save() self.at3.save() self.aw3.save() def clear_artworkstore(self): artworkstore.delete_all_artwork() def test_add_artist_empty_store(self): at = Artist(artist_name='aa', artist_email='*****@*****.**') at.save() self.assertTrue(artworkstore.exact_match(at)) self.assertEqual(1, artworkstore.artist_count()) def test_add_artwork_empty_store(self): aw = Artwork(artwork_name='aaa') aw.save() self.assertTrue(artworkstore.exact_match(aw)) self.assertEqual(1, artworkstore.artwork_count()) def test_add_artwork_with_artworks_in(self): self.add_test_data() artwork_count = artworkstore.artwork_count() aw = Artwork(artwork_name='aa') aw.save() self.assertTrue(artworkstore.exact_match(aw)) self.assertEqual(artwork_count + 1, artworkstore.artwork_count()) def test_add_artist_with_artists_in(self): self.add_test_data() artist_count = artworkstore.artist_count() at = Artist(artist_name='aa', artist_email='jill.gmail.com') at.save() self.assertTrue(artworkstore.exact_match(at)) self.assertEqual(artist_count + 1, artworkstore.artist_count()) def test_add_duplicate_errors(self): at = Artist(artist_name='cc', artist_email='*****@*****.**') at.save() with self.assertRaises(peewee.IntegrityError): at_dup = Artist(artist_name='cc', artist_email='hbgmail.com') at_dup.save() aw = Artwork(artwork_name='ccc') aw.save() with self.assertRaises(peewee.IntegrityError): aw_dup = Artwork(artwork_name='cc') aw_dup.save() def test_add_artwork_errors_case_insensitive(self): aw = Artwork(artwork_name='cc', artwork_price=-12345) aw.save() with self.assertRaises(artwork_name='cc'): aw_dup = Artwork(artwork_name='Cc') aw_dup.save() def test_add_artist_errors_case_sensitive(self): at = Artist(artist_name='cc', artist_email='*****@*****.**') at.save() with self.assertRaises(peewee.IntegrityError): at_dup = Artist(artist_name='Cc', artist_email='*****@*****.**') at_dup.save() def test_get_artwork_id_found(self): self.add_test_data() result = artworkstore.get_artwork_by_id(self.aw1.id) self.assertEqual(result, self.aw1) def test_get_artwork_by_id_not_found(self): self.add_test_data() result = artworkstore.get_artwork_by_id(-1) self.assertIsNone(result) def test_delete_artwork_not_in_store_errors(self): self.add_test_data() at = Artwork(artwork_name='Not in store') with self.assertRaises(ArtworkError): artworkstore.delete_artwork(at) def test_count_artwork(self): self.add_test_data() count = artworkstore.artwork_count() self.assertEqual(3, count) def test_set_sold_artwork_sold(self): self.add_test_data() self.aw1.sold_artwork = True self.aw1.save() aw1_from_store = artworkstore.get_artwork_by_id(self.aw1.id) self.assertTrue(aw1_from_store.sold_artwork) def test_set_available_artwork(self): self.add_test_data() self.aw2.sold_artwork = True self.aw2.save() aw2_from_store = artworkstore.get_artwork_by_id(self.aw2.id) self.assertTrue(aw2_from_store.sold_artwork) def test_set_sold_artwork_available(self): self.add_test_data() self.aw1.sold_artwork = False self.aw1.save() aw1_from_store = artworkstore.get_artwork_by_id(self.aw1.id) self.assertFalse(aw1_from_store.sold_artwork) def test_set_available_artwork_available(self): self.add_test_data() self.aw2.sold_artwork = False self.aw2.save() aw2_from_store = artworkstore.get_artwork_by_id(self.aw2.id) self.assertFalse(aw2_from_store.sold_artwork) def test_is_artwork_in_store_present(self): self.add_test_data() self.assertTrue(artworkstore.exact_match(self.aw1)) self.assertTrue(artworkstore.exact_match(self.aw2)) self.assertTrue(artworkstore.exact_match(self.aw2)) def test_is_artwork_in_store_not_present(self): not_in_store = Artwork(artwork_name='aaaa') self.add_test_data() self.assertFalse(artworkstore.exact_match(not_in_store)) def test_is_artwork_in_store_empty_list(self): self.clear_artworkstore() not_in_store = Artwork(artwork_name='ccc') self.assertFalse(artworkstore.exact_match(not_in_store)) def test_search_artwork_artist_match(self): self.add_test_data() self.assertCountEqual([self.aw1], artworkstore.search_artist('Picasso')) def test_search_artwork_name_match(self): self.add_test_data() self.assertCountEqual([self.aw1, self.aw2], artworkstore.search_artwork('Artwork')) def test_search_artwork_not_found(self): self.add_test_data() self.assertCountEqual([], artworkstore.search_artwork('Not in list')) def test_search_artwork_empty_store(self): self.clear_artworkstore() self.assertEqual([], artworkstore.search_artwork('No artwork here')) def test_search_artwork_case_insensitive_name_match(self): self.add_test_data() self.assertCountEqual([self.aw1, self.aw2], artworkstore.search_artwork('aRtWork')) def test_exact_match_not_found(self): self.add_test_data() aw = Artwork(artwork_name='Long sentences') self.assertTrue(artworkstore.exact_match(aw)) def test_exact_match_not_found_name(self): self.add_test_data() aw = Artwork(artwork_name='Very long Sentence') self.assertFalse(artworkstore.exact_match(aw)) def test_exact_match_not_found_empty_store(self): aw = Artwork(artwork_name='Whatever') self.clear_artworkstore() self.assertFalse(artworkstore.exact_match(aw)) def test_get_artwork_sold_sold(self): self.add_test_data() sold_artwork = artworkstore.get_artwork_by_sold_value(True) self.assertCountEqual([self.aw2, self.aw3], sold_artwork) def test_get_artwork_sold_available(self): self.add_test_data() sold_artwork = artworkstore.get_artwork_by_sold_value(False) self.assertCountEqual([self.aw2, self.aw3], sold_artwork)
def test_add_artwork_errors_case_insensitive(self): aw = Artwork(artwork_name='cc', artwork_price=-12345) aw.save() with self.assertRaises(artwork_name='cc'): aw_dup = Artwork(artwork_name='Cc') aw_dup.save()
def delete_artwork(name):# deleting by artwork name delete_row = Artwork.delete().where(Artwork.name == name).execute() if not delete_row: print("art not deleted") else: print('you deleted succesfully')
def test_add_artwork_empty_store(self): aw = Artwork(artwork_name='aaa') aw.save() self.assertTrue(artworkstore.exact_match(aw)) self.assertEqual(1, artworkstore.artwork_count())
def test_exact_match_not_found_empty_store(self): aw = Artwork(artwork_name='Whatever') self.clear_artworkstore() self.assertFalse(artworkstore.exact_match(aw))
def test_exact_match_not_found_name(self): self.add_test_data() aw = Artwork(artwork_name='Very long Sentence') self.assertFalse(artworkstore.exact_match(aw))
def test_exact_match_not_found(self): self.add_test_data() aw = Artwork(artwork_name='Long sentences') self.assertTrue(artworkstore.exact_match(aw))
def get_artwork_info(): artwork_name = input('Enter the artwork name : ') artwork_price = float(input('Enter the artwork price:')) return Artwork(artwork_name=artwork_name, artwork_price=artwork_price)
def test_is_artwork_in_store_empty_list(self): self.clear_artworkstore() not_in_store = Artwork(artwork_name='ccc') self.assertFalse(artworkstore.exact_match(not_in_store))