def test_importer(self):
        user = User(db_users.get_or_create(1, "Tester", new_user_data={
            "display_name": "test user",
        }))
        review = db_review.create(
            user_id=user.id,
            entity_id="e7aad618-fa86-3983-9e77-405e21796eca",
            entity_type="release_group",
            text="Testing",
            rating=5,
            is_draft=False,
            license_id=self.license["id"],
        )

        # Make dumps and delete entities
        self.runner.invoke(dump_manager.public, ['--location', self.tempdir])
        archives = get_archives(self.tempdir)
        db_review.delete(review['id'])
        db_users.delete(user.id)
        self.assertEqual(db_users.total_count(), 0)
        self.assertEqual(db_review.get_count(), 0)

        # Import dumps - cbdump.tar.bz2 and cbdump-reviews-all.tar.bz2 and check if data imported properly
        self.runner.invoke(dump_manager.importer, [archives['cbdump.tar.bz2']])
        self.assertEqual(db_users.total_count(), 1)

        self.runner.invoke(dump_manager.importer, [archives['cbdump-reviews-all.tar.bz2']])
        self.assertEqual(db_review.get_count(), 1)
def import_musicbrainz_row_ids():
    fix_exceptions()
    import_count = 0
    already_imported = 0
    deleted = 0
    not_found = 0

    all_users = db_users.list_users()
    musicbrainz_users = [
        x for x in all_users if x['musicbrainz_username'] is not None
    ]
    with musicbrainz_db.engine.connect() as mb_connection:
        with db.engine.connect() as connection:
            for user in musicbrainz_users:
                if user.get('musicbrainz_row_id') is not None:
                    already_imported += 1
                    continue

                name = user.get('musicbrainz_username')
                r = mb_connection.execute(
                    text("""
                    SELECT id
                      FROM editor
                     WHERE name = :musicbrainz_id
                    """), {
                        'musicbrainz_id': user['musicbrainz_username'],
                    })
                musicbrainz_row_id = None
                if r.rowcount > 0:
                    musicbrainz_row_id = r.fetchone()['id']
                    print('found %s - %s!!!!!!!!!!!!!!!!!!!' %
                          (name, musicbrainz_row_id))
                    import_count += 1
                    if not DRY_RUN:
                        connection.execute(
                            text("""
                            UPDATE "user"
                               SET musicbrainz_row_id = :musicbrainz_row_id
                             WHERE id = :id
                            """), {
                                'musicbrainz_row_id': musicbrainz_row_id,
                                'id': user['id'],
                            })
                else:
                    print('%s not found!' % name)
                    not_found += 1
                    if not DRY_RUN:
                        print('Deleting user %s' %
                              user['musicbrainz_username'])
                        db_users.delete(user['id'])
                        deleted += 1

    print('Total number of CB users: %d' % len(all_users))
    print('Total number of CB users with MusicBrainz usernames: %d' %
          len(musicbrainz_users))
    print('Total number of CB users with already imported row IDs: %d' %
          already_imported)
    print('Total number of CB users with row IDs that can be imported: %d' %
          import_count)
    print('Total number of CB users not found and deleted: %d' % not_found)
def import_musicbrainz_row_ids():
    fix_exceptions()
    import_count = 0
    already_imported = 0
    deleted = 0
    not_found = 0

    all_users = db_users.list_users()
    musicbrainz_users = [x for x in all_users if x['musicbrainz_username'] is not None]
    with musicbrainz_db.engine.connect() as mb_connection:
        with db.engine.connect() as connection:
            for user in musicbrainz_users:
                if user.get('musicbrainz_row_id') is not None:
                    already_imported += 1
                    continue

                name = user.get('musicbrainz_username')
                r = mb_connection.execute(text("""
                    SELECT id
                      FROM editor
                     WHERE name = :musicbrainz_id
                    """), {
                        'musicbrainz_id': user['musicbrainz_username'],
                    })
                musicbrainz_row_id = None
                if r.rowcount > 0:
                    musicbrainz_row_id = r.fetchone()['id']
                    print('found %s - %s!!!!!!!!!!!!!!!!!!!' % (name, musicbrainz_row_id))
                    import_count += 1
                    if not DRY_RUN:
                        connection.execute(text("""
                            UPDATE "user"
                               SET musicbrainz_row_id = :musicbrainz_row_id
                             WHERE id = :id
                            """), {
                                'musicbrainz_row_id': musicbrainz_row_id,
                                'id': user['id'],
                            })
                else:
                    print('%s not found!' % name)
                    not_found += 1
                    if not DRY_RUN:
                        print('Deleting user %s' % user['musicbrainz_username'])
                        db_users.delete(user['id'])
                        deleted += 1

    print('Total number of CB users: %d' % len(all_users))
    print('Total number of CB users with MusicBrainz usernames: %d' % len(musicbrainz_users))
    print('Total number of CB users with already imported row IDs: %d' % already_imported)
    print('Total number of CB users with row IDs that can be imported: %d' % import_count)
    print('Total number of CB users not found and deleted: %d' % not_found)
Example #4
0
    def test_delete(self):
        user1_id = self.user1.id
        db_users.delete(self.user1.id)
        # Votes should be deleted as well
        votes = db_users.get_votes(self.user1.id)
        self.assertEqual(len(votes), 0)
        # Spam Reports to be deleted as well
        spam_reports, count = db_spam_report.list_reports(user_id=user1_id)  # pylint: disable=unused-variable
        self.assertEqual(count, 0)

        db_users.delete(self.author.id)
        # Review should not exist
        reviews = db_users.get_reviews(self.author.id)
        self.assertEqual(len(reviews), 0)
Example #5
0
    def test_delete(self):

        user1_id = self.user1.id
        db_users.delete(self.user1.id)
        # Votes should be deleted as well
        votes = db_users.get_votes(self.user1.id)
        self.assertEqual(len(votes), 0)
        # Spam Reports to be deleted as well
        spam_reports, count = db_spam_report.list_reports(user_id=user1_id)  # pylint: disable=unused-variable
        self.assertEqual(count, 0)

        db_users.delete(self.author.id)
        # Review should not exist
        reviews = db_users.get_reviews(self.author.id)
        self.assertEqual(len(reviews), 0)
Example #6
0
    def test_delete(self):

        user1_id = self.user1.id
        db_users.delete(self.user1.id)
        # Votes should be deleted as well
        votes = db_users.get_votes(self.user1.id)
        self.assertEqual(len(votes), 0)
        # Spam Reports to be deleted as well
        spam_report_count = SpamReport.query.filter_by(
            user_id=user1_id, revision_id=self.revision_id).count()
        self.assertEqual(spam_report_count, 0)

        db_users.delete(self.author.id)
        # Review should not exist
        reviews = db_users.get_reviews(self.author.id)
        self.assertEqual(len(reviews), 0)
Example #7
0
def delete():
    if request.method == 'POST':
        db_users.delete(current_user.id)
        return redirect(url_for('frontend.index'))
    return render_template('profile/delete.html')
Example #8
0
def delete():
    if request.method == 'POST':
        db_users.delete(current_user.id)
        return redirect(url_for('frontend.index'))
    return render_template('profile/delete.html')