def test_notification_calls_uns(self): with record_events(notification.uns_notification_sent) as events: with self.app.test_request_context(): notification.notify(self.item, 'comment') self.assertEqual(len(events), 1)
def try_upload(self, name): data = { 'resumableFilename': 'data.gml', 'resumableIdentifier': 'data_gml', 'resumableTotalSize': '3', } file_data = dict(data) file_data['resumableChunkSize'] = '3' file_data['resumableChunkNumber'] = '1' file_data['file'] = (StringIO('teh'), 'data.gml') with record_events(parcel.file_uploaded) as uploaded_files: post_resp = self.client.post('/parcel/%s/chunk' % name, data=file_data) if post_resp.status_code == 403: self.assertEqual(len(uploaded_files), 0) return False elif post_resp.status_code == 200: resp = self.client.post('/parcel/%s/finalize_upload' % name, data=data) if resp.status_code != 200: self.fail('finalize upload failed') self.assertEqual(len(uploaded_files), 1) return True else: self.fail('unexpected http status code')
def try_new_parcel(self): with record_events(parcel.parcel_created) as new_parcels: post_resp = self.client.post("/parcel/new/country", data=self.PARCEL_METADATA) if post_resp.status_code == 403: self.assertEqual(len(new_parcels), 0) return False elif post_resp.status_code == 302: self.assertEqual(len(new_parcels), 1) return True else: self.fail("unexpected http status code")
def try_delete_file(self, parcel_name, filename="data.gml"): with record_events(parcel.parcel_file_deleted) as deleted_parcel_files: post_resp = self.client.post("/parcel/%s/file/%s/delete" % (parcel_name, filename)) if post_resp.status_code == 403: self.assertEqual(len(deleted_parcel_files), 0) return False elif post_resp.status_code == 302: self.assertEqual(len(deleted_parcel_files), 1) return True else: self.fail("unexpected http status code")
def try_finalize(self, parcel_name): with record_events(parcel.parcel_finalized) as finalized_parcels: post_resp = self.client.post('/parcel/%s/finalize' % parcel_name) if post_resp.status_code == 403: self.assertEqual(len(finalized_parcels), 0) return False elif post_resp.status_code == 302: self.assertEqual(len(finalized_parcels), 1) return True else: self.fail('unexpected http status code')
def try_finalize(self, parcel_name): with record_events(parcel.parcel_finalized) as finalized_parcels: post_resp = self.client.post("/parcel/%s/finalize" % parcel_name) if post_resp.status_code == 403: self.assertEqual(len(finalized_parcels), 0) return False elif post_resp.status_code == 302: self.assertEqual(len(finalized_parcels), 1) return True else: self.fail("unexpected http status code")
def try_new_report(self): with record_events(parcel.report_created) as new_reports: data = dict(self.REPORT_METADATA, file=(StringIO("ze file"), "doc.pdf")) resp = self.client.post("/report/new", data=data) if resp.status_code == 403: self.assertEqual(len(new_reports), 0) return False elif resp.status_code == 302: self.assertEqual(len(new_reports), 1) return True else: self.fail("unexpected http status code")
def try_new_parcel(self): with record_events(parcel.parcel_created) as new_parcels: post_resp = self.client.post('/parcel/new', data=self.PARCEL_METADATA) if post_resp.status_code == 403: self.assertEqual(len(new_parcels), 0) return False elif post_resp.status_code == 302: self.assertEqual(len(new_parcels), 1) return True else: self.fail('unexpected http status code')
def try_delete_file(self, parcel_name, filename='data.gml'): with record_events(parcel.parcel_file_deleted) as deleted_parcel_files: post_resp = self.client.post('/parcel/%s/file/%s/delete' % (parcel_name, filename)) if post_resp.status_code == 403: self.assertEqual(len(deleted_parcel_files), 0) return False elif post_resp.status_code == 302: self.assertEqual(len(deleted_parcel_files), 1) return True else: self.fail('unexpected http status code')
def test_notification_triggered_once_on_finalize_parcel(self): from definitions import RDF_URI resp_1 = self.client.post('/parcel/new', data=self.PARCEL_METADATA) self.assertEqual(resp_1.status_code, 302) parcel_name = resp_1.location.rsplit('/', 1)[-1] with record_events(notification.uns_notification_sent) as events: resp_2 = self.client.post('/parcel/%s/finalize' % parcel_name) self.assertEqual(resp_2.status_code, 302) self.assertEqual(len(events), 1) event_rdf = rdfdata(events[0]) self.assertEqual(event_rdf[RDF_URI['title']], ("Service provider upload finished" " (stage reference: %s)" % parcel_name)) self.assertNotIn(RDF_URI['decision'], event_rdf)
def test_notification_triggered_once_on_finalize_parcel(self): from gioland.definitions import RDF_URI resp_1 = self.client.post('/parcel/new/country', data=self.PARCEL_METADATA) self.assertEqual(resp_1.status_code, 302) parcel_name = resp_1.location.rsplit('/', 1)[-1] with record_events(notification.uns_notification_sent) as events: resp_2 = self.client.post('/parcel/%s/finalize' % parcel_name) self.assertEqual(resp_2.status_code, 302) self.assertEqual(len(events), 1) event_rdf = rdfdata(events[0]) self.assertEqual(event_rdf[RDF_URI['title']], ("Service provider upload finished" " (stage reference: %s)" % parcel_name)) self.assertNotIn(RDF_URI['decision'], event_rdf)
def test_parcel_rejection_triggers_accept_notification(self): from definitions import RDF_URI resp_1 = self.client.post('/parcel/new', data=self.PARCEL_METADATA) self.assertEqual(resp_1.status_code, 302) parcel1_name = resp_1.location.rsplit('/', 1)[-1] resp_2 = self.client.post('/parcel/%s/finalize' % parcel1_name) self.assertEqual(resp_2.status_code, 302) with self.app.test_request_context(): parcel1 = self.wh.get_parcel(parcel1_name) parcel2_name = parcel1.metadata['next_parcel'] with record_events(notification.uns_notification_sent) as events: resp_3 = self.client.post('/parcel/%s/finalize' % parcel2_name) self.assertEqual(resp_3.status_code, 302) self.assertEqual(len(events), 1) event_rdf = rdfdata(events[0]) self.assertEqual(event_rdf[RDF_URI['decision']], "accepted")
def test_parcel_rejection_triggers_accept_notification(self): from gioland.definitions import RDF_URI resp_1 = self.client.post('/parcel/new/country', data=self.PARCEL_METADATA) self.assertEqual(resp_1.status_code, 302) parcel1_name = resp_1.location.rsplit('/', 1)[-1] resp_2 = self.client.post('/parcel/%s/finalize' % parcel1_name) self.assertEqual(resp_2.status_code, 302) with self.app.test_request_context(): parcel1 = self.wh.get_parcel(parcel1_name) parcel2_name = parcel1.metadata['next_parcel'] with record_events(notification.uns_notification_sent) as events: resp_3 = self.client.post('/parcel/%s/finalize' % parcel2_name) self.assertEqual(resp_3.status_code, 302) self.assertEqual(len(events), 1) event_rdf = rdfdata(events[0]) self.assertEqual(event_rdf[RDF_URI['decision']], "accepted")
def try_upload(self, name): data = {"resumableFilename": "data.gml", "resumableIdentifier": "data_gml", "resumableTotalSize": "3"} file_data = dict(data) file_data["resumableChunkSize"] = "3" file_data["resumableChunkNumber"] = "1" file_data["file"] = (StringIO("teh"), "data.gml") with record_events(parcel.file_uploaded) as uploaded_files: post_resp = self.client.post("/parcel/%s/chunk" % name, data=file_data) if post_resp.status_code == 403: self.assertEqual(len(uploaded_files), 0) return False elif post_resp.status_code == 200: resp = self.client.post("/parcel/%s/finalize_upload" % name, data=data) if resp.status_code != 200: self.fail("finalize upload failed") self.assertEqual(len(uploaded_files), 1) return True else: self.fail("unexpected http status code")
def test_notification_not_triggered_on_new_parcel(self): with record_events(notification.uns_notification_sent) as events: resp = self.client.post('/parcel/new', data=self.PARCEL_METADATA) self.assertEqual(resp.status_code, 302) self.assertEqual(events, [])
def test_notification_not_triggered_on_new_parcel(self): with record_events(notification.uns_notification_sent) as events: resp = self.client.post('/parcel/new/country', data=self.PARCEL_METADATA) self.assertEqual(resp.status_code, 302) self.assertEqual(events, [])