def test_reset_journal_after_creating_a_copy(self): dossier = create(Builder('dossier').titled(u'Dossier')) document = create(Builder('document') .within(dossier) .titled("File to copy")) entry = ManualJournalEntry(document, 'meeting', 'comment', [], [], []) entry.save() cb = dossier.manage_copyObjects(document.getId()) dossier.manage_pasteObjects(cb) clone = dossier.objectValues()[-1] journal = IAnnotations(document).get(JOURNAL_ENTRIES_ANNOTATIONS_KEY) journal_clone = IAnnotations(clone).get( JOURNAL_ENTRIES_ANNOTATIONS_KEY) self.assertNotEquals(len(journal), len(journal_clone)) self.assertEquals( 1, len(journal_clone), 'Exepct exactly on entry in the journal of the cloned document') self.assertEquals(DOCUMENT_ADDED_ACTION, journal_clone[0]['action']['type'])
def createAndAdd(self, data): contacts, users = self.split_contacts_and_users(data.get('contacts')) entry = ManualJournalEntry(self.context, data.get('category'), data.get('comment'), contacts, users, data.get('related_documents')) entry.save() return entry
def reply(self): data = json_body(self.request) category = data.get('category', DEFAULT_COMMENT_CATEGORY) comment = data.get('comment') if not comment: raise BadRequest( "The request body requires the 'comment' attribute") if not self._validate_category(category): raise BadRequest("The provided 'category' does not exists.") documents, invalid_urls = self._lookup_documents( data.get('related_documents', [])) if invalid_urls: raise BadRequest( "Could not lookup the following documents: {}".format( ', '.join(invalid_urls))) contacts = [] users = [] entry = ManualJournalEntry(self.context, category, comment, contacts, users, documents) entry.save() self.request.response.setStatus(204) return super(JournalPost, self).reply()
def reply(self): data = json_body(self.request) category = data.get('category', DEFAULT_COMMENT_CATEGORY) comment = data.get('comment') if not comment: raise BadRequest("The request body requires the 'comment' attribute") if not self._validate_category(category): raise BadRequest("The provided 'category' does not exists.") documents, invalid_urls = self._lookup_documents( data.get('related_documents', [])) if invalid_urls: raise BadRequest( "Could not lookup the following documents: {}".format( ', '.join(invalid_urls))) contacts = [] users = [] entry = ManualJournalEntry(self.context, category, comment, contacts, users, documents) entry.save() self.request.response.setStatus(204) return super(JournalPost, self).reply()
def test_validate_item_fields(self, browser): self.login(self.regular_user, browser) person = create( Builder('person').having(firstname=u'H\xfcgo', lastname='Boss')) user = OgdsUserToContactAdapter.query.get(self.regular_user.id) with freeze(datetime(2017, 10, 16, 0, 0, tzinfo=pytz.utc)): ManualJournalEntry(self.dossier, 'information', 'is an agent', [person], [user], [self.document]).save() response = browser.open( self.dossier.absolute_url() + '/@journal?b_size=2', method='GET', headers=http_headers(), ).json self.assertDictEqual( { 'actor_fullname': u'B\xe4rfuss K\xe4thi', 'actor_id': u'kathi.barfuss', 'comments': u'is an agent', 'time': u'2017-10-16T00:00:00+00:00', 'title': u'Manual entry: Information' }, response.get('items')[0])
def test_returns_journal_entries_in_newest_first_order(self, browser): self.login(self.regular_user, browser) self.clear_journal_entries(self.dossier) ManualJournalEntry(self.dossier, 'information', 'first', [], [], []).save() ManualJournalEntry(self.dossier, 'information', 'second', [], [], []).save() response = browser.open( self.dossier.absolute_url() + '/@journal', method='GET', headers=http_headers(), ).json entry_titles = [item.get('comments') for item in response.get('items')] self.assertEqual(['second', 'first'], entry_titles)
def test_show_total_items(self, browser): self.login(self.regular_user, browser) self.clear_journal_entries(self.dossier) ManualJournalEntry(self.dossier, 'information', 'first', [], [], []).save() ManualJournalEntry(self.dossier, 'information', 'second', [], [], []).save() browser.open( self.dossier.absolute_url() + '/@journal', method='GET', headers=http_headers(), ) response = browser.json self.assertEqual(2, response.get('items_total'))
def test_listing_is_batched(self, browser): self.login(self.regular_user, browser) self.clear_journal_entries(self.dossier) ManualJournalEntry(self.dossier, 'information', 'first', [], [], []).save() ManualJournalEntry(self.dossier, 'information', 'second', [], [], []).save() ManualJournalEntry(self.dossier, 'information', 'third', [], [], []).save() response = browser.open( self.dossier.absolute_url() + '/@journal?b_size=2', method='GET', headers=http_headers(), ).json self.assertEqual(3, response.get('items_total')) self.assertEqual(2, len(response.get('items'))) self.assertIn('batching', response)