コード例 #1
0
    def test_integration_object_events(self):
        """ Trigger every event of a objec at least one times
        and check the journalentries.
        """

        dossier1 = create(Builder('dossier'))
        dossier2 = create(Builder('dossier'))

        document = create(
            Builder('document').within(dossier1).titled(u'Document'))
        document2 = create(
            Builder('document').within(dossier2).titled(u'Document'))

        notify(
            ObjectMovedEvent(
                document,
                dossier1,
                'oldName',
                dossier2,
                'newName',
            ))
        self.check_annotation(
            dossier1,
            action_type='Object moved',
            action_title='Object moved: %s' % document.title_or_id(),
        )

        # Test that a normal ObjectAddedEvent does not result in an object
        # moved journal entry.
        notify(ObjectAddedEvent(document2))
        entry1 = get_journal_entry(dossier2, entry=-1)
        entry2 = get_journal_entry(dossier2, entry=-2)
        self.assertTrue(entry1.get('action').get('type') != 'Object moved')
        self.assertTrue(entry2.get('action').get('type') != 'Object moved')

        notify(
            ObjectWillBeMovedEvent(
                document,
                dossier1,
                'oldName',
                dossier2,
                'newName',
            ))
        self.check_annotation(dossier1,
                              action_type='Object cut',
                              action_title='Object cut: %s' %
                              document.title_or_id())

        # Here we don't have a journal-entry
        length = get_journal_length(dossier1)
        notify(ObjectWillBeAddedEvent(
            document,
            dossier2,
            'newName',
        ))
        self.assertTrue(length == get_journal_length(dossier1))
コード例 #2
0
    def test_integration_object_events(self):
        """ Trigger every event of a objec at least one times
        and check the journalentries.
        """
        portal = self.layer['portal']

        dossier1 = createContentInContainer(
            portal, 'opengever.dossier.businesscasedossier', 'd1')
        dossier2 = createContentInContainer(
            portal, 'opengever.dossier.businesscasedossier', 'd2')

        document = createContentInContainer(
            dossier1, 'opengever.document.document', 'doc1', title='Document')

        document2 = createContentInContainer(
            dossier2, 'opengever.document.document', 'doc2', title='Document2')

        notify(ObjectMovedEvent(
            document,
            dossier1,
            'oldName',
            dossier2,
            'newName', ))
        self.check_annotation(
            dossier1,
            action_type='Object moved',
            action_title='Object moved: %s' % document.title_or_id(), )

        # Test that a normal ObjectAddedEvent does not result in an object
        # moved journal entry.
        notify(ObjectAddedEvent(document2))
        entry1 = get_journal_entry(dossier2, entry=-1)
        entry2 = get_journal_entry(dossier2, entry=-2)
        self.assertTrue(entry1.get('action').get('type') != 'Object moved')
        self.assertTrue(entry2.get('action').get('type') != 'Object moved')

        notify(ObjectWillBeMovedEvent(
            document,
            dossier1,
            'oldName',
            dossier2,
            'newName', ))
        self.check_annotation(
                dossier1,
                action_type='Object cut',
                action_title='Object cut: %s' % document.title_or_id(), )

        # Here we don't have a journal-entry
        length = get_journal_length(dossier1)
        notify(ObjectWillBeAddedEvent(
            document,
            dossier2,
            'newName', ))
        self.assertTrue(length == get_journal_length(dossier1))
コード例 #3
0
    def test_integration_object_events(self):
        """ Trigger every event of a objec at least one times
        and check the journalentries.
        """

        dossier1 = create(Builder('dossier'))
        dossier2 = create(Builder('dossier'))

        document = create(Builder('document')
                          .within(dossier1)
                          .titled(u'Document'))
        document2 = create(Builder('document')
                           .within(dossier2)
                           .titled(u'Document'))

        notify(ObjectMovedEvent(
            document,
            dossier1,
            'oldName',
            dossier2,
            'newName', ))
        self.check_annotation(
            dossier1,
            action_type='Object moved',
            action_title='Object moved: %s' % document.title_or_id(), )

        # Test that a normal ObjectAddedEvent does not result in an object
        # moved journal entry.
        notify(ObjectAddedEvent(document2))
        entry1 = get_journal_entry(dossier2, entry=-1)
        entry2 = get_journal_entry(dossier2, entry=-2)
        self.assertTrue(entry1.get('action').get('type') != 'Object moved')
        self.assertTrue(entry2.get('action').get('type') != 'Object moved')

        notify(ObjectWillBeMovedEvent(
            document,
            dossier1,
            'oldName',
            dossier2,
            'newName', ))
        self.check_annotation(
            dossier1,
            action_type='Object cut',
            action_title='Object cut: %s' % document.title_or_id())

        # Here we don't have a journal-entry
        length = get_journal_length(dossier1)
        notify(ObjectWillBeAddedEvent(
            document,
            dossier2,
            'newName', ))
        self.assertTrue(length == get_journal_length(dossier1))
コード例 #4
0
ファイル: testing.py プロジェクト: 4teamwork/opengever.core
    def checkin_document_via_api(self, browser, raw_token, payload, document, comment=None):
        self.assertTrue(document.is_checked_out())

        with self.as_officeconnector(browser):
            headers = {
                'Accept': 'application/json',
                'Authorization': ' '.join(('Bearer', raw_token, )),
                'Content-Type': 'application/json',
            }

            browser.open(
                document,
                view=payload.get('checkin'),
                method='POST',
                headers=headers,
                data=json.dumps({'comment': comment}),
            )

        self.assert_journal_entry(document, DOCUMENT_CHECKED_IN, u'Document checked in')

        journal_comments = get_journal_entry(document).get('comments')

        if comment:
            self.assertTrue(journal_comments)
        else:
            self.assertFalse(journal_comments)

        self.assertEquals(204, browser.status_code)
        self.assertFalse(document.is_checked_out())
コード例 #5
0
    def assert_doc_properties_updated_journal_entry_generated(
            self, document, user):
        entry = get_journal_entry(document)

        self.assertEqual(DOC_PROPERTIES_UPDATED, entry['action']['type'])
        self.assertEqual(user.id, entry['actor'])
        self.assertEqual('', entry['comments'])
コード例 #6
0
    def assert_journal_entry(self, obj, action_type, title, comment=None, entry=-1):  # noqa
        entry = get_journal_entry(obj, entry)
        action = entry.get('action')

        self.assertEquals(action_type, action.get('type'))
        self.assertEquals(title, translate(action.get('title')))

        if comment is not None:
            self.assertEquals(comment, entry.get('comments'))
コード例 #7
0
    def assert_journal_entry(self, obj, action_type, title, comment=None, entry=-1):  # noqa
        entry = get_journal_entry(obj, entry)
        action = entry.get('action')

        self.assertEquals(action_type, action.get('type'))
        self.assertEquals(title, translate(action.get('title')))

        if comment is not None:
            self.assertEquals(comment, entry.get('comments'))
コード例 #8
0
    def test_unlock_event_gets_logged_in_journal(self, browser):
        browser.login().open(self.repo, view='referenceprefix_manager')
        browser.css('.unlock').first.click()

        # get last journal entry
        journal = get_journal_entry(self.root, entry=-1)

        self.assertEquals(
            'Unlocked prefix 1 in weiterbildung.',
            translate(journal.get('action').get('title')))
コード例 #9
0
    def test_unlock_actions_are_journalized(self, browser):
        self.login(self.administrator, browser)
        browser.open(self.branch_repofolder, view='referenceprefix_manager')
        browser.click_on('Unlock')
        statusmessages.assert_no_error_messages()

        # get last journal entry
        journal = get_journal_entry(self.repository_root, entry=-1)
        self.assertEquals('Unlocked prefix 1 in fuhrung.',
                          translate(journal.get('action').get('title')))
コード例 #10
0
    def checkin_document(self,
                         browser,
                         tokens,
                         payload,
                         document,
                         comment=None):  # noqa
        with self.as_officeconnector(browser):
            headers = {
                'Authorization': ' '.join((
                    'Bearer',
                    tokens.get('raw_token'),
                )),
            }

            if comment:
                encoder = MultipartEncoder({
                    'form.widgets.comment':
                    comment,
                    'form.buttons.button_checkin':
                    'Checkin',
                    '_authenticator':
                    payload.get('csrf-token'),
                })

                headers['Content-Type'] = encoder.content_type

                browser.open(
                    document,
                    view=payload.get('checkin-with-comment'),
                    headers=headers,
                    method='POST',
                    data=encoder.to_string(),
                )
            else:
                browser.open(
                    document,
                    headers=headers,
                    view=payload.get('checkin-without-comment'),
                    send_authenticator=True,
                )

        self.assert_journal_entry(
            document,
            DOCUMENT_CHECKED_IN,
            u'Document checked in',
        )

        journal_comments = get_journal_entry(document).get('comments')
        if comment:
            self.assertTrue(journal_comments)
        else:
            self.assertFalse(journal_comments)

        self.assertEquals(200, browser.status_code)
コード例 #11
0
    def test_unlock_actions_are_journalized(self, browser):
        self.login(self.administrator, browser)
        browser.open(self.branch_repofolder, view='referenceprefix_manager')
        browser.click_on('Unlock')
        statusmessages.assert_no_error_messages()

        # get last journal entry
        journal = get_journal_entry(self.repository_root, entry=-1)
        self.assertEquals(
            'Unlocked prefix 1 in fuhrung.',
            translate(journal.get('action').get('title')))
コード例 #12
0
    def test_unlock_event_gets_logged_in_journal(self):
        self.browser.open('%s/referenceprefix_manager' % (self.repo.absolute_url()))

        # works because we only have one unlock button
        self.browser.getLink("Unlock").click()

        # get last journal entry
        journal = get_journal_entry(self.root, entry=-1)

        self.assertEquals(
            translate(journal.get('action').get('title')),
            'Unlocked prefix %d in %s.' % (1, self.repo.title_or_id()))
コード例 #13
0
    def test_unlock_event_gets_logged_in_journal(self):
        self.browser.open('%s/referenceprefix_manager' %
                          (self.repo.absolute_url()))

        # works because we only have one unlock button
        self.browser.getLink("Unlock").click()

        # get last journal entry
        journal = get_journal_entry(self.root, entry=-1)

        self.assertEquals(
            translate(journal.get('action').get('title')),
            'Unlocked prefix %d in %s.' % (1, self.repo.title_or_id()))
コード例 #14
0
    def test_listing_supports_filtering_on_comments(self, browser):
        with freeze(datetime(2016, 8, 12)):
            self.dossier = create(Builder('dossier'))
            entry = get_journal_entry(self.dossier)
            entry['comments'] = 'Lorem Ipsum'
            transaction.commit()
            browser.login().open(self.dossier, view=u'tabbedview_view-journal',
                                 data={'searchable_text': u'ipsum'})

            expected = [
                ['Time', 'Title', 'Changed by', 'Comments', 'References'],
                ['12.08.2016 00:00',
                 'Dossier added: dossier-1',
                 'Test User (test_user_1_)', 'Lorem Ipsum', '']]
            self.assertEquals(expected, browser.css('.listing').first.lists())
コード例 #15
0
    def test_checkin_document_with_comment(self, browser):
        self.login(self.regular_user, browser)
        manager = getMultiAdapter((self.document, self.request),
                                  ICheckinCheckoutManager)
        manager.checkout()

        browser.open(self.document.absolute_url() + '/@checkin',
                     data='{"comment": "foo bar"}',
                     method='POST',
                     headers={'Accept': 'application/json',
                              'Content-Type': 'application/json'})
        self.assertEqual(204, browser.status_code)
        self.assertFalse(self.document.is_checked_out())

        self.assertEqual(
            'foo bar', get_journal_entry(self.document)['comments'])
コード例 #16
0
ファイル: testing.py プロジェクト: lukasgraf/opengever.core
    def checkin_document(self, browser, tokens, payload, document, comment=None):  # noqa
        with self.as_officeconnector(browser):
            headers = {
                'Authorization': ' '.join((
                    'Bearer',
                    tokens.get('raw_token'),
                    )),
            }

            if comment:
                encoder = MultipartEncoder({
                    'form.widgets.comment': comment,
                    'form.buttons.button_checkin': 'Checkin',
                    '_authenticator': payload.get('csrf-token'),
                    })

                headers['Content-Type'] = encoder.content_type

                browser.open(
                    document,
                    view=payload.get('checkin-with-comment'),
                    headers=headers,
                    method='POST',
                    data=encoder.to_string(),
                    )
            else:
                browser.open(
                    document,
                    headers=headers,
                    view=payload.get('checkin-without-comment'),
                    send_authenticator=True,
                    )

        self.assert_journal_entry(
            document,
            DOCUMENT_CHECKED_IN,
            u'Document checked in',
            )

        journal_comments = get_journal_entry(document).get('comments')
        if comment:
            self.assertTrue(journal_comments)
        else:
            self.assertFalse(journal_comments)

        self.assertEquals(200, browser.status_code)
コード例 #17
0
    def check_annotation(self,
                         obj,
                         action_type='',
                         action_title='',
                         actor=TEST_USER_ID,
                         comment='',
                         check_entry=-1, ):
        """ Check the annotations for the right entries.
        """
        time = DateTime().Date()

        journal = get_journal_entry(obj, entry=check_entry)
        self.assertEquals(comment, journal.get('comments'))
        self.assertEquals(actor, journal.get('actor'))
        self.assertEquals(time, journal.get('time').Date())
        self.assertEquals(action_type, journal.get('action').get('type'))
        self.assertEquals(
            action_title, translate(journal.get('action').get('title')))
コード例 #18
0
    def check_annotation(self,
                         obj,
                         action_type='',
                         action_title='',
                         actor=TEST_USER_ID,
                         comment='',
                         check_entry=-1, ):
        """ Check the annotations for the right entries.
        """
        time = DateTime().Date()

        journal = get_journal_entry(obj, entry=check_entry)
        self.assertEquals(comment, journal.get('comments'))
        self.assertEquals(actor, journal.get('actor'))
        self.assertEquals(time, journal.get('time').Date())
        self.assertEquals(action_type, journal.get('action').get('type'))
        self.assertEquals(
            action_title, translate(journal.get('action').get('title')))
コード例 #19
0
    def test_checkin_document_with_comment(self, browser):
        self.login(self.regular_user, browser)
        manager = getMultiAdapter((self.document, self.request),
                                  ICheckinCheckoutManager)
        manager.checkout()

        browser.open(self.document.absolute_url() + '/@checkin',
                     data='{"comment": "foo bar"}',
                     method='POST',
                     headers={
                         'Accept': 'application/json',
                         'Content-Type': 'application/json'
                     })
        self.assertEqual(204, browser.status_code)
        self.assertFalse(self.document.is_checked_out())

        self.assertEqual('foo bar',
                         get_journal_entry(self.document)['comments'])
コード例 #20
0
    def test_files_with_custom_properties_are_not_updated(self):
        self.document = create(
            Builder('document')
            .within(self.dossier)
            .titled("Document with custom props")
            .with_asset_file('with_custom_properties.docx'))

        expected_doc_properties = [('Test', 'Peter',)]

        writer = DocPropertyWriter(self.document)
        writer.update_doc_properties(only_existing=True)
        with TemporaryDocFile(self.document.file) as tmpfile:
            properties = read_properties(tmpfile.path)
            self.assertItemsEqual(expected_doc_properties, properties)

        self.assertEqual(1, get_journal_length(self.document))
        entry = get_journal_entry(self.document)
        self.assertNotEqual(entry['action']['type'], DOC_PROPERTIES_UPDATED)
コード例 #21
0
    def test_files_with_custom_properties_are_not_updated(self):
        self.document = create(
            Builder('document').within(
                self.dossier).titled("Document with custom props").
            with_asset_file('with_custom_properties.docx'))

        expected_doc_properties = [(
            'Test',
            'Peter',
        )]

        writer = DocPropertyWriter(self.document)
        writer.update_doc_properties(only_existing=True)
        with TemporaryDocFile(self.document.file) as tmpfile:
            properties = read_properties(tmpfile.path)
            self.assertItemsEqual(expected_doc_properties, properties)

        self.assertEqual(1, get_journal_length(self.document))
        entry = get_journal_entry(self.document)
        self.assertNotEqual(entry['action']['type'], DOC_PROPERTIES_UPDATED)
コード例 #22
0
    def test_files_with_custom_properties_are_not_updated(self):
        self.login(self.regular_user)
        self.with_asset_file('with_custom_properties.docx')

        expected_doc_properties = [('Test', 'Peter',)]

        (
            DocPropertyWriter(self.document)
            .update_doc_properties(only_existing=True)
            )

        with TemporaryDocFile(self.document.file) as tmpfile:
            properties = read_properties(tmpfile.path)
            self.assertItemsEqual(expected_doc_properties, properties)

        self.assertEqual(1, get_journal_length(self.document))

        entry = get_journal_entry(self.document)

        self.assertNotEqual(entry['action']['type'], DOC_PROPERTIES_UPDATED)
コード例 #23
0
    def checkin_document_via_api(self,
                                 browser,
                                 raw_token,
                                 payload,
                                 document,
                                 comment=None):
        self.assertTrue(document.is_checked_out())

        with self.as_officeconnector(browser):
            headers = {
                'Accept': 'application/json',
                'Authorization': ' '.join((
                    'Bearer',
                    raw_token,
                )),
                'Content-Type': 'application/json',
            }

            browser.open(
                document,
                view=payload.get('checkin'),
                method='POST',
                headers=headers,
                data=json.dumps({'comment': comment}),
            )

        self.assert_journal_entry(document, DOCUMENT_CHECKED_IN,
                                  u'Document checked in')

        journal_comments = get_journal_entry(document).get('comments')

        if comment:
            self.assertTrue(journal_comments)
        else:
            self.assertFalse(journal_comments)

        self.assertEquals(204, browser.status_code)
        self.assertFalse(document.is_checked_out())
コード例 #24
0
    def test_integration_object_events(self):
        """ Trigger every event of a objec at least one times
        and check the journalentries.
        """
        portal = self.layer['portal']

        dossier1 = createContentInContainer(
            portal, 'opengever.dossier.businesscasedossier', 'd1')
        dossier2 = createContentInContainer(
            portal, 'opengever.dossier.businesscasedossier', 'd2')

        document = createContentInContainer(dossier1,
                                            'opengever.document.document',
                                            'doc1',
                                            title='Document')

        document2 = createContentInContainer(dossier2,
                                             'opengever.document.document',
                                             'doc2',
                                             title='Document2')

        notify(
            ObjectMovedEvent(
                document,
                dossier1,
                'oldName',
                dossier2,
                'newName',
            ))
        self.check_annotation(
            dossier1,
            action_type='Object moved',
            action_title='Object moved: %s' % document.title_or_id(),
        )

        # Test that a normal ObjectAddedEvent does not result in an object
        # moved journal entry.
        notify(ObjectAddedEvent(document2))
        entry1 = get_journal_entry(dossier2, entry=-1)
        entry2 = get_journal_entry(dossier2, entry=-2)
        self.assertTrue(entry1.get('action').get('type') != 'Object moved')
        self.assertTrue(entry2.get('action').get('type') != 'Object moved')

        notify(
            ObjectWillBeMovedEvent(
                document,
                dossier1,
                'oldName',
                dossier2,
                'newName',
            ))
        self.check_annotation(
            dossier1,
            action_type='Object cut',
            action_title='Object cut: %s' % document.title_or_id(),
        )

        # Here we don't have a journal-entry
        length = get_journal_length(dossier1)
        notify(ObjectWillBeAddedEvent(
            document,
            dossier2,
            'newName',
        ))
        self.assertTrue(length == get_journal_length(dossier1))
コード例 #25
0
ファイル: test_case.py プロジェクト: lukasgraf/opengever.core
 def assert_journal_entry(self, obj, action_type, title, entry=-1):
     entry = get_journal_entry(obj, entry)
     action = entry.get('action')
     self.assertEquals(action_type, action.get('type'))
     self.assertEquals(title, translate(action.get('title')))
コード例 #26
0
    def assert_doc_properties_updated_journal_entry_generated(self, document):
        entry = get_journal_entry(document)

        self.assertEqual(DOC_PROPERTIES_UPDATED, entry['action']['type'])
        self.assertEqual(TEST_USER_ID, entry['actor'])
        self.assertEqual('', entry['comments'])
コード例 #27
0
 def assert_journal_entry(self, obj, type, title, entry=-1):
     entry = get_journal_entry(obj, entry)
     action = entry.get('action')
     self.assertEquals(type, action.get('type'))
     self.assertEquals(title, translate(action.get('title')))