当前位置: 首页>>代码示例>>Python>>正文


Python models.ChangeDescription类代码示例

本文整理汇总了Python中reviewboard.changedescs.models.ChangeDescription的典型用法代码示例。如果您正苦于以下问题:Python ChangeDescription类的具体用法?Python ChangeDescription怎么用?Python ChangeDescription使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ChangeDescription类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_with_site

    def test_get_with_site(self):
        """Testing the GET review-requests/<id>/changes/ API
        with access to a local site
        """
        review_request = self.create_review_request(publish=True,
                                                    with_local_site=True)

        self._login_user(local_site=True)

        now = timezone.now()
        change1 = ChangeDescription(public=True,
                                    timestamp=now)
        change1.record_field_change('summary', 'foo', 'bar')
        change1.save()
        review_request.changedescs.add(change1)

        change2 = ChangeDescription(public=True,
                                    timestamp=now + timedelta(seconds=1))
        change2.record_field_change('description', 'foo', 'bar')
        change2.save()
        review_request.changedescs.add(change2)

        rsp = self.apiGet(
            get_change_list_url(review_request, self.local_site_name),
            expected_mimetype=change_list_mimetype)
        self.assertEqual(rsp['stat'], 'ok')
        self.assertEqual(len(rsp['changes']), 2)

        self.assertEqual(rsp['changes'][0]['id'], change2.pk)
        self.assertEqual(rsp['changes'][1]['id'], change1.pk)
开发者ID:CrystalLokKoo,项目名称:reviewboard,代码行数:30,代码来源:test_change.py

示例2: test_get_change_not_modified

    def test_get_change_not_modified(self):
        """Testing the GET review-requests/<id>/changes/<id>/ API with Not Modified response"""
        review_request = self.create_review_request()

        changedesc = ChangeDescription(public=True)
        changedesc.save()
        review_request.changedescs.add(changedesc)

        self._testHttpCaching(get_change_item_url(changedesc), check_last_modified=True)
开发者ID:harrifeng,项目名称:reviewboard,代码行数:9,代码来源:test_change.py

示例3: test_is_new_for_user_with_owner

    def test_is_new_for_user_with_owner(self):
        """Testing ChangeDescription.is_new_for_user with owner"""
        user = User.objects.create_user(username='test-user',
                                        email='[email protected]')

        changedesc = ChangeDescription(
            user=user,
            timestamp=datetime(2017, 9, 7, 15, 27, 0))
        self.assertFalse(changedesc.is_new_for_user(
            user=user,
            last_visited=datetime(2017, 9, 7, 16, 0, 0)))
开发者ID:chipx86,项目名称:reviewboard,代码行数:11,代码来源:tests.py

示例4: close

    def close(self, type, user=None, description=None, rich_text=False):
        """Closes the review request.

        The type must be one of SUBMITTED or DISCARDED.
        """
        if (user and not self.is_mutable_by(user) and
            not user.has_perm("reviews.can_change_status", self.local_site)):
            raise PermissionError

        if type not in [self.SUBMITTED, self.DISCARDED]:
            raise AttributeError("%s is not a valid close type" % type)

        if self.status != type:
            # TODO: Use the user's default for rich_text.
            changedesc = ChangeDescription(public=True,
                                           text=description or "",
                                           rich_text=rich_text or False)
            changedesc.record_field_change('status', self.status, type)
            changedesc.save()

            self.changedescs.add(changedesc)

            if type == self.SUBMITTED:
                self.public = True
            else:
                self.commit_id = None

            self.status = type
            self.save(update_counts=True)

            review_request_closed.send(sender=self.__class__, user=user,
                                       review_request=self,
                                       type=type)
        else:
            # Update submission description.
            changedesc = self.changedescs.filter(public=True).latest()
            changedesc.timestamp = timezone.now()
            changedesc.text = description or ""
            changedesc.rich_text = rich_text
            changedesc.save()

            # Needed to renew last-update.
            self.save()

        try:
            draft = self.draft.get()
        except ObjectDoesNotExist:
            pass
        else:
            draft.delete()
开发者ID:iapilgrim,项目名称:reviewboard,代码行数:50,代码来源:review_request.py

示例5: reopen

    def reopen(self, user=None):
        """Reopens the review request for review."""
        from reviewboard.reviews.models.review_request_draft import \
            ReviewRequestDraft

        if (user and not self.is_mutable_by(user) and
            not user.has_perm("reviews.can_change_status", self.local_site)):
            raise PermissionError

        if self.status != self.PENDING_REVIEW:
            changedesc = ChangeDescription()
            changedesc.record_field_change('status', self.status,
                                           self.PENDING_REVIEW)

            if self.status == self.DISCARDED:
                # A draft is needed if reopening a discarded review request.
                self.public = False
                changedesc.save()
                draft = ReviewRequestDraft.create(self)
                draft.changedesc = changedesc
                draft.save()
            else:
                changedesc.public = True
                changedesc.save()
                self.changedescs.add(changedesc)

            self.status = self.PENDING_REVIEW
            self.save(update_counts=True)

        review_request_reopened.send(sender=self.__class__, user=user,
                                     review_request=self)
开发者ID:karthikkn,项目名称:reviewboard,代码行数:31,代码来源:review_request.py

示例6: testRecordString

    def testRecordString(self):
        """Testing record_field_change with a string value"""
        old_value = "abc"
        new_value = "def"

        changedesc = ChangeDescription()
        changedesc.record_field_change("test", old_value, new_value)

        self.assert_("test" in changedesc.fields_changed)
        self.assert_("old" in changedesc.fields_changed["test"])
        self.assert_("new" in changedesc.fields_changed["test"])
        self.assert_("added" not in changedesc.fields_changed["test"])
        self.assert_("removed" not in changedesc.fields_changed["test"])
        self.assertEqual(changedesc.fields_changed["test"]["old"], (old_value,))
        self.assertEqual(changedesc.fields_changed["test"]["new"], (new_value,))
开发者ID:B-Rich,项目名称:reviewboard,代码行数:15,代码来源:tests.py

示例7: close

    def close(self, type, user=None, description=None, rich_text=False):
        """Closes the review request.

        The type must be one of SUBMITTED or DISCARDED.
        """
        if (user and not self.is_mutable_by(user) and
            not user.has_perm("reviews.can_change_status", self.local_site)):
            raise PermissionError

        if type not in [self.SUBMITTED, self.DISCARDED]:
            raise AttributeError("%s is not a valid close type" % type)

        draft = get_object_or_none(self.draft)

        if self.status != type:
            if (draft is not None and
                not self.public and type == self.DISCARDED):
                # Copy over the draft information if this is a private discard.
                draft.copy_fields_to_request(self)

            # TODO: Use the user's default for rich_text.
            changedesc = ChangeDescription(public=True,
                                           text=description or "",
                                           rich_text=rich_text or False)

            status_field = get_review_request_field('status')(self)
            status_field.record_change_entry(changedesc, self.status, type)
            changedesc.save()

            self.changedescs.add(changedesc)

            if type == self.SUBMITTED:
                if not self.public:
                    raise PublishError("The draft must be public first.")
            else:
                self.commit_id = None

            self.status = type
            self.save(update_counts=True)

            review_request_closed.send(sender=self.__class__, user=user,
                                       review_request=self,
                                       type=type)
        else:
            # Update submission description.
            changedesc = self.changedescs.filter(public=True).latest()
            changedesc.timestamp = timezone.now()
            changedesc.text = description or ""
            changedesc.rich_text = rich_text
            changedesc.save()

            # Needed to renew last-update.
            self.save()

        # Delete the associated draft review request.
        if draft is not None:
            draft.delete()
开发者ID:guitao,项目名称:reviewboard,代码行数:57,代码来源:review_request.py

示例8: test_record_list

    def test_record_list(self):
        """Testing ChangeDescription.record_field_change with a list value"""
        old_value = [1, 2, 3]
        new_value = [2, 3, 4]

        changedesc = ChangeDescription()
        changedesc.record_field_change("test", old_value, new_value)

        self.assertIn("test", changedesc.fields_changed)
        self.assertIn("old", changedesc.fields_changed["test"])
        self.assertIn("new", changedesc.fields_changed["test"])
        self.assertIn("added", changedesc.fields_changed["test"])
        self.assertIn("removed", changedesc.fields_changed["test"])
        self.assertEqual(changedesc.fields_changed["test"]["old"], [(i,) for i in old_value])
        self.assertEqual(changedesc.fields_changed["test"]["new"], [(i,) for i in new_value])
        self.assertEqual(changedesc.fields_changed["test"]["added"], [(4,)])
        self.assertEqual(changedesc.fields_changed["test"]["removed"], [(1,)])
开发者ID:klpyang,项目名称:reviewboard,代码行数:17,代码来源:tests.py

示例9: test_get_with_site_no_access

    def test_get_with_site_no_access(self):
        """Testing the GET review-requests/<id>/changes/<id>/ API
        without access to a local site
        """
        review_request = self.create_review_request(publish=True,
                                                    with_local_site=True)

        now = timezone.now()
        change = ChangeDescription(public=True, timestamp=now)
        change.record_field_change('summary', 'foo', 'bar')
        change.save()
        review_request.changedescs.add(change)

        rsp = self.apiGet(
            get_change_item_url(change, self.local_site_name),
            expected_status=403)
        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
开发者ID:CrystalLokKoo,项目名称:reviewboard,代码行数:18,代码来源:test_change.py

示例10: test_is_new_for_user_with_non_owner

    def test_is_new_for_user_with_non_owner(self):
        """Testing ChangeDescription.is_new_for_user with non-owner"""
        user1 = User.objects.create_user(username='test-user-1',
                                         email='[email protected]')
        user2 = User.objects.create_user(username='test-user-2',
                                         email='[email protected]')

        changedesc = ChangeDescription(
            user=user1,
            timestamp=datetime(2017, 9, 7, 15, 27, 0))
        self.assertTrue(changedesc.is_new_for_user(
            user=user2,
            last_visited=datetime(2017, 9, 7, 10, 0, 0)))
        self.assertFalse(changedesc.is_new_for_user(
            user=user2,
            last_visited=datetime(2017, 9, 7, 16, 0, 0)))
        self.assertFalse(changedesc.is_new_for_user(
            user=user2,
            last_visited=datetime(2017, 9, 7, 15, 27, 0)))
开发者ID:chipx86,项目名称:reviewboard,代码行数:19,代码来源:tests.py

示例11: test_record_object_list_name_field

    def test_record_object_list_name_field(self):
        """Testing ChangeDescription.record_field_change with an object list
        (using name_field)
        """

        class DummyObject(object):
            def __init__(self, id):
                self.id = id
                self.text = "Object %s" % id

            def get_absolute_url(self):
                return "http://localhost/%s" % self.id

        objs = [DummyObject(i) for i in range(4)]
        old_value = [objs[0], objs[1], objs[2]]
        new_value = [objs[1], objs[2], objs[3]]

        changedesc = ChangeDescription()
        changedesc.record_field_change("test", old_value, new_value, "text")

        self.assertIn("test", changedesc.fields_changed)
        self.assertIn("old", changedesc.fields_changed["test"])
        self.assertIn("new", changedesc.fields_changed["test"])
        self.assertIn("added", changedesc.fields_changed["test"])
        self.assertIn("removed", changedesc.fields_changed["test"])
        self.assertEqual(
            set(changedesc.fields_changed["test"]["old"]),
            set([(obj.text, obj.get_absolute_url(), obj.id) for obj in old_value]),
        )
        self.assertEqual(
            set(changedesc.fields_changed["test"]["new"]),
            set([(obj.text, obj.get_absolute_url(), obj.id) for obj in new_value]),
        )
        self.assertEqual(
            set(changedesc.fields_changed["test"]["added"]),
            set([(new_value[2].text, new_value[2].get_absolute_url(), new_value[2].id)]),
        )
        self.assertEqual(
            set(changedesc.fields_changed["test"]["removed"]),
            set([(old_value[0].text, old_value[0].get_absolute_url(), old_value[0].id)]),
        )
开发者ID:klpyang,项目名称:reviewboard,代码行数:41,代码来源:tests.py

示例12: test_get_changes

    def test_get_changes(self):
        """Testing the GET review-requests/<id>/changes/ API"""
        review_request = self.create_review_request(publish=True)

        now = timezone.now()
        change1 = ChangeDescription(public=True, timestamp=now)
        change1.record_field_change("summary", "foo", "bar")
        change1.save()
        review_request.changedescs.add(change1)

        change2 = ChangeDescription(public=True, timestamp=now + timedelta(seconds=1))
        change2.record_field_change("description", "foo", "bar")
        change2.save()
        review_request.changedescs.add(change2)

        rsp = self.apiGet(get_change_list_url(review_request), expected_mimetype=change_list_mimetype)
        self.assertEqual(rsp["stat"], "ok")
        self.assertEqual(len(rsp["changes"]), 2)

        self.assertEqual(rsp["changes"][0]["id"], change2.pk)
        self.assertEqual(rsp["changes"][1]["id"], change1.pk)
开发者ID:harrifeng,项目名称:reviewboard,代码行数:21,代码来源:test_change.py

示例13: create

    def create(review_request):
        """
        Creates a draft based on a review request.

        This will copy over all the details of the review request that
        we care about. If a draft already exists for the review request,
        the draft will be returned.
        """
        draft, draft_is_new = \
            ReviewRequestDraft.objects.get_or_create(
                review_request=review_request,
                defaults={
                    'summary': review_request.summary,
                    'description': review_request.description,
                    'testing_done': review_request.testing_done,
                    'bugs_closed': review_request.bugs_closed,
                    'branch': review_request.branch,
                })

        if draft.changedesc is None and review_request.public:
            changedesc = ChangeDescription()
            changedesc.save()
            draft.changedesc = changedesc

        if draft_is_new:
            map(draft.target_groups.add, review_request.target_groups.all())
            map(draft.target_people.add, review_request.target_people.all())
            for screenshot in review_request.screenshots.all():
                screenshot.draft_caption = screenshot.caption
                screenshot.save()
                draft.screenshots.add(screenshot)

            for screenshot in review_request.inactive_screenshots.all():
                screenshot.draft_caption = screenshot.caption
                screenshot.save()
                draft.inactive_screenshots.add(screenshot)

            draft.save();

        return draft
开发者ID:cortextual,项目名称:reviewboard,代码行数:40,代码来源:models.py

示例14: save_autolandrequest_id

    def save_autolandrequest_id(self, fieldname, rr, autoland_request_id):
        # TODO: this method is only required while we are using change
        #       descriptions to render autoland results. Once Bug 1176330 is
        #       fixed this code can be removed.

        # There's possibly a race condition here with multiple web-heads. If
        # two requests come in at the same time to this endpoint, the request
        # that saves their value first here will get overwritten by the second
        # but the first request will have their changedescription come below
        # the second. In that case you'd have the "most recent" try build stats
        # appearing at the top be for a changedescription that has a different
        # try build below it (Super rare, not a big deal really).
        old_request_id = rr.extra_data.get(fieldname, None)
        rr.extra_data[fieldname] = autoland_request_id
        rr.save()

        # In order to display the fact that a build was kicked off in the UI,
        # we construct a change description that our TryField can render.
        changedesc = ChangeDescription(public=True, text="", rich_text=False)
        changedesc.record_field_change(fieldname, old_request_id, autoland_request_id)
        changedesc.save()
        rr.changedescs.add(changedesc)
开发者ID:pkdevboxy,项目名称:version-control-tools,代码行数:22,代码来源:resources.py

示例15: reopen

    def reopen(self, user=None):
        """Reopens the review request for review."""
        from reviewboard.reviews.models.review_request_draft import \
            ReviewRequestDraft

        if (user and not self.is_mutable_by(user) and
            not user.has_perm("reviews.can_change_status", self.local_site)):
            raise PermissionError

        old_status = self.status
        old_public = self.public

        if old_status != self.PENDING_REVIEW:
            # The reopening signal is only fired when actually making a status
            # change since the main consumers (extensions) probably only care
            # about changes.
            review_request_reopening.send(sender=self.__class__,
                                          user=user,
                                          review_request=self)

            changedesc = ChangeDescription(user=user or self.submitter)
            status_field = get_review_request_field('status')(self)
            status_field.record_change_entry(changedesc, old_status,
                                             self.PENDING_REVIEW)

            if old_status == self.DISCARDED:
                # A draft is needed if reopening a discarded review request.
                self.public = False
                changedesc.save()
                draft = ReviewRequestDraft.create(self)
                draft.changedesc = changedesc
                draft.save()
            else:
                changedesc.public = True
                changedesc.save()
                self.changedescs.add(changedesc)

            self.status = self.PENDING_REVIEW
            self.save(update_counts=True)

        review_request_reopened.send(sender=self.__class__, user=user,
                                     review_request=self,
                                     old_status=old_status,
                                     old_public=old_public)
开发者ID:xiaogao6681,项目名称:reviewboard,代码行数:44,代码来源:review_request.py


注:本文中的reviewboard.changedescs.models.ChangeDescription类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。