From 8ae7c4ac486547a9cfa57fc9a46e9ef98512a4bd Mon Sep 17 00:00:00 2001 From: Jorrit Schaap <schaap@astron.nl> Date: Tue, 23 Jun 2020 16:48:09 +0200 Subject: [PATCH] TMSS-207: added some helper methods --- SAS/TMSS/test/tmss_test_data_rest.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/SAS/TMSS/test/tmss_test_data_rest.py b/SAS/TMSS/test/tmss_test_data_rest.py index 9d494439180..79a864a2de4 100644 --- a/SAS/TMSS/test/tmss_test_data_rest.py +++ b/SAS/TMSS/test/tmss_test_data_rest.py @@ -31,13 +31,21 @@ class TMSSRESTTestDataCreator(): self.django_api_url = django_api_url self.auth = auth + def get_response_as_json_object(self, url): + """GET the given data the self.django_api_url+url_postfix, and return the response""" + return json.loads(requests.get(url, auth=self.auth).content.decode('utf-8')) + def post_data_and_get_response(self, data, url_postfix): """POST the given data the self.django_api_url+url_postfix, and return the response""" return requests.post(self.django_api_url + url_postfix, json=data, auth=self.auth) + def post_data_and_get_response_as_json_object(self, data, url_postfix): + """POST the given data the self.django_api_url+url_postfix, and return the response""" + return json.loads(self.post_data_and_get_response(data, url_postfix).content.decode('utf-8')) + def post_data_and_get_url(self, data, url_postfix): """POST the given data the self.django_api_url+url_postfix, and return the response's url""" - return json.loads(self.post_data_and_get_response(data, url_postfix).content.decode('utf-8'))['url'] + return self.post_data_and_get_response_as_json_object(data, url_postfix)['url'] ####################################################### # the methods below can be used to create test data @@ -393,7 +401,7 @@ class TMSSRESTTestDataCreator(): return {"subtask": subtask_url, "tags": []} - def Dataproduct(self, filename="my_filename", specifications_template_url=None, subtask_output_url=None, dataproduct_feedback_template_url=None): + def Dataproduct(self, filename="my_filename", directory="/tmp/", specifications_template_url=None, subtask_output_url=None, dataproduct_feedback_template_url=None, dataformat="MeasurementSet"): if specifications_template_url is None: specifications_template_url = self.post_data_and_get_url(self.SubtaskTemplate(), '/dataproduct_specifications_template/') @@ -403,16 +411,16 @@ class TMSSRESTTestDataCreator(): if dataproduct_feedback_template_url is None: dataproduct_feedback_template_url = self.post_data_and_get_url(self.DataproductFeedbackTemplate(), '/dataproduct_feedback_template/') - return {"filename": "my.file", - "directory": "/home/boskabouter/", - "dataformat": self.django_api_url + '/dataformat/Beamformed/', + return {"filename": filename, + "directory": directory, + "dataformat": "%s/dataformat/%s/" % (self.django_api_url, dataformat), "deleted_since": None, "pinned_since": None, "specifications_doc": "{}", "specifications_template": specifications_template_url, "tags": ["TMSS", "TESTING"], "producer": subtask_output_url, - "do_cancel": datetime.utcnow().isoformat(), + "do_cancel": None, "expected_size": 1234, "size": 123, "feedback_doc": "{}", @@ -472,7 +480,6 @@ class TMSSRESTTestDataCreator(): if dataproduct_urls is None: dataproduct_urls = [self.post_data_and_get_url(self.Dataproduct(), '/dataproduct/'), self.post_data_and_get_url(self.Dataproduct(), '/dataproduct/')] - if subtask_output_url is None: subtask_output_url = self.post_data_and_get_url(self.SubtaskOutput(), '/subtask_output/') -- GitLab