예제 #1
0
    def test_db_artist_search(self):
        # Put artist in DB
        artist_in = artist_from_document(test_artist_data[0])
        artist_id = self.db.put_artist(artist_in)

        # Check non-matching search query
        search_results = self.db.search_artist('queers')
        self.assertEqual(0, len(search_results),
                         'Non-matching search should not return any result')

        # Check matching search query
        search_results = self.db.search_artist('queens')
        self.assertEqual(1, len(search_results),
                         'Matching search should return one result')

        # Check projection correctness
        artist_search_result = artist_from_document({
            '_id':
            ObjectId(artist_id),
            'name':
            artist_in.name,
            'image':
            artist_in.image,
            'genres': [
                'alternative rock', 'stoner rock', 'hard rock',
                'alternative metal'
            ]
        })
        self.assertDictEqual(
            asdict(artist_search_result), asdict(search_results[0]),
            'Artist search result should match search projection')
예제 #2
0
    def test_db_artist_crud(self):
        # Put an artist inside the database and get it back
        artist_in = artist_from_document(test_artist_data[0])
        artist_id = self.db.put_artist(artist_in)
        artist_out = self.db.get_artist(artist_id, include_releases=True)

        # Check if ID matches
        self.assertEqual(
            artist_id, artist_out.id,
            'The ID of the returned artist should match the one provided')

        # Check inserted artist has no releases
        self.assertIsNone(
            artist_out.releases,
            'The returned artist should still not have any release')

        # Check object equality
        artist_data_in = asdict(artist_in)
        artist_data_out = asdict(artist_out)
        artist_data_in['releases'] = None
        artist_data_out['id'] = None
        artist_data_out['counter'] = None  # defaults to 0
        self.assertDictEqual(
            artist_data_in, artist_data_out,
            'Inserted and retrieved artist should match '
            'except for ID (only in output) and releases (only in input)')

        # Check no longer exists after removal
        self.db.remove_artist(artist_id)
        self.assertIsNone(
            self.db.get_artist(artist_id),
            'The artist should no longer exist in the database after removal')
예제 #3
0
    def setUp(self):
        super().setUp()

        # Insert releases in the database
        self.artist_in = artist_from_document(test_artist_data[0])
        self.artist_id = self.db.put_artist(self.artist_in)

        self.release_ids = self.db.put_releases(self.artist_id,
                                                self.artist_in.releases)
예제 #4
0
def create_artist(name):
    if lastfm_api_key is None:
        artist_doc = {'name': name, 'sort_name': name}
        image = None
    else:
        lfm_data, mbid, image = lfm_get_artist_info(name)
        mb_data = mb_get_artist_info(mbid)
        artist_doc = {**lfm_data, **mb_data}
    return artist_from_document(artist_doc), image
예제 #5
0
    def post(self):
        """Create an artist
        ---
        tags: [metadata]
        requestBody:
          description: Artist to create
          required: true
          content:
            application/json:
              schema:
                type: object
                properties:
                  name: {type: string, description: Artist name}
                  country: {type: string, description: Artist country}
                  life_span: {type: dict, description: Artist life span (begin - end)}
                  genres: {type: list, description: Artist genres (list of string)}
                  bio: {type: string, description: Artist bio}
                  members: {type: list, description: Members (list of dict)}
                  links: {type: dict, description: Artist social links}
                required: [name]
              examples:
                0: {summary: 'Artist', value: {'name': 'NAME', 'country': 'COUNTRY',
                                               'life_span': {'begin': 1994, 'end': None},
                                               'genres': ['bla', 'asd'], 'bio': 'eheh',
                                               'members': [{'name': 'io', 'role': 'piano'}, {'name': 'me', 'role': 'guitar'}],
                                               'links': {'website': 'www', 'instagram': 'www', 'facebook': 'www', 'twitter': 'www'}}
                   }
        responses:
          201:
            description: Artist created
            content:
              application/json:
                example: {'artist_id': 'ARTIST_ID'}
          400:
            description: ID not valid
            content:
              application/json:
                example: {'message': 'ID not valid'}
        """
        data = _arg_parser_create.parse_args()

        user_id = security.get_jwt_identity()

        if not ObjectId.is_valid(user_id):
            return {'message': 'User ID not valid'}, HTTPStatus.BAD_REQUEST

        if db.get_user_type(user_id) != 'creator':
            return {'message': 'You are not a creator'}, HTTPStatus.UNAUTHORIZED

        data[c.ARTIST_CREATOR] = user_id
        data[c.ARTIST_SORT_NAME] = create_sort_name(data['name'])

        artist_id = db.put_artist(artist_from_document(data))

        return {'artist_id': artist_id}, HTTPStatus.CREATED
예제 #6
0
    def setUp(self):
        super().setUp()

        # Insert songs in the database
        self.artist_in = artist_from_document(test_artist_data[0])
        self.artist_id = self.db.put_artist(self.artist_in)

        self.release_ids = []
        self.song_ids = []

        for rel in self.artist_in.releases:
            rel_id = self.db.put_release(self.artist_id, rel)
            my_song_ids = self.db.put_songs(rel_id, rel.songs)

            self.release_ids.append(rel_id)
            self.song_ids.append(my_song_ids)