Example #1
0
 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_add_duplicate_email(self):
        example = Artist('Example', '*****@*****.**')
        add_new_artist_to_db.add_artist_test(example)

        example2 = Artist('Example2', '*****@*****.**')
        added2 = add_new_artist_to_db.add_artist_test(example2)
        self.assertFalse(added2)

        excpeted_rows = [ ('Example', '*****@*****.**')]
        actual_rows = self.get_all_data_from_artistinfo()

        self.assertCountEqual(excpeted_rows, actual_rows)
Example #3
0
    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()
Example #4
0
    def test_add_duplicate_name_artist(self):

        example = Artist('Example', 25)
        added = db.add_artist(example)

        example2 = Artist('Example', 40)  # same name
        added2 = db.add_artist(example2)

        self.assertFalse(added2)

        expected_rows = [('Example', 25)]  # only one artist
        actual_rows = self.get_all_data()

        # assertCountEqual will compare two iterables, e.g. a list of tuples returned from DB
        self.assertCountEqual(expected_rows, actual_rows)
Example #5
0
def create_artist_submission():
    # called upon submitting the new artist listing form
    # TODO: insert form data as a new Venue record in the db, instead
    # TODO: modify data to be the data object returned from db insertion
    new_artist = Artist(
        name=request.form.get('name'),
        genres=request.form.get('genres'),
        city=request.form.get('city'),
        state=request.form.get('state'),
        phone=request.form.get('phone'),
        website_link=request.form.get('website_link'),
        facebook_link=request.form.get('facebook_link'),
        image_link=request.form.get('image_link'),
        seeking_venue=request.form.get('seeking_venue'),
        seeking_description=request.form.get('seeking_description'),
        past_shows_count=request.form.get('past_shows_count'),
        upcoming_shows_count=request.form.get('upcoming_shows_count'))
    try:
        data = new_artist
        db.session.add(data)
        db.session.commit()
        flash('Artist ' + request.form['name'] + ' was successfully listed!')
    except:
        db.session.rollback()
        flash('An error occurred. Artist ' + data.name +
              ' could not be listed.')
    finally:
        db.session.close()

    return render_template('pages/home.html')
Example #6
0
def create_artist_submission():
    try:
        artistData = request.form
        artistName = artistData.get('name')
        artistPhone = artistData.get('phone')
        artistCity = artistData.get('city')
        artistState = artistData.get('state')
        artistFacebookLink = artistData.get('facebook_link')
        artistGenresList = artistData.getlist('genres')
        artist = Artist(name=artistName,
                        phone=artistPhone,
                        city=artistCity,
                        state=artistState,
                        facebook_link=artistFacebookLink)
        for artistGenres in artistGenresList:
            if Genres.query.filter_by(name=artistGenres).first():
                artist.genres.append(
                    Genres.query.filter_by(name=artistGenres).first())
            else:
                genres = Genres(name=artistGenres)
                artist.genres.append(genres)
        db.session.add(artist)
        db.session.commit()
        flash('artist ' + request.form['name'] + ' was successfully listed!')
    except:
        db.session.rollback()
        flash('An error occurred. artist ' + request.form['name'] +
              ' could not be listed!')
    finally:
        db.session.close()

    return render_template('pages/home.html')
Example #7
0
def populateArtist(session, artist_name, album_name):
    """Populates the artist database table with data from the Spotify API.

    Keyword arguments:
    session -- the database session.
    artist_name -- the name of the artist to search for.
    album_name -- the name of the album to search for.
    """
    album_result = sp.search(q='artist:' + artist_name + ' album:'
                             + album_name, type='album')
    album = sp.album(album_result['albums']['items'][0]['uri'])
    artist = sp.artist(album['artists'][0]['uri'])

    # Populate artist information based on the album search.
    existing_artist = session.query(Artist).filter(
        Artist.uri == artist['uri']).first()
    if (existing_artist is None):
        artist_db_obj = Artist(name=artist['name'],
                               uri=artist['uri'],
                               popularity=artist['popularity'],
                               followers=artist['followers']['total'])
        session.add(artist_db_obj)
        session.commit()
    else:
        artist_db_obj = existing_artist

    populateAlbum(session, artist_db_obj, album)
Example #8
0
def create_artist_submission():
    form = ArtistForm()
    if not form.validate():
        flash(form.errors)
        return redirect(url_for('create_artist_form'))

    error = False
    try:
        artist = Artist()
        artist.name = request.form['name']
        artist.city = request.form['city']
        artist.state = request.form['state']
        artist.phone = request.form['phone']
        tmp_genres = request.form.getlist('genres')
        artist.genres = ','.join(tmp_genres)  # convert list to string
        artist.facebook_link = request.form['facebook_link']
        db.session.add(artist)
        db.session.commit()
    except:
        error = True
        db.session.rollback()
        print(sys.exc_info())
    finally:
        db.session.close()
        if error:
            flash('An error occurred. Artist ' + request.form['name'] +
                  ' could not be listed.')
        else:
            flash('Artist ' + request.form['name'] +
                  ' was successfully listed!')
        return render_template('pages/home.html')
Example #9
0
def artists_create_post():
    # called upon submitting the new artist listing form
    # TODO: insert form data as a new Venue record in the db, instead
    # TODO: modify data to be the data object returned from db insertion
    form = ArtistForm(request.form)
    if form.validate():
        name = form.name.data
        city = form.city.data
        state = form.state.data
        phone = form.phone.data
        genres = request.form.getlist('genres')
        facebook_link = form.facebook_link.data
        image_link = form.image_link.data

        artist = Artist(name=name,
                        city=city,
                        state=state,
                        phone=phone,
                        genres=genres,
                        facebook_link=facebook_link,
                        image_link=image_link)
        artist.insert()
        # db.session.add(artist)
        # db.session.commit()
        flash('Artist ' + form.name.data + ' was successfully listed!')
    else:
        print(form.errors)
        flash('An error occurred. Artist ' + form.name.data +
              ' could not be listed.')
        return render_template('forms/new_artist.html', form=form)
    # on successful db insert, flash success

    # TODO: on unsuccessful db insert, flash an error instead.
    # e.g., flash('An error occurred. Artist ' + data.name + ' could not be listed.')
    return render_template('pages/home.html')
    def test_artist_will_be_captilized(self):
        example = Artist('patrick mahomes', '*****@*****.**')
        add_new_artist_to_db.add_artist_test(example)
        excpected_rows = [('Patrick Mahomes', '*****@*****.**')]
        actual_rows = self.get_all_data_from_artistinfo()

        self.assertCountEqual(excpected_rows, actual_rows)
Example #11
0
def create_artist_submission():
    # called upon submitting the new artist listing form
    # TODO: insert form data as a new Venue record in the db, instead
    # TODO: modify data to be the data object returned from db insertion
    error = False
    try:
        data = Artist()
        data.name = request.form['name']
        data.city = request.form['city']
        data.state = request.form['state']
        data.phone = request.form['phone']
        data.genres = request.form.getlist('genres')
        data.facebook_link = request.form['facebook_link']

        if Artist.query.filter_by(name=data.name).filter_by(
                city=data.city).filter_by(state=data.state).filter_by(
                    phone=data.phone).count() != 0:
            flash("Artist " + request.form['name'] +
                  " is already in the database")
            return render_template('pages/home.html')

        db.session.add(data)
        db.session.commit()
    except:
        error = True
        db.session.rollback()
        print(sys.exc_info())
    finally:
        db.session.close()
    if error:
        flash('An error occurred. Artist ' + request.form['name'] +
              ' could not be listed.')
    if not error:
        flash('Artist ' + request.form['name'] + ' was successfully listed!')
    return render_template('pages/home.html')
Example #12
0
    def _read(self, path):
        self._setDefaults()

        config = ConfigParser.ConfigParser()
        if len(config.read([path])):
            for a in config.sections():
                if a != "global":
                    try:
                        name = config.get(a, "name")
                    except:
                        continue
                    try:
                        date = config.get(a, "date")
                    except:
                        date = None
                    try:
                        disambiguation = config.get(a, "disambiguation")
                    except:
                        disambiguation = None
                    self._artists.add(Artist(name, date, disambiguation))
                else:
                    try:
                        self._interval = config.getint(a, "interval")
                    except:
                        pass
                    try:
                        self._command = config.get(a, "command")
                    except:
                        pass
        else:
            raise ReadFailed
Example #13
0
 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())
Example #14
0
def create_artist_submission():
    # called upon submitting the new artist listing form
    form = ArtistForm()
    # DONE: insert form data as a new Artist record in the db, instead
    # DONE: modify data to be the data object returned from db insertion
    if request.method == 'POST':
        try:
            artist = Artist(
                    name=form.name.data,
                    city=form.city.data,
                    state=form.state.data,
                    genres=form.genres.data,
                    phone=form.phone.data,
                    image_link=form.image_link.data,
                    facebook_link=form.facebook_link.data
                    )

            db.session.add(artist)
            db.session.commit()

            # on successful db insert, flash success
            flash('Artist ' + form.name.data +
                  ' was successfully listed!')
        except:
            db.session.rollback()
            # DONE: on unsuccessful db insert, flash an error instead.
            flash('An error occurred. Artist ' + form.name.data +
                  ' could not be listed.')

        finally:
            db.session.close()
            return render_template('pages/home.html')
Example #15
0
def create_artist_submission():
    error = False
    artist = Artist()
    try:
        artist.name = request.form['name']
        artist.city = request.form['city']
        artist.state = request.form['state']
        artist.phone = request.form['phone'],
        artist.facebook_link = request.form['facebook_link'],
        artist.genres = request.form.getlist('genres'),
        artist.image_link = request.form['image_link']
        artist.website = request.form['website']
        artist.seeking_venue = True if 'seeking_venue' in request.form else False
        artist.seeking_description = request.form['seeking_description']
        db.session.add(artist)
        db.session.commit()
    except:
        error = True
        db.session.rollback()
        print(sys.exc_info())
    if error:
        flash('An error ' + request.form['name'] + ' could not be listed.')
    if not error:
        flash(request.form['name'] + ' was successfully added!')
    return render_template('pages/home.html')
Example #16
0
def add_artist(name, email):#adding new artist
    try:
        Artist(name = name, email = email).save()
        print("you added new name")
    #except IntegrityError as e:
        #raise ArtError('Error adding artist because' + str(e)) 
    except Exception as err:
        print(err)
Example #17
0
def add_artist(obj):
    with session_scope() as session:
        session.add(
            Artist(name=obj['name'],
                   spotify_id=obj['spotify_id'],
                   image_url=obj['images'][0]['url'],
                   followers=obj['followers'],
                   popularity=obj['popularity']))
Example #18
0
def register_fan():
    """Fan Registration page"""
    fan_info = request.form.get('fan_info')
    user_id = request.form.get('user_id')
    artist = Artist(user_id=user_id, bio=bio, statement=statement)
    db.session.add(artist)

    db.session.commit()
    return redirect("/")
Example #19
0
 def setUp(self):
     DB.drop_all()
     DB.create_all()
     artist1 = Artist(
         '1', 'Andy Warhol', '1900', 'Male', 'American',
         '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(artist1)
     DB.session.commit()
    def get_related_artists(self,
                            artist_id: str) -> Generator[Artist, None, None]:
        r = self._spotipy.artist_related_artists(artist_id)

        for artist_obj in r["artists"]:
            yield Artist(
                name=artist_obj["name"],
                identifier=artist_obj["id"],
                popularity=artist_obj["popularity"],
            )
    def test_add_artist(self):
        example = Artist('Example', '*****@*****.**')
        added = add_new_artist_to_db.add_artist_test(example)

        self.assertTrue(added)

        expected_rows = [ ('Example', '*****@*****.**')]
        actual_rows = self.get_all_data_from_artistinfo()
        self.assertCountEqual(expected_rows, actual_rows)

        example2 = Artist('Another Example', '*****@*****.**')
        added2 = add_new_artist_to_db.add_artist_test(example2)

        self.assertTrue(added2)

        expected_rows = [ ('Example', '*****@*****.**'), ('Another Example', '*****@*****.**')]
        actual_rows = self.get_all_data_from_artistinfo()

        self.assertCountEqual(expected_rows, actual_rows)
Example #22
0
def register_artist():
    """Artist Registration page"""
    bio = request.form.get('bio')
    statement = request.form.get('statement')
    user_id = request.form.get('user_id')
    artist = Artist(user_id=user_id, bio=bio, statement=statement)
    db.session.add(artist)

    db.session.commit()
    return redirect("/")
Example #23
0
    def test_add_artist(self):
        example = Artist('Example', 25)
        added = db.add_artist(example)

        self.assertTrue(added)

        expected_rows = [('Example', 25)]
        actual_rows = self.get_all_data()

        # assertCountEqual will compare two iterables, e.g. a list of tuples returned from DB
        self.assertCountEqual(expected_rows, actual_rows)

        example2 = Artist('Another Example', 30)
        added2 = db.add_artist(example2)

        self.assertTrue(added2)

        expected_rows = [('Example', 25), ('Another Example', 30)]
        actual_rows = self.get_all_data()

        self.assertCountEqual(expected_rows, actual_rows)
Example #24
0
def add_new_artist():
    name = input('Enter name: ')
    age = int(input('Enter age: '))

    artist = Artist(name, age)
    added = db.add_artist(artist)

    # todo distinguish between added, duplicate, unexpected error 
    if added:
        print('Added artist')
    else:
        print('Duplicate artist')
Example #25
0
def create_artist(artist_id, artist_name, popularity, image_url):
    """Create and return a new Artist"""

    artist = Artist(artist_id=artist_id,
                    artist_name=artist_name,
                    popularity=popularity,
                    image_url=image_url)

    db.session.add(artist)
    db.session.commit()

    return artist
Example #26
0
    def get_artist_from_context(self, context):
        """Return an Artist from a Context.

        Args:
            context (dict): The Context to convert from.

        Returns:
            Artist: The Artist.
        """
        artist_id = id_from_uri(context["uri"])
        result = self.get_api_v1("artists/{}".format(artist_id))
        return Artist(result or {})
Example #27
0
 def test_addition_deletion(self):
     """
     Test adding and deleting
     """
     artist2 = Artist(
         '2', 'Pablo Picasso', '1920', 'Male', 'Spain',
         '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(artist2)
     DB.session.commit()
     self.assertEqual(len(Artist.query.all()), 2)
     Artist.query.filter_by(name='Pablo Picasso').delete()
     DB.session.commit()
     self.assertEqual(len(Artist.query.all()), 1)
Example #28
0
def create_artist_submission():
    # called upon submitting the new artist listing form
    # TODO: insert form data as a new Venue record in the db, instead
    # TODO: modify data to be the data object returned from db insertion
    error = False
    data = {}
    try:
        name = request.form.get('name')
        city = request.form.get('city')
        state = request.form.get('state')
        phone = request.form.get('phone')
        image_link = request.form.get('image_link')
        genres = request.form.getlist('genres')
        facebook_link = request.form.get('facebook_link')
        website = request.form.get('website')
        seeking_venue = request.form.get('seeking_venue')
        if seeking_venue == "True":
            seeking_venue = True
        else:
            seeking_venue = False

        seeking_description = request.form.get('seeking_description')
        artist = Artist(name=name,
                        city=city,
                        state=state,
                        phone=phone,
                        image_link=image_link,
                        genres=genres,
                        facebook_link=facebook_link,
                        website=website,
                        seeking_venue=seeking_venue,
                        seeking_description=seeking_description)
        db.session.add(artist)
        db.session.commit()
        data = artist
        print(data)
    except:
        error = True
        db.session.rollback()
        print(sys.exc_info())
    finally:
        db.session.close()
    if error:
        flash('An error occurred. Artist ' + data.name +
              ' could not be listed.')
    else:
        # on successful db insert, flash success
        flash('Artist ' + request.form['name'] + ' was successfully listed!')
    return render_template('pages/home.html')
Example #29
0
def add_artist_users_artists(user, items):
    for item in items:
        if item['id'] not in [
                artist.spotify_artist_id for artist in user.artists
        ]:
            artist = Artist(spotify_artist_id=item['id'],
                            name=item['name'],
                            art_url=item['images'][0]['url'],
                            users=[user])
            db.session.add(artist)
        else:
            artist = db.session.query(Artist).filter(
                Artist.spotify_artist_id == item['id']).one()
            artist.users.append(user)
    db.session.commit()
Example #30
0
    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()