Ejemplo n.º 1
0
 def test_list_licenses(self):
     db_license.create(
         id="test",
         full_name="Test license",
         info_url="www.example.com",
     )
     licenses = db_license.list_licenses()
     self.assertDictEqual(
         {
             "id": "test",
             "full_name": "Test license",
             "info_url": "www.example.com"
         }, licenses[0])
Ejemplo n.º 2
0
def install(*args):
    for arg in args:
        if arg == LicenseData:
            for key, entity in arg.__dict__.items():
                if not key.startswith("__"):
                    try:
                        db_license.create(
                            id=entity["id"],
                            full_name=entity["full_name"],
                            info_url=entity["info_url"],
                        )
                    except Exception:
                        print('Failed to add %s!' % key)
                    else:
                        print('Added %s.' % key)
Ejemplo n.º 3
0
def install(*args):
    for arg in args:
        if arg == LicenseData:
            for key, entity in arg.__dict__.items():
                if not key.startswith("__"):
                    try:
                        db_license.create(
                            id=entity["id"],
                            full_name=entity["full_name"],
                            info_url=entity["info_url"],
                        )
                    except Exception:
                        print('Failed to add %s!' % key)
                    else:
                        print('Added %s.' % key)
Ejemplo n.º 4
0
    def setUp(self):
        super(StatisticsTestCase, self).setUp()

        self.user_1 = User(
            db_users.get_or_create(1,
                                   "Tester 1",
                                   new_user_data={
                                       "display_name": "test user 1",
                                   }))
        self.user_2 = User(
            db_users.get_or_create(2,
                                   "Tester 2",
                                   new_user_data={
                                       "display_name": "test user 2",
                                   }))

        self.license = db_license.create(
            id=u'Test',
            full_name=u"Test License",
        )

        # totally disable cache get or set
        cache.gen_key = MagicMock(return_value=None)
        cache.get = MagicMock(return_value=None)
        cache.set = MagicMock(return_value=None)
Ejemplo n.º 5
0
 def test_delete_license():
     license = db_license.create(
         id="test",
         full_name="Test license",
         info_url="www.example.com",
     )
     db_license.delete(id=license["id"])
Ejemplo n.º 6
0
    def setUp(self):
        super(CommentTestCase, self).setUp()

        # each comment requires a user and a review, so create a user and
        # review

        # create user
        self.user = User(db_users.get_or_create(1, "Tester", new_user_data={
            "display_name": "test user",
        }))
        self.user_2 = User(db_users.get_or_create(2, "Tester 2", new_user_data={
            "display_name": "test user 2",
        }))

        # need to create a license before creating a review
        self.license = db_license.create(
            id=u'Test',
            full_name=u"Test License",
        )
        self.review = db_review.create(
            user_id=self.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"],
        )
Ejemplo n.º 7
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 = db_license.create(
         id='Test',
         full_name='Test License',
     )
     self.review = db_review.create(
         entity_id="e7aad618-fa86-3983-9e77-405e21796eca",
         entity_type="release_group",
         text="Testing!",
         user_id=self.author.id,
         is_draft=False,
         license_id=license["id"],
     )
     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 = db_spam_report.create(self.revision_id, self.user1.id,
                                         "Testing Reason Report")
Ejemplo n.º 8
0
 def setUp(self):
     super(SpamReportTestCase, self).setUp()
     author = User(db_users.get_or_create(0, '0', new_user_data={
         "display_name": "Author",
     }))
     self.user1 = User(db_users.get_or_create(1, '1', new_user_data={
         "display_name": "Tester #1",
     }))
     self.user2 = User(db_users.get_or_create(2, '2', new_user_data={
         "display_name": "Tester #2",
     }))
     license = db_license.create(
         id='Test',
         full_name='Test License',
     )
     self.review = db_review.create(
         entity_id="e7aad618-fa86-3983-9e77-405e21796eca",
         entity_type="release_group",
         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"]
Ejemplo n.º 9
0
 def setUp(self):
     super(CommentViewsTestCase, self).setUp()
     self.reviewer = User(
         db_users.get_or_create(1,
                                "aef06569-098f-4218-a577-b413944d9493",
                                new_user_data={
                                    "display_name": u"Reviewer",
                                }))
     self.commenter = User(
         db_users.get_or_create(2,
                                "9371e5c7-5995-4471-a5a9-33481f897f9c",
                                new_user_data={
                                    "display_name": u"Commenter",
                                }))
     self.license = db_license.create(
         id="CC BY-SA 3.0",
         full_name="Test License.",
     )
     self.review = db_review.create(
         user_id=self.reviewer.id,
         entity_id="e7aad618-fa86-3983-9e77-405e21796eca",
         entity_type="release_group",
         text="Test Review.",
         rating=5,
         is_draft=False,
         license_id=self.license["id"],
     )
     current_app.jinja_env.filters["entity_details"] = mock_get_entity_by_id
    def setUp(self):
        super(ModerationLogTestCase, self).setUp()

        self.admin = User(
            db_users.get_or_create(1,
                                   "Admin",
                                   new_user_data={
                                       "display_name": "Admin",
                                   }))
        self.user = User(
            db_users.get_or_create(2,
                                   "Tester",
                                   new_user_data={
                                       "display_name": "Tester",
                                   }))
        self.reason = "Testing!"
        self.license = db_license.create(
            id=u'TEST',
            full_name=u"Test License",
        )

        self.review = db_review.create(
            user_id=self.user.id,
            entity_id="e7aad618-fa86-3983-9e77-405e21796eca",
            entity_type="release_group",
            text="It is beautiful!",
            is_draft=False,
            license_id=self.license["id"],
            language='en',
        )
Ejemplo n.º 11
0
    def setUp(self):
        super(ReviewTestCase, self).setUp()

        # Review needs user
        self.user = User(
            db_users.get_or_create(1,
                                   "Tester",
                                   new_user_data={
                                       "display_name": "test user",
                                   }))
        self.user_2 = User(
            db_users.get_or_create(2,
                                   "Tester 2",
                                   new_user_data={
                                       "display_name": "test user 2",
                                   }))

        # And license
        self.license = db_license.create(
            id=u'Test',
            full_name=u"Test License",
        )

        # disable caching
        cache.get = MagicMock(return_value=None)
Ejemplo n.º 12
0
 def setUp(self):
     super(VoteTestCase, self).setUp()
     author = User(
         db_users.get_or_create(0,
                                '0',
                                new_user_data={
                                    "display_name": "Author",
                                }))
     self.user_1 = User(
         db_users.get_or_create(1,
                                '1',
                                new_user_data={
                                    "display_name": "Tester #1",
                                }))
     self.user_2 = User(
         db_users.get_or_create(2,
                                '2',
                                new_user_data={
                                    "display_name": "Tester #2",
                                }))
     license = db_license.create(
         id='Test',
         full_name='Test License',
     )
     self.review = db_review.create(
         entity_id="e7aad618-fa86-3983-9e77-405e21796eca",
         entity_type="release_group",
         text="Testing!",
         rating=5,
         user_id=author.id,
         is_draft=False,
         license_id=license["id"],
     )
Ejemplo n.º 13
0
 def setUp(self):
     super(ReviewViewsTestCase, self).setUp()
     self.user = User(
         db_users.get_or_create("Tester",
                                new_user_data={
                                    "display_name": "test user",
                                }))
     self.another_user = User(
         db_users.get_or_create("Hacker!",
                                new_user_data={
                                    "display_name": "test hacker",
                                }))
     self.license = db_license.create(
         id="CC BY-SA 3.0",
         full_name="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.",
         rating=5,
         is_draft=False,
         license_id=self.license["id"],
     )
Ejemplo n.º 14
0
 def setUp(self):
     super(RevisionTestCase, self).setUp()
     self.author = User(
         db_users.get_or_create(1,
                                'Author',
                                new_user_data={
                                    "display_name": '0',
                                }))
     self.user_1 = User(
         db_users.get_or_create(2,
                                'Tester #1',
                                new_user_data={
                                    "display_name": '1',
                                }))
     self.user_2 = User(
         db_users.get_or_create(3,
                                'Tester #2',
                                new_user_data={
                                    "display_name": '2',
                                }))
     self.license = db_license.create(
         id=u'TEST',
         full_name=u"Test License",
     )
     self.review = db_review.create(
         user_id=self.author.id,
         entity_id="e7aad618-fa86-3983-9e77-405e21796eca",
         entity_type="release_group",
         text=u"Testing!",
         rating=5,
         is_draft=False,
         license_id=self.license["id"],
     )
Ejemplo n.º 15
0
 def setUp(self):
     super(RecordingViewsTestCase, self).setUp()
     mb_recording.get_recording_by_id = MagicMock()
     mb_recording.get_recording_by_id.return_value = {
         'id':
         '442ddce2-ffa1-4865-81d2-b42c40fec7c5',
         'name':
         'Dream Come True',
         'length':
         229.0,
         'artists': [{
             'id': '164f0d73-1234-4e2c-8743-d77bf2191051',
             'name': 'Kanye West',
             'join_phrase': ' feat. '
         }, {
             'id': '75a72702-a5ef-4513-bca5-c5b944903546',
             'name': 'John Legend'
         }],
         'artist-credit-phrase':
         'Kanye West feat. John Legend'
     }
     self.user = User(
         db_users.get_or_create(1,
                                "Tester",
                                new_user_data={"display_name":
                                               "test user"}))
     self.license = db_license.create(id='Test', full_name='Test License')
Ejemplo n.º 16
0
 def setUp(self):
     super(UserTestCase, self).setUp()
     self.user1 = User(db_users.get_or_create(1, 'tester_1', new_user_data={
         "display_name": "test",
     }))
     self.user2 = User(db_users.get_or_create(2, "тестер", new_user_data={
         "display_name": "test1",
     }))
     self.author = User(db_users.get_or_create(3, "author1", new_user_data={
         "display_name": "Author1",
     }))
     license = db_license.create(
         id='Test',
         full_name='Test License',
     )
     self.review = db_review.create(
         entity_id="e7aad618-fa86-3983-9e77-405e21796eca",
         entity_type="release_group",
         text="Testing!",
         user_id=self.author.id,
         is_draft=False,
         license_id=license["id"],
     )
     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 = db_spam_report.create(self.revision_id, self.user1.id, "Testing Reason Report")
Ejemplo n.º 17
0
 def setUp(self):
     super(SpamReportTestCase, self).setUp()
     author = User(db_users.get_or_create(0, '0', new_user_data={
         "display_name": "Author",
     }))
     self.user1 = User(db_users.get_or_create(1, '1', new_user_data={
         "display_name": "Tester #1",
     }))
     self.user2 = User(db_users.get_or_create(2, '2', new_user_data={
         "display_name": "Tester #2",
     }))
     license = db_license.create(
         id='Test',
         full_name='Test License',
     )
     self.review = db_review.create(
         entity_id="e7aad618-fa86-3983-9e77-405e21796eca",
         entity_type="release_group",
         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"]
Ejemplo n.º 18
0
 def setUp(self):
     super().setUp()
     self.tempdir = tempfile.mkdtemp()
     self.runner = CliRunner()
     self.license = db_license.create(
         id=u'test',
         full_name=u"Test License",
     )
Ejemplo n.º 19
0
 def test_license_create(self):
     license = db_license.create(
         id="Test",
         full_name="Test License",
         info_url="www.example.com",
     )
     self.assertEqual(license["id"], "Test")
     self.assertEqual(license["full_name"], "Test License")
     self.assertEqual(license["info_url"], "www.example.com")
Ejemplo n.º 20
0
 def setUp(self):
     super(ReleaseGroupViewsTestCase, self).setUp()
     self.user = User(db_users.get_or_create(1, "Tester", new_user_data={
         "display_name": "test user",
     }))
     self.license = db_license.create(
         id='Test',
         full_name='Test License',
     )
Ejemplo n.º 21
0
 def setUp(self):
     super(ProfileViewsTestCase, self).setUp()
     self.license = db_license.create(
         id="CC BY-SA 3.0",
         full_name="Created so we can fill the form correctly.",
     )
     self.user = User(db_users.get_or_create(1, "aef06569-098f-4218-a577-b413944d9493", new_user_data={
         "display_name": "Tester",
     }))
Ejemplo n.º 22
0
 def setUp(self):
     super(StatisticsViewsTestCase, self).setUp()
     self.user = User(
         db_users.get_or_create(1,
                                "aef06569-098f-4218-a577-b413944d9493",
                                new_user_data={
                                    "display_name": u"Tester",
                                }))
     self.license = db_license.create(
         id="CC BY-SA 3.0",
         full_name="Test License.",
     )
Ejemplo n.º 23
0
 def setUp(self):
     super(ProfileViewsTestCase, self).setUp()
     self.license = db_license.create(
         id="CC BY-SA 3.0",
         full_name="Created so we can fill the form correctly.",
     )
     self.user = User(
         db_users.get_or_create(1,
                                "aef06569-098f-4218-a577-b413944d9493",
                                new_user_data={
                                    "display_name": "Tester",
                                }))
Ejemplo n.º 24
0
    def setUp(self):
        super(AvgRatingTestCase, self).setUp()

        self.user = User(db_users.get_or_create(1, "Tester", new_user_data={
            "display_name": "test user",
        }))
        self.user_2 = User(db_users.get_or_create(2, "Tester 2", new_user_data={
            "display_name": "test user 2",
        }))
        self.license = db_license.create(
            id=u'Test',
            full_name=u"Test License",
        )
Ejemplo n.º 25
0
    def setUp(self):
        super(StatisticsTestCase, self).setUp()

        self.user_1 = User(db_users.get_or_create(1, "Tester 1", new_user_data={
            "display_name": "test user 1",
        }))
        self.user_2 = User(db_users.get_or_create(2, "Tester 2", new_user_data={
            "display_name": "test user 2",
        }))

        self.license = db_license.create(
            id=u'Test',
            full_name=u"Test License",
        )
Ejemplo n.º 26
0
    def setUp(self):
        super(StatisticsViewsTestCase, self).setUp()
        self.user = User(db_users.get_or_create(1, "aef06569-098f-4218-a577-b413944d9493", new_user_data={
            "display_name": u"Tester",
        }))
        self.license = db_license.create(
            id="CC BY-SA 3.0",
            full_name="Test License.",
        )

        # totally disable cache get or set
        cache.gen_key = MagicMock(return_value=None)
        cache.get = MagicMock(return_value=None)
        cache.set = MagicMock(return_value=None)
Ejemplo n.º 27
0
 def setUp(self):
     super(ReviewViewsTestCase, self).setUp()
     self.user = User(db_users.get_or_create("aef06569-098f-4218-a577-b413944d9493", new_user_data={
         "display_name": u"Tester",
     }))
     self.hacker = User(db_users.get_or_create("9371e5c7-5995-4471-a5a9-33481f897f9c", new_user_data={
         "display_name": u"Hacker!",
     }))
     self.license = db_license.create(
         id="CC BY-SA 3.0",
         full_name="Created so we can fill the form correctly.",
     )
     self.review_text = "Testing! This text should be on the page."
     mb_release.browse_releases = MagicMock()
     current_app.jinja_env.filters['entity_details'] = mock_get_entity_by_id
Ejemplo n.º 28
0
 def setUp(self):
     super(RateViewsTestCase, self).setUp()
     self.test_entity = {
         'id': 'e7aad618-fa86-3983-9e77-405e21796eca',
         'title': 'Test Release Group',
         'first-release-year': 1970,
     }
     mb_release_group.get_release_group_by_id = mock.MagicMock()
     mb_release_group.get_release_group_by_id.return_value = self.test_entity
     self.reviewer = User(db_users.get_or_create(1, "aef06569-098f-4218-a577-b413944d9493", new_user_data={
         "display_name": u"Reviewer",
     }))
     self.license = db_license.create(
         id="CC BY-SA 3.0",
         full_name="Test License.",
     )
Ejemplo n.º 29
0
    def setUp(self):
        super(AvgRatingTestCase, self).setUp()

        self.user = User(
            db_users.get_or_create("Tester",
                                   new_user_data={
                                       "display_name": "test user",
                                   }))
        self.user_2 = User(
            db_users.get_or_create("Tester 2",
                                   new_user_data={
                                       "display_name": "test user 2",
                                   }))
        self.license = db_license.create(
            id=u'Test',
            full_name=u"Test License",
        )
Ejemplo n.º 30
0
 def setUp(self):
     super(ReleaseGroupViewsTestCase, self).setUp()
     mb_release_group.get_release_group_by_id = MagicMock()
     mb_release_group.get_release_group_by_id.return_value = {
         'id': '8ef859e3-feb2-4dd1-93da-22b91280d768',
         'title': 'Collision Course',
         'first-release-year': 2004,
     }
     self.user = User(
         db_users.get_or_create("Tester",
                                new_user_data={
                                    "display_name": "test user",
                                }))
     self.license = db_license.create(
         id='Test',
         full_name='Test License',
     )
Ejemplo n.º 31
0
 def setUp(self):
     super(CommentViewsTestCase, self).setUp()
     self.user = User(db_users.get_or_create(1, "aef06569-098f-4218-a577-b413944d9493", new_user_data={
         "display_name": u"Tester",
     }))
     self.license = db_license.create(
         id="CC BY-SA 3.0",
         full_name="Created so we can fill the form correctly.",
     )
     self.review = db_review.create(
         user_id=self.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"],
     )
Ejemplo n.º 32
0
    def setUp(self):
        super(ReviewTestCase, self).setUp()

        # Review needs user
        self.user = User(db_users.get_or_create(1, "Tester", new_user_data={
            "display_name": "test user",
        }))
        self.user_2 = User(db_users.get_or_create(2, "Tester 2", new_user_data={
            "display_name": "test user 2",
        }))

        # And license
        self.license = db_license.create(
            id=u'Test',
            full_name=u"Test License",
        )

        # disable caching
        cache.get = MagicMock(return_value=None)
Ejemplo n.º 33
0
 def setUp(self):
     super(RateViewsTestCase, self).setUp()
     self.test_entity = {
         'id': 'e7aad618-fa86-3983-9e77-405e21796eca',
         'title': 'Test Release Group',
         'first-release-year': 1970,
     }
     mb_release_group.get_release_group_by_id = mock.MagicMock()
     mb_release_group.get_release_group_by_id.return_value = self.test_entity
     self.reviewer = User(
         db_users.get_or_create(1,
                                "aef06569-098f-4218-a577-b413944d9493",
                                new_user_data={
                                    "display_name": u"Reviewer",
                                }))
     self.license = db_license.create(
         id="CC BY-SA 3.0",
         full_name="Test License.",
     )
Ejemplo n.º 34
0
    def setUp(self):
        super(ReviewTestCase, self).setUp()

        # Review needs user
        self.user = User(
            db_users.get_or_create("Tester",
                                   new_user_data={
                                       "display_name": "test user",
                                   }))
        self.user_2 = User(
            db_users.get_or_create("Tester 2",
                                   new_user_data={
                                       "display_name": "test user 2",
                                   }))

        # And license
        self.license = db_license.create(
            id=u'Test',
            full_name=u"Test License",
        )
Ejemplo n.º 35
0
 def setUp(self):
     super(ReviewViewsTestCase, self).setUp()
     self.user = User(db_users.get_or_create(1, "Tester", new_user_data={
         "display_name": "test user",
     }))
     self.another_user = User(db_users.get_or_create(2, "Hacker!", new_user_data={
         "display_name": "test hacker",
     }))
     self.license = db_license.create(
         id="CC BY-SA 3.0",
         full_name="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.",
         rating=5,
         is_draft=False,
         license_id=self.license["id"],
     )
Ejemplo n.º 36
0
 def setUp(self):
     super(CommentViewsTestCase, self).setUp()
     self.reviewer = User(db_users.get_or_create(1, "aef06569-098f-4218-a577-b413944d9493", new_user_data={
         "display_name": u"Reviewer",
     }))
     self.commenter = User(db_users.get_or_create(2, "9371e5c7-5995-4471-a5a9-33481f897f9c", new_user_data={
         "display_name": u"Commenter",
     }))
     self.license = db_license.create(
         id="CC BY-SA 3.0",
         full_name="Test License.",
     )
     self.review = db_review.create(
         user_id=self.reviewer.id,
         entity_id="e7aad618-fa86-3983-9e77-405e21796eca",
         entity_type="release_group",
         text="Test Review.",
         rating=5,
         is_draft=False,
         license_id=self.license["id"],
     )
     current_app.jinja_env.filters["entity_details"] = mock_get_entity_by_id
Ejemplo n.º 37
0
 def setUp(self):
     super(RevisionTestCase, self).setUp()
     self.author = User(db_users.get_or_create(1, 'Author', new_user_data={
         "display_name": '0',
     }))
     self.user_1 = User(db_users.get_or_create(2, 'Tester #1', new_user_data={
         "display_name": '1',
     }))
     self.user_2 = User(db_users.get_or_create(3, 'Tester #2', new_user_data={
         "display_name": '2',
     }))
     self.license = db_license.create(
         id=u'TEST',
         full_name=u"Test License",
     )
     self.review = db_review.create(
         user_id=self.author.id,
         entity_id="e7aad618-fa86-3983-9e77-405e21796eca",
         entity_type="release_group",
         text=u"Testing!",
         rating=5,
         is_draft=False,
         license_id=self.license["id"],
     )
    def setUp(self):
        super(ModerationLogTestCase, self).setUp()

        self.admin = User(db_users.get_or_create(1, "Admin", new_user_data={
            "display_name": "Admin",
        }))
        self.user = User(db_users.get_or_create(2, "Tester", new_user_data={
            "display_name": "Tester",
        }))
        self.reason = "Testing!"
        self.license = db_license.create(
            id=u'TEST',
            full_name=u"Test License",
        )

        self.review = db_review.create(
            user_id=self.user.id,
            entity_id="e7aad618-fa86-3983-9e77-405e21796eca",
            entity_type="release_group",
            text="It is beautiful!",
            is_draft=False,
            license_id=self.license["id"],
            language='en',
        )
Ejemplo n.º 39
0
 def setUp(self):
     super(VoteTestCase, self).setUp()
     author = User(db_users.get_or_create(0, '0', new_user_data={
         "display_name": "Author",
     }))
     self.user_1 = User(db_users.get_or_create(1, '1', new_user_data={
         "display_name": "Tester #1",
     }))
     self.user_2 = User(db_users.get_or_create(2, '2', new_user_data={
         "display_name": "Tester #2",
     }))
     license = db_license.create(
         id='Test',
         full_name='Test License',
     )
     self.review = db_review.create(
         entity_id="e7aad618-fa86-3983-9e77-405e21796eca",
         entity_type="release_group",
         text="Testing!",
         rating=5,
         user_id=author.id,
         is_draft=False,
         license_id=license["id"],
     )
Ejemplo n.º 40
0
    def test_update(self):
        review = db_review.create(
            user_id=self.user.id,
            entity_id="e7aad618-fa86-3983-9e77-405e21796eca",
            entity_type="release_group",
            text="Testing",
            rating=5,
            is_draft=True,
            license_id=self.license["id"],
        )
        another_license = db_license.create(
            id="License-2",
            full_name="Another License",
        )
        # Update review to only rating
        db_review.update(
            review_id=review["id"],
            drafted=review["is_draft"],
            rating=4,
            is_draft=False,
            license_id=another_license["id"],
            language="es",
        )
        # Checking if contents are updated
        retrieved_review = db_review.list_reviews()[0][0]
        self.assertEqual(retrieved_review["text"], None)
        self.assertEqual(retrieved_review["rating"], 4)
        self.assertFalse(retrieved_review["is_draft"])
        self.assertEqual(retrieved_review["license_id"], another_license["id"])
        self.assertEqual(retrieved_review["language"], "es")
        # Update review to only text
        db_review.update(
            review_id=review["id"],
            drafted=review["is_draft"],
            text="Testing update",
            is_draft=False,
            license_id=another_license["id"],
            language="es",
        )
        # Checking if contents are updated
        retrieved_review = db_review.list_reviews()[0][0]
        self.assertEqual(retrieved_review["text"], "Testing update")
        self.assertEqual(retrieved_review["rating"], None)

        # Updating should create a new revision.
        revisions = db_revision.get(retrieved_review["id"], limit=None)
        self.assertEqual(len(revisions), 3)
        self.assertEqual(revisions[0]["timestamp"], retrieved_review["last_revision"]["timestamp"])
        self.assertEqual(revisions[0]["text"], retrieved_review["text"])
        self.assertEqual(revisions[0]["rating"], retrieved_review["rating"])

        # Checking things that shouldn't be allowed
        with self.assertRaises(db_exceptions.BadDataException):
            db_review.update(
                review_id=retrieved_review["id"],
                drafted=retrieved_review["is_draft"],
                text="Sucks!",
                license_id=self.license["id"],
            )
        review = db_review.get_by_id(review["id"])
        with self.assertRaises(db_exceptions.BadDataException):
            db_review.update(
                review_id=review["id"],
                drafted=review["is_draft"],
                text="Sucks!",
                is_draft=True,
            )
Ejemplo n.º 41
0
    def test_update(self):
        review = db_review.create(
            user_id=self.user.id,
            entity_id="e7aad618-fa86-3983-9e77-405e21796eca",
            entity_type="release_group",
            text="Testing",
            rating=5,
            is_draft=True,
            license_id=self.license["id"],
        )
        another_license = db_license.create(
            id="License-2",
            full_name="Another License",
        )
        # Update review to only rating
        db_review.update(
            review_id=review["id"],
            drafted=review["is_draft"],
            rating=4,
            is_draft=False,
            license_id=another_license["id"],
            language="es",
        )
        # Checking if contents are updated
        retrieved_review = db_review.list_reviews()[0][0]
        self.assertEqual(retrieved_review["text"], None)
        self.assertEqual(retrieved_review["rating"], 4)
        self.assertFalse(retrieved_review["is_draft"])
        self.assertEqual(retrieved_review["license_id"], another_license["id"])
        self.assertEqual(retrieved_review["language"], "es")
        # Update review to only text
        db_review.update(
            review_id=review["id"],
            drafted=review["is_draft"],
            text="Testing update",
            is_draft=False,
            license_id=another_license["id"],
            language="es",
        )
        # Checking if contents are updated
        retrieved_review = db_review.list_reviews()[0][0]
        self.assertEqual(retrieved_review["text"], "Testing update")
        self.assertEqual(retrieved_review["rating"], None)

        # Updating should create a new revision.
        revisions = db_revision.get(retrieved_review["id"], limit=None)
        self.assertEqual(len(revisions), 3)
        self.assertEqual(revisions[0]["timestamp"],
                         retrieved_review["last_revision"]["timestamp"])
        self.assertEqual(revisions[0]["text"], retrieved_review["text"])
        self.assertEqual(revisions[0]["rating"], retrieved_review["rating"])

        # Checking things that shouldn't be allowed
        with self.assertRaises(db_exceptions.BadDataException):
            db_review.update(
                review_id=retrieved_review["id"],
                drafted=retrieved_review["is_draft"],
                text="Sucks!",
                license_id=self.license["id"],
            )
        review = db_review.get_by_id(review["id"])
        with self.assertRaises(db_exceptions.BadDataException):
            db_review.update(
                review_id=review["id"],
                drafted=review["is_draft"],
                text="Sucks!",
                is_draft=True,
            )