Exemplo n.º 1
0
    def test_create_a_response_object_with_all_changes(self):
        self.login(self.workspace_member)
        self.todo.title = u'before'
        self.todo.responsible = self.workspace_member.getId()

        changes_tracker = AutoResponseChangesTracker(self.todo, self.request)
        with changes_tracker.track_changes(['title', 'responsible']):
            self.todo.title = u'after'
            self.todo.responsible = self.workspace_admin.getId()

        self.assertItemsEqual([{
            'field_id': 'responsible',
            'before': {
                u'token': u'beatrice.schrodinger',
                u'title': u'Schr\xf6dinger B\xe9atrice'
            },
            'after': {
                u'token': u'fridolin.hugentobler',
                u'title': u'Hugentobler Fridolin'
            },
            'field_title': '',
        }, {
            'field_id': 'title',
            'before': 'before',
            'after': 'after',
            'field_title': '',
        }],
                              IResponseContainer(self.todo).list()[0].changes)
Exemplo n.º 2
0
    def test_do_not_create_a_response_object_if_there_are_no_changes(self):
        self.login(self.workspace_member)

        changes_tracker = AutoResponseChangesTracker(self.todo, self.request)
        with changes_tracker.track_changes(['title']):
            pass

        self.assertEqual([], IResponseContainer(self.todo).list())
Exemplo n.º 3
0
    def test_tracks_changes_of_an_object(self):
        self.login(self.workspace_member)
        self.todo.title = u'before'
        changes_tracker = AutoResponseChangesTracker(self.todo, self.request)
        with changes_tracker.track_changes(['title']):
            self.todo.title = u'James B\xc3\xb6nd'

        self.assertDictEqual({'title': (u'before', u'James B\xc3\xb6nd')},
                             changes_tracker.changes)
Exemplo n.º 4
0
    def test_do_not_track_not_tracking_fields(self):
        self.login(self.workspace_member)
        self.todo.title = u'before'

        changes_tracker = AutoResponseChangesTracker(self.todo, self.request)
        with changes_tracker.track_changes(['responsible']):
            self.todo.title = u'after'

        self.assertDictEqual({}, changes_tracker.changes)
Exemplo n.º 5
0
    def __call__(self, validate_all=False, data=None, create=False):
        if create:
            return super(DeserializeToDoFromJson,
                         self).__call__(validate_all, data, create)
        if data is None:
            data = json_body(self.request)

        changes_tracker = AutoResponseChangesTracker(self.context,
                                                     self.request)
        with changes_tracker.track_changes(data.keys()):
            result = super(DeserializeToDoFromJson,
                           self).__call__(validate_all, data, create)

        return result
Exemplo n.º 6
0
    def test_track_multiple_fields(self):
        self.login(self.workspace_member)
        self.todo.title = u'before'
        self.todo.responsible = self.workspace_member.getId()
        changes_tracker = AutoResponseChangesTracker(self.todo, self.request)
        with changes_tracker.track_changes(['title', 'responsible']):
            self.todo.title = u'after'
            self.todo.responsible = self.workspace_admin.getId()

        self.assertDictEqual(
            {
                'title': (u'before', u'after'),
                'responsible': (
                    {
                        u'token': u'beatrice.schrodinger',
                        u'title': u'Schr\xf6dinger B\xe9atrice'
                    },
                    {
                        u'token': u'fridolin.hugentobler',
                        u'title': u'Hugentobler Fridolin'
                    },
                )
            }, changes_tracker.changes)
Exemplo n.º 7
0
    def test_adapter_for_IResponseSupported_objects(self):
        self.login(self.workspace_member)
        changes_tracker = AutoResponseChangesTracker(self.todo, self.request)

        self.assertIsInstance(changes_tracker, AutoResponseChangesTracker)