def test_save_framework(self): request = MagicMock(authenticated_userid="user_uuid") framework = MagicMock() framework.mode = "test" framework.revisions = [] framework.dateModified = datetime.datetime(2018, 8, 2, 12, 9, 2, 440566) framework.rev = "12341234" request.validated = { "framework": framework, "framework_src": "src_test" } res = save_framework(request) self.assertTrue(res)
def patch(self): """Framework Edit (partial) .. sourcecode:: http PATCH /frameworks/40b48e4878534db1bf228d5928f8f1d9?acc_token=7c6a46e300bb41438ef626232028950b HTTP/1.1 Host: example.com Accept: application/json { "data": { "qualificationPeriod": { "endDate": "2021-02-22T14:33:22.129267+02:00" }, "procuringEntity": { "contactPoint": { "email": "*****@*****.**", "name": "зміна", "telephone": "0440000002" } }, "description": "Назва предмета закупівлі1" } } And here is the response to be expected: .. sourcecode:: http HTTP/1.0 200 OK Content-Type: application/json { "data": { "status": "active", "description": "Назва предмета закупівлі1", "classification": { "scheme": "ДК021", "description": "Mustard seeds", "id": "03111600-8" }, "title": "updated in draft status", "enquiryPeriod": { "startDate": "2020-09-08T01:00:00+03:00", "endDate": "2020-09-23T00:00:00+03:00" }, "qualificationPeriod": { "startDate": "2020-09-23T00:00:00+03:00", "endDate": "2021-02-22T14:33:22.129267+02:00" }, "prettyID": "UA-F-2020-09-08-000001", "period": { "startDate": "2020-09-08T01:00:00+03:00", "endDate": "2021-01-23T00:00:00+02:00" }, "frameworkType": "electronicCatalogue", "date": "2020-09-08T01:00:00+03:00", "additionalClassifications": [ { "scheme": "ДК003", "id": "17.21.1", "description": "папір і картон гофровані, паперова й картонна тара" } ], "next_check": "2020-10-07T00:00:00+03:00", "procuringEntity": { "contactPoint": { "email": "*****@*****.**", "telephone": "0440000002", "name": "зміна" }, "identifier": { "scheme": "UA-EDR", "id": "40996564", "legalName": "Назва організації(ЦЗО)" }, "name": "Повна назва юридичної організації.", "kind": "central", "address": { "countryName": "Україна", "postalCode": "01220", "streetAddress": "вул. Банкова, 11, корпус 1", "region": "м. Київ", "locality": "м. Київ" } }, "owner": "broker", "dateModified": "2020-09-08T01:00:00+03:00", "id": "40b48e4878534db1bf228d5928f8f1d9" } } """ framework = self.context if self.request.authenticated_role == "chronograph": check_status(self.request) save_framework(self.request) else: if self.request.validated["data"].get("status") not in ("draft", "active"): raise_operation_error( self.request, "Can't switch to {} status".format( self.request.validated["data"].get("status"))) if self.request.validated["data"].get("status") == "active": model = self.request.context._fields["qualificationPeriod"] calculate_framework_periods(self.request, model) validate_qualification_period_duration(self.request, model) apply_patch(self.request, src=self.request.validated["framework_src"], obj_name="framework") self.LOGGER.info("Updated framework {}".format(framework.id), extra=context_unpack( self.request, {"MESSAGE_ID": "framework_patch"})) # TODO: Change to chronograph_view for chronograph return {"data": framework.serialize(framework.status)}
def post(self): """This API request is targeted to creating new Frameworks by procuring organizations. Creating new Framework ------------------- Example request to create framework: .. sourcecode:: http POST /frameworks HTTP/1.1 Host: example.com Accept: application/json { "data": { "description": "Назва предмета закупівлі", "classification": { "scheme": "ДК021", "description": "Mustard seeds", "id": "03111600-8" }, "title": "Узагальнена назва закупівлі", "qualificationPeriod": { "endDate": "2021-02-07T14:33:22.129267+02:00" }, "additionalClassifications": [ { "scheme": "ДК003", "id": "17.21.1", "description": "папір і картон гофровані, паперова й картонна тара" } ], "procuringEntity": { "contactPoint": { "telephone": "0440000000", "email": "*****@*****.**", "name": "Назва організації(ЦЗО)" }, "identifier": { "scheme": "UA-EDR", "id": "40996564", "legalName": "Назва організації(ЦЗО)" }, "kind": "central", "name": "Повна назва юридичної організації.", "address": { "countryName": "Україна", "postalCode": "01220", "region": "м. Київ", "streetAddress": "вул. Банкова, 11, корпус 1", "locality": "м. Київ" } } } } This is what one should expect in response: .. sourcecode:: http HTTP/1.1 201 Created Location: http://localhost/api/0.1/frameworks/40b48e4878534db1bf228d5928f8f1d9 Content-Type: application/json { "data": { "status": "draft", "description": "Назва предмета закупівлі", "classification": { "scheme": "ДК021", "description": "Mustard seeds", "id": "03111600-8" }, "prettyID": "UA-F-2020-09-08-000001", "qualificationPeriod": { "endDate": "2021-02-07T14:33:22.129267+02:00" }, "frameworkType": "electronicCatalogue", "dateModified": "2020-09-08T01:00:00+03:00", "date": "2020-09-08T01:00:00+03:00", "additionalClassifications": [ { "scheme": "ДК003", "id": "17.21.1", "description": "папір і картон гофровані, паперова й картонна тара" } ], "procuringEntity": { "contactPoint": { "email": "*****@*****.**", "telephone": "0440000000", "name": "Назва організації(ЦЗО)" }, "identifier": { "scheme": "UA-EDR", "id": "40996564", "legalName": "Назва організації(ЦЗО)" }, "name": "Повна назва юридичної організації.", "kind": "central", "address": { "countryName": "Україна", "postalCode": "01220", "streetAddress": "вул. Банкова, 11, корпус 1", "region": "м. Київ", "locality": "м. Київ" } }, "owner": "broker", "title": "Узагальнена назва закупівлі", "id": "40b48e4878534db1bf228d5928f8f1d9" } } """ framework_id = generate_id() framework = self.request.validated["framework"] framework.id = framework_id if not framework.get("prettyID"): framework.prettyID = generate_framework_pretty_id( get_now(), self.db, self.server_id) access = set_ownership(framework, self.request) self.request.validated["framework"] = framework self.request.validated["framework_src"] = {} if save_framework(self.request): self.LOGGER.info( "Created framework {} ({})".format(framework_id, framework.prettyID), extra=context_unpack( self.request, {"MESSAGE_ID": "framework_create"}, { "framework_id": framework_id, "prettyID": framework.prettyID, "framework_mode": framework.mode }, ), ) self.request.response.status = 201 self.request.response.headers["Location"] = self.request.route_url( "{}:Framework".format(framework.frameworkType), framework_id=framework_id) return { "data": framework.serialize(framework.status), "access": access }
def save(self, request, **kwargs): return save_framework(request)