def test_checkout_checkin_open_with_file_without_comment(self, browser): self.login(self.regular_user, browser) oc_url = self.fetch_document_checkout_oc_url(browser, self.document) self.assertIsNotNone(oc_url) self.assertEquals(200, browser.status_code) tokens = self.validate_checkout_token(self.regular_user, oc_url, self.document) payload = self.fetch_document_checkout_payloads(browser, tokens)[0] self.validate_checkout_payload(payload, self.document) self.checkout_document(browser, tokens, payload, self.document) lock_token = self.lock_document(browser, tokens, self.document) original_checksum = sha256( self.download_document(browser, tokens, payload), ).hexdigest() with open(path_to_asset('addendum.docx')) as f: self.upload_document(browser, tokens, payload, self.document, f) new_checksum = sha256( self.download_document(browser, tokens, payload), ).hexdigest() self.assertNotEquals(new_checksum, original_checksum) self.unlock_document(browser, tokens, self.document, lock_token) self.checkin_document(browser, tokens, payload, self.document)
def test_checkout_checkin_open_with_file_without_comment(self, browser): self.login(self.manager, browser) oc_url = self.fetch_document_checkout_oc_url(browser, self.document) self.assertIsNotNone(oc_url) self.assertEquals(200, browser.status_code) tokens = self.validate_checkout_token(self.manager, oc_url, self.document) payload = self.fetch_document_checkout_payloads(browser, tokens)[0] self.validate_checkout_payload(payload, self.document) self.checkout_document(browser, tokens, payload, self.document) lock_token = self.lock_document(browser, tokens, self.document) original_checksum = sha256( self.download_document(browser, tokens, payload), ).hexdigest() with open(path_to_asset('addendum.docx')) as f: self.upload_document(browser, tokens, payload, self.document, f) new_checksum = sha256(self.download_document(browser, tokens, payload), ).hexdigest() self.assertNotEquals(new_checksum, original_checksum) self.unlock_document(browser, tokens, self.document, lock_token) self.checkin_document(browser, tokens, payload, self.document)
def test_checkout_checkin_open_with_file_without_comment(self, browser): self.login(self.manager, browser) with freeze(FREEZE_DATE): oc_url = self.fetch_document_checkout_oc_url(browser, self.document) self.assertIsNotNone(oc_url) self.assertEquals(200, browser.status_code) expected_token = { u'action': u'checkout', u'documents': [u'createtreatydossiers000000000002'], u'exp': 4121033100, u'sub': u'admin', u'url': u'http://nohost/plone/oc_checkout', } raw_token = oc_url.split(':')[-1] token = jwt.decode(raw_token, JWT_SIGNING_SECRET_ZOPE, algorithms=('HS256',)) self.assertEqual(expected_token, token) expected_payloads = [{ u'checkin-with-comment': u'@@checkin_document', u'checkin-without-comment': u'checkin_without_comment', u'checkout': u'@@checkout_documents', u'content-type': u'application/vnd.openxmlformats-officedocument.wordprocessingml.document', u'document-url': u'http://nohost/plone/ordnungssystem/fuhrung/vertrage-und-vereinbarungen/dossier-1/document-14', u'download': u'download', u'filename': u'Vertraegsentwurf.docx', u'upload-form': u'file_upload', u'uuid': u'createtreatydossiers000000000002', }] payloads = self.fetch_document_checkout_payloads(browser, raw_token, token) self.assertEquals(200, browser.status_code) for payload, expected_payload in zip(payloads, expected_payloads): payload_copy = deepcopy(payload) self.assertTrue(payload_copy.pop('csrf-token', None)) self.assertFalse(payload_copy.pop('reauth', None)) self.assertEqual(expected_payload, payload_copy) self.checkout_document(browser, raw_token, payloads[0], self.document) lock_token = self.lock_document(browser, raw_token, self.document) original_checksum = sha256( self.download_document(browser, raw_token, payloads[0]), ).hexdigest() with open(path_to_asset('addendum.docx')) as f: self.upload_document(browser, raw_token, payloads[0], self.document, f) new_checksum = sha256( self.download_document(browser, raw_token, payloads[0]), ).hexdigest() self.assertNotEquals(new_checksum, original_checksum) self.unlock_document(browser, raw_token, self.document, lock_token) self.checkin_document(browser, raw_token, payloads[0], self.document)
def test_tus_can_upload_msg_mail(self, browser): self.login(self.regular_user, browser) # initialize the upload with POST filename = 'testmail.msg' file_path = path_to_asset(filename) file_size = os.path.getsize(file_path) metadata = _prepare_metadata(filename, eml_mimetype, 'ftw.mail.mail') response = browser.open( self.empty_dossier.absolute_url() + '/@tus-upload', method='POST', headers={ 'Accept': 'application/json', "Tus-Resumable": "1.0.0", "Upload-Length": str(file_size), "Upload-Metadata": metadata }, ) self.assertEqual(response.status_code, 201) # upload the data with PATCH location = response.headers["Location"] with self.observe_children(self.empty_dossier) as children: with open(file_path, "rb") as infile: response = browser.open( location, method='PATCH', headers={ 'Accept': 'application/json', "Content-Type": "application/offset+octet-stream", "Upload-Offset": "0", "Tus-Resumable": "1.0.0", }, data=infile.read(), ) self.assertEqual(response.status_code, 204) self.assertEqual(1, len(children['added'])) uploaded_mail = children['added'].pop() self.assertEqual(filename, uploaded_mail.get_filename()) self.assertEqual('ftw.mail.mail', uploaded_mail.portal_type) self.assertEqual(file_size, uploaded_mail.get_file().size) # make sure that the uploaded file was moved to the original_message field self.assertIsNotNone(uploaded_mail.original_message) self.assertEqual(file_size, uploaded_mail.original_message.size)
def test_tus_can_upload_text_file_as_ogdocument(self, browser): self.login(self.regular_user, browser) # initialize the upload with POST filename = 'text.txt' file_path = path_to_asset(filename) file_size = os.path.getsize(file_path) metadata = _prepare_metadata(filename, eml_mimetype, 'opengever.document.document') response = browser.open( self.empty_dossier.absolute_url() + '/@tus-upload', method='POST', headers={ 'Accept': 'application/json', "Tus-Resumable": "1.0.0", "Upload-Length": str(file_size), "Upload-Metadata": metadata }, ) self.assertEqual(response.status_code, 201) # upload the data with PATCH location = response.headers["Location"] with self.observe_children(self.empty_dossier) as children: with open(file_path, "rb") as infile: response = browser.open( location, method='PATCH', headers={ 'Accept': 'application/json', "Content-Type": "application/offset+octet-stream", "Upload-Offset": "0", "Tus-Resumable": "1.0.0", }, data=infile.read(), ) self.assertEqual(response.status_code, 204) self.assertEqual(1, len(children['added'])) uploaded_document = children['added'].pop() self.assertEqual(filename, uploaded_document.get_filename()) self.assertEqual('opengever.document.document', uploaded_document.portal_type) self.assertEqual(file_size, uploaded_document.get_file().size)
def test_foreign_contributor_can_checkout_related_document_on_assigned_task(self, browser): self.login(self.regular_user, browser) # We get a reference to self.document so the foreign user can access it document = self.document browser.open(self.dossier) factoriesmenu.add('Task') browser.fill({ 'Title': 'Task title', 'Task Type': 'For direct execution', 'Related Items': document, }) form = browser.find_form_by_field('Responsible') form.find_widget('Responsible').fill( ':'.join(('rk', self.foreign_contributor.getId()))) browser.find('Save').click() self.login(self.foreign_contributor, browser) with freeze(FREEZE_DATE): oc_url = self.fetch_document_checkout_oc_url(browser, document) self.assertIsNotNone(oc_url) self.assertEqual(200, browser.status_code) expected_token = { u'action': u'checkout', u'documents': [u'createtreatydossiers000000000002'], u'exp': 4121033100, u'sub': u'james.bond', u'url': u'http://nohost/plone/oc_checkout', } raw_token = oc_url.split(':')[-1] token = jwt.decode(raw_token, JWT_SIGNING_SECRET_PLONE, algorithms=('HS256',)) self.assertEqual(expected_token, token) expected_payloads = [{ u'status': u'status', u'checkin': u'@checkin', u'checkout': u'@checkout', u'content-type': u'application/vnd.openxmlformats-officedocument.wordprocessingml.document', u'document-url': u'http://nohost/plone/ordnungssystem/fuhrung/vertrage-und-vereinbarungen/dossier-1/document-14', u'download': u'download', u'filename': u'Vertraegsentwurf.docx', u'lock': u'@lock', u'unlock': u'@unlock', u'upload': u'@tus-replace', u'uuid': u'createtreatydossiers000000000002', }] payloads = self.fetch_document_checkout_payloads(browser, raw_token, token) self.assertEqual(200, browser.status_code) for payload, expected_payload in zip(payloads, expected_payloads): payload_copy = deepcopy(payload) self.assertFalse(payload_copy.pop('csrf-token', None)) self.assertTrue(payload_copy.pop('reauth', None)) self.assertEqual(expected_payload, payload_copy) self.checkout_document_via_api(browser, raw_token, payloads[0], document) self.lock_document_via_api(browser, raw_token, payloads[0], document) original_checksum = sha256(self.download_document(browser, raw_token, payloads[0])).hexdigest() with open(path_to_asset('addendum.docx')) as f: self.upload_document_via_api(browser, raw_token, payloads[0], document, f) new_checksum = sha256(self.download_document(browser, raw_token, payloads[0])).hexdigest() self.assertNotEqual(new_checksum, original_checksum) self.unlock_document_via_api(browser, raw_token, payloads[0], document) self.checkin_document_via_api(browser, raw_token, payloads[0], document)
def test_create_with_oneoffixx(self, browser): self.login(self.dossier_responsible, browser) with freeze(FREEZE_DATE): oc_url = self.fetch_document_oneoffixx_oc_url(browser, self.shadow_document) self.assertIsNotNone(oc_url) self.assertEquals(200, browser.status_code) expected_token = { u'action': u'oneoffixx', u'documents': [u'createshadowdocument000000000001'], u'exp': 4121033100, u'sub': u'robert.ziegler', u'url': u'http://nohost/plone/oc_oneoffixx', } raw_token = oc_url.split(':')[-1] token = jwt.decode(raw_token, JWT_SIGNING_SECRET_PLONE, algorithms=('HS256',)) self.assertEqual(expected_token, token) expected_payloads = [{ u'connect-xml': u'@@oneoffix_connect_xml', u'content-type': u'application/vnd.openxmlformats-officedocument.wordprocessingml.document', u'document-url': u'http://nohost/plone/ordnungssystem/fuhrung/vertrage-und-vereinbarungen/dossier-1/document-38', u'filename': None, u'uuid': u'createshadowdocument000000000001', }] payloads = self.fetch_document_oneoffixx_payloads(browser, raw_token, token) self.assertEquals(200, browser.status_code) for payload, expected_payload in zip(payloads, expected_payloads): self.assertTrue(payload.pop('csrf-token', None)) self.assertEqual(expected_payload, payload) expected_oneoffixx_xml = resource_string("opengever.oneoffixx.tests.assets", "oneoffixx_connect_xml.txt") with freeze(FREEZE_DATE): oneoffixx_xml = self.download_oneoffixx_xml(browser, raw_token, payloads[0]) self.maxDiff = None self.assertEqual(expected_oneoffixx_xml.splitlines(), oneoffixx_xml.splitlines()) tree = ET.ElementTree(ET.fromstring(oneoffixx_xml)) namespace = re.match(r'\{.*\}', tree.getroot().tag).group(0) namespace_url = namespace.strip('{}') ET.register_namespace('', namespace_url) ET.register_namespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance') raw_token = tree.find( './/{namespace}Command[@Name="InvokeProcess"]' '/{namespace}Parameters' '/{namespace}Add[@key="Arguments"]' .format(namespace=namespace) ).text.split(':')[-1] expected_token = { u'action': u'checkout', u'documents': [u'createshadowdocument000000000001'], u'exp': 4121033100, u'sub': u'robert.ziegler', u'url': u'http://nohost/plone/oc_checkout', } token = jwt.decode(raw_token, JWT_SIGNING_SECRET_PLONE, algorithms=('HS256',)) self.assertEqual(expected_token, token) expected_payloads = [{ u'checkin-with-comment': u'@@checkin_document', u'checkin-without-comment': u'checkin_without_comment', u'checkout': u'@@checkout_documents', u'content-type': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', u'document-url': u'http://nohost/plone/ordnungssystem/fuhrung/vertrage-und-vereinbarungen/dossier-1/document-38', u'download': u'download', u'filename': None, u'upload-form': u'file_upload', u'uuid': u'createshadowdocument000000000001', }] # XXX - As the last document we touched was XML and we touched XML # namespacing after that, we'll need to reset the browser to circumvent # an ftw.testbrowser bug browser.reset() payloads = self.fetch_document_checkout_payloads(browser, raw_token, token) self.assertEquals(200, browser.status_code) for payload, expected_payload in zip(payloads, expected_payloads): payload_copy = deepcopy(payload) self.assertTrue(payload_copy.pop('csrf-token', None)) self.assertFalse(payload_copy.pop('reauth', None)) self.assertEqual(expected_payload, payload_copy) self.assertTrue(self.shadow_document.is_shadow_document()) self.checkout_document(browser, raw_token, payloads[0], self.shadow_document) lock_token = self.lock_document(browser, raw_token, self.shadow_document) with open(path_to_asset('addendum.docx')) as f: self.upload_document(browser, raw_token, payloads[0], self.shadow_document, f) self.assertFalse(self.shadow_document.is_shadow_document()) self.unlock_document(browser, raw_token, self.shadow_document, lock_token) self.checkin_document(browser, raw_token, payloads[0], self.shadow_document, comment='foobar')
def test_checkout_checkin_open_with_file_without_comment(self, browser): self.login(self.regular_user, browser) with freeze(FREEZE_DATE): oc_url = self.fetch_document_checkout_oc_url( browser, self.document) self.assertIsNotNone(oc_url) self.assertEqual(200, browser.status_code) expected_token = { u'action': u'checkout', u'documents': [u'createtreatydossiers000000000002'], u'exp': 4121033100, u'sub': u'kathi.barfuss', u'url': u'http://nohost/plone/oc_checkout', } raw_token = oc_url.split(':')[-1] token = jwt.decode(raw_token, JWT_SIGNING_SECRET_PLONE, algorithms=('HS256', )) self.assertEqual(expected_token, token) expected_payloads = [{ u'status': u'status', u'checkin': u'@checkin', u'checkout': u'@checkout', u'content-type': u'application/vnd.openxmlformats-officedocument.wordprocessingml.document', u'document-url': u'http://nohost/plone/ordnungssystem/fuhrung/vertrage-und-vereinbarungen/dossier-1/document-14', u'download': u'download', u'filename': u'Vertraegsentwurf.docx', u'lock': u'@lock', u'unlock': u'@unlock', u'upload': u'@tus-replace', u'uuid': u'createtreatydossiers000000000002', }] payloads = self.fetch_document_checkout_payloads( browser, raw_token, token) self.assertEqual(200, browser.status_code) for payload, expected_payload in zip(payloads, expected_payloads): payload_copy = deepcopy(payload) self.assertFalse(payload_copy.pop('csrf-token', None)) self.assertTrue(payload_copy.pop('reauth', None)) self.assertEqual(expected_payload, payload_copy) self.checkout_document_via_api(browser, raw_token, payloads[0], self.document) self.lock_document_via_api(browser, raw_token, payloads[0], self.document) original_checksum = sha256( self.download_document(browser, raw_token, payloads[0])).hexdigest() with open(path_to_asset('addendum.docx')) as f: self.upload_document_via_api(browser, raw_token, payloads[0], self.document, f) new_checksum = sha256( self.download_document(browser, raw_token, payloads[0])).hexdigest() self.assertNotEqual(new_checksum, original_checksum) self.unlock_document_via_api(browser, raw_token, payloads[0], self.document) self.checkin_document_via_api(browser, raw_token, payloads[0], self.document)
def test_create_with_oneoffixx(self, browser): self.login(self.dossier_responsible, browser) with freeze(FREEZE_DATE): oc_url = self.fetch_document_oneoffixx_oc_url( browser, self.shadow_document) self.assertIsNotNone(oc_url) self.assertEquals(200, browser.status_code) expected_token = { u'action': u'oneoffixx', u'documents': [u'createshadowdocument000000000001'], u'exp': 4121033100, u'sub': u'robert.ziegler', u'url': u'http://nohost/plone/oc_oneoffixx', } raw_token = oc_url.split(':')[-1] token = jwt.decode(raw_token, JWT_SIGNING_SECRET_PLONE, algorithms=('HS256', )) self.assertEqual(expected_token, token) expected_payloads = [{ u'connect-xml': u'@@oneoffix_connect_xml', u'content-type': u'application/vnd.openxmlformats-officedocument.wordprocessingml.document', u'document-url': u'http://nohost/plone/ordnungssystem/fuhrung/vertrage-und-vereinbarungen/dossier-1/document-38', u'filename': None, u'uuid': u'createshadowdocument000000000001', }] payloads = self.fetch_document_oneoffixx_payloads( browser, raw_token, token) self.assertEquals(200, browser.status_code) for payload, expected_payload in zip(payloads, expected_payloads): self.assertTrue(payload.pop('csrf-token', None)) self.assertEqual(expected_payload, payload) expected_oneoffixx_xml = resource_string( "opengever.oneoffixx.tests.assets", "oneoffixx_connect_xml.txt") with freeze(FREEZE_DATE): oneoffixx_xml = self.download_oneoffixx_xml( browser, raw_token, payloads[0]) self.maxDiff = None self.assertEqual(expected_oneoffixx_xml.splitlines(), oneoffixx_xml.splitlines()) tree = ET.ElementTree(ET.fromstring(oneoffixx_xml)) namespace = re.match(r'\{.*\}', tree.getroot().tag).group(0) namespace_url = namespace.strip('{}') ET.register_namespace('', namespace_url) ET.register_namespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance') raw_token = tree.find('.//{namespace}Command[@Name="InvokeProcess"]' '/{namespace}Parameters' '/{namespace}Add[@key="Arguments"]'.format( namespace=namespace)).text.split(':')[-1] expected_token = { u'action': u'checkout', u'documents': [u'createshadowdocument000000000001'], u'exp': 4121033100, u'sub': u'robert.ziegler', u'url': u'http://nohost/plone/oc_checkout', } token = jwt.decode(raw_token, JWT_SIGNING_SECRET_PLONE, algorithms=('HS256', )) self.assertEqual(expected_token, token) expected_payloads = [{ u'checkin-with-comment': u'@@checkin_document', u'checkin-without-comment': u'checkin_without_comment', u'checkout': u'@@checkout_documents', u'content-type': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', u'document-url': u'http://nohost/plone/ordnungssystem/fuhrung/vertrage-und-vereinbarungen/dossier-1/document-38', u'download': u'download', u'filename': None, u'upload-form': u'file_upload', u'uuid': u'createshadowdocument000000000001', }] # XXX - As the last document we touched was XML and we touched XML # namespacing after that, we'll need to reset the browser to circumvent # an ftw.testbrowser bug browser.reset() payloads = self.fetch_document_checkout_payloads( browser, raw_token, token) self.assertEquals(200, browser.status_code) for payload, expected_payload in zip(payloads, expected_payloads): payload_copy = deepcopy(payload) self.assertTrue(payload_copy.pop('csrf-token', None)) self.assertFalse(payload_copy.pop('reauth', None)) self.assertEqual(expected_payload, payload_copy) self.assertTrue(self.shadow_document.is_shadow_document()) self.checkout_document(browser, raw_token, payloads[0], self.shadow_document) lock_token = self.lock_document(browser, raw_token, self.shadow_document) with open(path_to_asset('addendum.docx')) as f: self.upload_document(browser, raw_token, payloads[0], self.shadow_document, f) self.assertFalse(self.shadow_document.is_shadow_document()) self.unlock_document(browser, raw_token, self.shadow_document, lock_token) self.checkin_document(browser, raw_token, payloads[0], self.shadow_document, comment='foobar')
def test_files_with_cached_custom_properties_are_updated(self): self.login(self.regular_user) filename = 'with_cached_custom_properties.docx' expected_properties = { 'Document.ReferenceNumber': '00 / 11 / 222', 'Document.SequenceNumber': '222', 'Dossier.ReferenceNumber': '00 / 11', 'Dossier.Title': 'Foo Dossier', 'User.FullName': 'Foo Bar', 'User.ID': 'foo.bar', 'ogg.document.delivery_date': datetime(2000, 2, 2, 10, 0, tzinfo=pytz.utc), 'ogg.document.document_author': 'Foo Bar', 'ogg.document.document_date': datetime(1990, 1, 1, 10, 0, tzinfo=pytz.utc), 'ogg.document.document_type': 'Foo Docu', 'ogg.document.reception_date': datetime(2010, 3, 3, 10, 0, tzinfo=pytz.utc), 'ogg.document.reference_number': '0 / 11 / 222', 'ogg.document.sequence_number': '222', 'ogg.document.title': 'cached-docprops', 'ogg.document.version_number': 333, 'ogg.dossier.reference_number': '0 / 11', 'ogg.dossier.sequence_number': '11', 'ogg.dossier.title': 'Foo Dossier', 'ogg.user.title': 'foobar', 'ogg.user.userid': 'foobar', } properties = dict(property for property in read_properties(assets.path_to_asset(filename))) self.assertItemsEqual(expected_properties, properties) self.with_asset_file(filename) DocPropertyWriter(self.document).update_doc_properties(only_existing=False) expected_properties = { 'Document.ReferenceNumber': 'Client1 1.1 / 1 / 12', 'Document.SequenceNumber': '12', 'Dossier.ReferenceNumber': 'Client1 1.1 / 1', 'Dossier.Title': u'Vertr\xe4ge mit der kantonalen Finanzverwaltung', 'User.FullName': u'B\xe4rfuss K\xe4thi', 'User.ID': 'kathi.barfuss', 'ogg.document.delivery_date': datetime(2010, 1, 3, 0, 0), 'ogg.document.document_author': 'test_user_1_', 'ogg.document.document_date': datetime(2010, 1, 3, 0, 0), 'ogg.document.document_type': 'Contract', 'ogg.document.reception_date': datetime(2010, 1, 3, 0, 0), 'ogg.document.reference_number': 'Client1 1.1 / 1 / 12', 'ogg.document.sequence_number': '12', 'ogg.document.title': u'Vertr\xe4gsentwurf', 'ogg.document.version_number': 0, 'ogg.dossier.external_reference': u'qpr-900-9001-\xf7', 'ogg.dossier.reference_number': 'Client1 1.1 / 1', 'ogg.dossier.sequence_number': '1', 'ogg.dossier.title': u'Vertr\xe4ge mit der kantonalen Finanzverwaltung', 'ogg.user.address1': 'Kappelenweg 13', 'ogg.user.address2': 'Postfach 1234', 'ogg.user.city': 'Vorkappelen', 'ogg.user.country': 'Schweiz', 'ogg.user.department': 'Staatskanzlei', 'ogg.user.department_abbr': 'SK', 'ogg.user.description': 'nix', 'ogg.user.directorate': 'Staatsarchiv', 'ogg.user.directorate_abbr': 'Arch', 'ogg.user.email': '*****@*****.**', 'ogg.user.email2': '*****@*****.**', 'ogg.user.firstname': u'K\xe4thi', 'ogg.user.lastname': u'B\xe4rfuss', 'ogg.user.phone_fax': '012 34 56 77', 'ogg.user.phone_mobile': '012 34 56 76', 'ogg.user.phone_office': '012 34 56 78', 'ogg.user.salutation': 'Prof. Dr.', 'ogg.user.title': u'B\xe4rfuss K\xe4thi', 'ogg.user.url': 'http://www.example.com', 'ogg.user.userid': 'kathi.barfuss', 'ogg.user.zip_code': '1234', } with TemporaryDocFile(self.document.file) as tmpfile: properties = dict(property for property in read_properties(tmpfile.path)) self.assertItemsEqual(expected_properties, properties)
def test_foreign_contributor_can_checkout_related_document_on_assigned_task( self, browser): self.login(self.regular_user, browser) # We get a reference to self.document so the foreign user can access it document = self.document browser.open(self.dossier) factoriesmenu.add('Task') browser.fill({ 'Title': 'Task title', 'Task Type': 'For direct execution', 'Related Items': document, }) form = browser.find_form_by_field('Responsible') form.find_widget('Responsible').fill(':'.join( ('rk', self.foreign_contributor.getId()))) browser.find('Save').click() self.login(self.foreign_contributor, browser) with freeze(FREEZE_DATE): oc_url = self.fetch_document_checkout_oc_url(browser, document) self.assertIsNotNone(oc_url) self.assertEqual(200, browser.status_code) expected_token = { u'action': u'checkout', u'documents': [u'createtreatydossiers000000000002'], u'exp': 4121033100, u'sub': u'james.bond', u'url': u'http://nohost/plone/oc_checkout', } raw_token = oc_url.split(':')[-1] token = jwt.decode(raw_token, JWT_SIGNING_SECRET_PLONE, algorithms=('HS256', )) self.assertEqual(expected_token, token) expected_payloads = [{ u'status': u'status', u'checkin': u'@checkin', u'checkout': u'@checkout', u'content-type': u'application/vnd.openxmlformats-officedocument.wordprocessingml.document', u'document-url': u'http://nohost/plone/ordnungssystem/fuhrung/vertrage-und-vereinbarungen/dossier-1/document-14', u'download': u'download', u'filename': u'Vertraegsentwurf.docx', u'lock': u'@lock', u'unlock': u'@unlock', u'upload': u'@tus-replace', u'uuid': u'createtreatydossiers000000000002', }] payloads = self.fetch_document_checkout_payloads( browser, raw_token, token) self.assertEqual(200, browser.status_code) for payload, expected_payload in zip(payloads, expected_payloads): payload_copy = deepcopy(payload) self.assertFalse(payload_copy.pop('csrf-token', None)) self.assertTrue(payload_copy.pop('reauth', None)) self.assertEqual(expected_payload, payload_copy) self.checkout_document_via_api(browser, raw_token, payloads[0], document) self.lock_document_via_api(browser, raw_token, payloads[0], document) original_checksum = sha256( self.download_document(browser, raw_token, payloads[0])).hexdigest() with open(path_to_asset('addendum.docx')) as f: self.upload_document_via_api(browser, raw_token, payloads[0], document, f) new_checksum = sha256( self.download_document(browser, raw_token, payloads[0])).hexdigest() self.assertNotEqual(new_checksum, original_checksum) self.unlock_document_via_api(browser, raw_token, payloads[0], document) self.checkin_document_via_api(browser, raw_token, payloads[0], document)