def test_licence_removal(self):
        license = License(id=u"Test", full_name=u'Test License')
        db.session.add(license)
        db.session.commit()
        self.assertEqual(License.query.count(), 1)

        license.delete()
        self.assertEqual(License.query.count(), 0)
Example #2
0
class LicenseData(object):
    """Licenses that can be used with reviews.

    If you add new ones or remove existing, make sure to update forms,
    views, and other stuff that depends on that.
    """
    cc_by_sa_3 = License(
        id=u"CC BY-SA 3.0",
        full_name=u"Creative Commons Attribution-ShareAlike 3.0 Unported",
        info_url=u"https://creativecommons.org/licenses/by-sa/3.0/")
    cc_by_nc_sa_3 = License(
        id=u"CC BY-NC-SA 3.0",
        full_name=
        u"Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported",
        info_url=u"https://creativecommons.org/licenses/by-nc-sa/3.0/")
Example #3
0
 def setUp(self):
     super(VoteTestCase, self).setUp()
     author = User(
         db_users.get_or_create('0',
                                new_user_data={
                                    "display_name": "Author",
                                }))
     self.user_1 = User(
         db_users.get_or_create('1',
                                new_user_data={
                                    "display_name": "Tester #1",
                                }))
     self.user_2 = User(
         db_users.get_or_create('2',
                                new_user_data={
                                    "display_name": "Tester #2",
                                }))
     license = License(id='Test', full_name='Test License')
     db.session.add(license)
     db.session.commit()
     self.review = Review.create(
         release_group='e7aad618-fa86-3983-9e77-405e21796eca',
         text="Testing!",
         user_id=author.id,
         is_draft=False,
         license_id=license.id)
Example #4
0
    def test_user_has_voted(self):
        # Review needs user
        user_1 = User(display_name=u'Tester #1')
        db.session.add(user_1)
        db.session.commit()

        # and license
        license = License(id=u"Test", full_name=u'Test License')
        db.session.add(license)
        db.session.commit()

        review = Review.create(
            user_id=user_1.id,
            release_group='e7aad618-fa86-3983-9e77-405e21796eca',
            text=u"Testing!",
            is_draft=False,
            license_id=license.id)
        db.session.add(review)
        db.session.commit()

        user_2 = User(display_name=u'Tester #2')
        db.session.add(user_2)
        db.session.commit()

        self.assertFalse(user_2.has_voted(review))
        Vote.create(user_2.id, review, True)
        self.assertTrue(user_2.has_voted(review))
Example #5
0
 def setUp(self):
     super(UserTestCase, self).setUp()
     self.user1 = User(
         db_users.get_or_create('tester_1',
                                new_user_data={
                                    "display_name": "test",
                                }))
     self.user2 = User(
         db_users.get_or_create("тестер",
                                new_user_data={
                                    "display_name": "test1",
                                }))
     self.author = User(
         db_users.get_or_create("author1",
                                new_user_data={
                                    "display_name": "Author1",
                                }))
     license = License(id='Test', full_name='Test License')
     db.session.add(license)
     db.session.commit()
     self.review = Review.create(
         release_group='e7aad618-fa86-3983-9e77-405e21796eca',
         text="Testing!",
         user_id=self.author.id,
         is_draft=False,
         license_id=license.id,
     )
     vote = db_vote.submit(self.user1.id, self.review.last_revision.id,
                           True)
     self.review_created = self.review.last_revision.timestamp
     self.review_id = self.review.id
     self.revision_id = self.review.last_revision.id
     self.report = SpamReport.create(self.revision_id, self.user1.id,
                                     "Testing Reason Report")
Example #6
0
    def test_vote_create(self):
        # Preparing test data
        author = User.get_or_create(u'Author', musicbrainz_id=u'0')
        user_1 = User.get_or_create(u'Tester #1', musicbrainz_id=u'1')
        user_2 = User.get_or_create(u'Tester #2', musicbrainz_id=u'2')
        license = License(id=u'Test', full_name=u'Test License')
        db.session.add(license)
        db.session.commit()
        review = Review.create(
            release_group='e7aad618-fa86-3983-9e77-405e21796eca',
            text=u"Testing!",
            user=author,
            is_draft=False,
            license_id=license.id)

        vote_u1_positive = Vote.create(user_1, review, True)

        votes = db.session.query(Vote).all()
        self.assertEqual(len(votes), 1)
        self.assertIn(vote_u1_positive, votes)

        vote_u2_negative = Vote.create(user_2, review, False)

        votes = db.session.query(Vote).all()
        self.assertEqual(len(votes), 2)
        self.assertIn(vote_u1_positive, votes)
        self.assertIn(vote_u2_negative, votes)
Example #7
0
 def setUp(self):
     super(ReviewViewsTestCase, self).setUp()
     self.user = User.get_or_create(
         u"Tester", u"aef06569-098f-4218-a577-b413944d9493")
     self.hacker = User.get_or_create(
         u"Hacker!", u"9371e5c7-5995-4471-a5a9-33481f897f9c")
     self.license = License.create(
         u"CC BY-SA 3.0", u"Created so we can fill the form correctly.")
     self.review_text = "Testing! This text should be on the page."
Example #8
0
    def setUp(self):
        super(ReviewTestCase, self).setUp()

        # Review needs user
        self.user = User(display_name=u'Tester')
        db.session.add(self.user)
        db.session.commit()

        # and license
        self.license = License(id=u"Test", full_name=u'Test License')
        db.session.add(self.license)
        db.session.commit()
 def setUp(self):
     super(ReviewViewsTestCase, self).setUp()
     self.user = User.get_or_create(u"Tester", u"aef06569-098f-4218-a577-b413944d9493")
     self.hacker = User.get_or_create(u"Hacker!", u"9371e5c7-5995-4471-a5a9-33481f897f9c")
     self.license = License.create(u"CC BY-SA 3.0", u"Created so we can fill the form correctly.")
     self.review = dict(
         entity_id="6b3cd75d-7453-39f3-86c4-1441f360e121",
         entity_type='release_group',
         user=self.user,
         text="Testing! This text should be on the page.",
         is_draft=False,
         license_id=self.license.id,
     )
Example #10
0
 def setUp(self):
     super(ReviewViewsTestCase, self).setUp()
     self.user = User.get_or_create("Tester", "aef06569-098f-4218-a577-b413944d9493")
     self.another_user = User.get_or_create("Hacker!", "9371e5c7-5995-4471-a5a9-33481f897f9c")
     self.license = License.create("CC BY-SA 3.0", "Created so we can fill the form correctly.")
     self.review = dict(
         entity_id="6b3cd75d-7453-39f3-86c4-1441f360e121",
         entity_type='release_group',
         user_id=self.user.id,
         text="Testing! This text should be on the page.",
         is_draft=False,
         license_id=self.license.id,
     )
Example #11
0
 def setUp(self):
     super(VoteTestCase, self).setUp()
     author = User.get_or_create('Author', musicbrainz_id='0')
     self.user_1 = User.get_or_create('Tester #1', musicbrainz_id='1')
     self.user_2 = User.get_or_create('Tester #2', musicbrainz_id='2')
     license = License(id='Test', full_name='Test License')
     db.session.add(license)
     db.session.commit()
     self.review = Review.create(
         release_group='e7aad618-fa86-3983-9e77-405e21796eca',
         text="Testing!",
         user=author,
         is_draft=False,
         license_id=license.id)
Example #12
0
    def setUp(self):
        super(RevisionTestCase, self).setUp()
        self.author = User.get_or_create('Author', musicbrainz_id='0')
        self.user_1 = User.get_or_create('Tester #1', musicbrainz_id='1')
        self.user_2 = User.get_or_create('Tester #2', musicbrainz_id='2')
        self.license = License(id=u'TEST', full_name=u"Test License")
        db.session.add(self.license)
        db.session.commit()

        self.review = Review.create(
            user_id=self.author.id,
            release_group='e7aad618-fa86-3983-9e77-405e21796eca',
            text=u"Testing!",
            is_draft=False,
            license_id=self.license.id)
    def setUp(self):
        super(RevisionTestCase, self).setUp()

        self.user = User(display_name=u'Tester')
        db.session.add(self.user)
        db.session.commit()

        self.license = License(id=u'TEST', full_name=u"Test License")
        db.session.add(self.license)
        db.session.commit()

        self.review = Review.create(user=self.user,
                                    release_group='e7aad618-fa86-3983-9e77-405e21796eca',
                                    text=u"Testing!",
                                    is_draft=False,
                                    license_id=self.license.id)
    def setUp(self):
        super(SpamReportTestCase, self).setUp()

        # We need review and a couple of users to work with.

        self.reporter = User(display_name=u'Reporter')
        db.session.add(self.reporter)

        self.author = User(display_name=u'Author')
        db.session.add(self.author)
        self.license = License(id=u'Test', full_name=u'Test License')
        db.session.add(self.license)
        db.session.flush()

        self.review = Review.create(user=self.author, release_group='e7aad618-fa86-3983-9e77-405e21796eca',
                                    text=u"It's... beautiful!", is_draft=False, license_id=self.license.id,
                                    language='en')
Example #15
0
    def setUp(self):
        super(ModerationLogCase, self).setUp()

        self.admin = User(display_name=u'Admin')
        db.session.add(self.admin)

        self.user = User(display_name=u'User')
        db.session.add(self.user)

        self.reason = "Testing Reason"

        self.license = License(id=u'Test', full_name=u'Test License')
        db.session.add(self.license)
        db.session.flush()

        self.review = Review.create(user_id=self.user.id, release_group='e7aad618-fa86-3983-9e77-405e21796eca',
                                    text=u"It's... beautiful!", is_draft=False, license_id=self.license.id,
                                    language='en')
Example #16
0
    def test_reviews_property(self):
        user = User(display_name=u'Tester')
        db.session.add(user)
        db.session.commit()

        self.assertEqual(len(user.reviews), 0)

        license = License(id=u"Test", full_name=u'Test License')
        db.session.add(license)
        db.session.flush()
        review = Review.create(
            user_id=user.id,
            release_group='e7aad618-fa86-3983-9e77-405e21796eca',
            text=u"Testing!",
            is_draft=False,
            license_id=license.id)
        db.session.add(review)
        db.session.commit()
        self.assertEqual(len(user.reviews), 1)

        review.delete()
        self.assertEqual(len(user.reviews), 0)
Example #17
0
    def test_update(self):
        review = Review.create(
            user=self.user,
            release_group='e7aad618-fa86-3983-9e77-405e21796eca',
            text=u"Awesome!",
            is_draft=True,
            license_id=self.license.id)
        another_license = License(id=u"License-2",
                                  full_name=u"Another license")
        db.session.add(another_license)
        db.session.commit()
        review.update(text=u"Bad...",
                      is_draft=False,
                      license_id=another_license.id,
                      language='es')

        # Checking if contents are updated
        retrieved_review = Review.query.all()[0]
        self.assertEqual(retrieved_review.text, u"Bad...")
        self.assertFalse(retrieved_review.is_draft)
        self.assertEqual(retrieved_review.license_id, another_license.id)
        self.assertEqual(retrieved_review.language, 'es')

        # Updating should create a new revision.
        self.assertEqual(len(retrieved_review.revisions), 2)
        self.assertNotEqual(retrieved_review.revisions[0],
                            retrieved_review.last_revision)

        # Let's try doing some things that shouldn't be allowed!

        with self.assertRaises(BadRequest):  # like changing license...
            review.update(text=u"Sucks!", license_id=self.license.id)

        with self.assertRaises(
                BadRequest):  # or converting review back to draft...
            review.update(text=u"Sucks!", is_draft=True)
Example #18
0
 def setUp(self):
     super(SpamReportTestCase, self).setUp()
     author = User(db_users.get_or_create('0', new_user_data={
         "display_name": "Author",
     }))
     self.user1 = User(db_users.get_or_create('1', new_user_data={
         "display_name": "Tester #1",
     }))
     self.user2 = User(db_users.get_or_create('2', new_user_data={
         "display_name": "Tester #2",
     }))
     license = License(id='Test', full_name='Test License')
     db.session.add(license)
     db.session.commit()
     self.review = Review.create(
             release_group='e7aad618-fa86-3983-9e77-405e21796eca',
             text="Testing!",
             user_id=author.id,
             is_draft=False,
             license_id=license.id,
     )
     self.revision_id = self.review.last_revision.id
     self.report = db_spam_report.create(self.revision_id, self.user1.id, "To test is this report")
     self.report_time = self.report["reported_at"]
Example #19
0
 def test_licence_creation(self):
     license = License(id=u"Test", full_name=u'Test License')
     db.session.add(license)
     db.session.commit()
     self.assertEqual(License.query.count(), 1)
 def setUp(self):
     super(ReviewViewsTestCase, self).setUp()
     self.user = User.get_or_create(u"Tester", u"aef06569-098f-4218-a577-b413944d9493")
     self.hacker = User.get_or_create(u"Hacker!", u"9371e5c7-5995-4471-a5a9-33481f897f9c")
     self.license = License.create(u"CC BY-SA 3.0", u"Created so we can fill the form correctly.")
     self.review_text = "Testing! This text should be on the page."