def save_monitoring(request, date_modified=None, update_context_date=False):
    monitoring = request.validated['monitoring']
    patch = get_revision_changes(request.validated['monitoring_src'],
                                 monitoring.serialize('plain'))
    if patch:
        add_revision(request, monitoring, patch)

        old_date_modified = monitoring.dateModified
        now = date_modified or get_now()
        monitoring.dateModified = now
        if update_context_date and "dateModified" in request.context:
            request.context.dateModified = now
        try:
            monitoring.store(request.registry.db)
        except ModelValidationError as e:  # pragma: no cover
            for i in e.messages:
                request.errors.add('body', i, e.messages[i])
            request.errors.status = 422
        except Exception as e:  # pragma: no cover
            request.errors.add('body', 'data', str(e))
        else:
            LOGGER.info('Saved monitoring {}: dateModified {} -> {}'.format(
                monitoring.id, old_date_modified
                and old_date_modified.isoformat(),
                monitoring.dateModified.isoformat()),
                        extra=context_unpack(
                            request, {'MESSAGE_ID': 'save_monitoring'}))
            return True
示例#2
0
def save_inspection(request, date_modified=None):
    inspection = request.validated['inspection']
    patch = get_revision_changes(request.validated['inspection_src'],
                                 inspection.serialize("plain"))
    if patch:
        add_revision(request, inspection, patch)

        old_date_modified = inspection.dateModified
        inspection.dateModified = date_modified or get_now()
        try:
            inspection.store(request.registry.db)
        except ModelValidationError as e:  # pragma: no cover
            for i in e.messages:
                request.errors.add('body', i, e.messages[i])
            request.errors.status = 422
        except Exception as e:  # pragma: no cover
            request.errors.add('body', 'data', str(e))
        else:
            LOGGER.info('Saved inspection {}: dateModified {} -> {}'.format(
                inspection.id, old_date_modified
                and old_date_modified.isoformat(),
                inspection.dateModified.isoformat()),
                        extra=context_unpack(
                            request, {'MESSAGE_ID': 'save_inspection'}))
            return True
示例#3
0
    def create_active_monitoring(self, **kwargs):
        self.create_monitoring(**kwargs)
        self.app.authorization = ('Basic', (self.sas_name, self.sas_pass))

        self.app.patch_json(
            '/monitorings/{}'.format(self.monitoring_id), {
                "data": {
                    "decision": {
                        "description": "text",
                        "date": get_now().isoformat()
                    },
                    "status": "active",
                }
            })

        # get credentials for tha monitoring owner
        self.app.authorization = ('Basic', (self.broker_name,
                                            self.broker_pass))
        with mock.patch(
                'openprocurement.audit.monitoring.validation.TendersClient'
        ) as mock_api_client:
            mock_api_client.return_value.extract_credentials.return_value = {
                'data': {
                    'tender_token': sha512(b'tender_token').hexdigest()
                }
            }
            response = self.app.patch_json(
                '/monitorings/{}/credentials?acc_token={}'.format(
                    self.monitoring_id, 'tender_token'))
        self.tender_owner_token = response.json['access']['token']
示例#4
0
def save_request(request, date_modified=None):
    obj = request.validated["request"]
    patch = get_revision_changes(
        request.validated["request_src"], obj.serialize("plain")
    )
    if patch:
        add_revision(request, obj, patch)

        old_date_modified = obj.dateModified
        obj.dateModified = date_modified or get_now()
        try:
            obj.store(request.registry.db)
        except ModelValidationError as e:  # pragma: no cover
            for i in e.messages:
                request.errors.add("body", i, e.messages[i])
            request.errors.status = 422
        except Exception as e:  # pragma: no cover
            request.errors.add("body", "data", str(e))
        else:
            LOGGER.info(
                "Saved request {}: dateModified {} -> {}".format(
                    obj.id,
                    old_date_modified and old_date_modified.isoformat(),
                    obj.dateModified.isoformat(),
                ),
                extra=context_unpack(request, {"MESSAGE_ID": "save_request"}),
            )
            return True
def _validate_patch_monitoring_status_addressed_to_completed(request):
    monitoring = request.validated['monitoring']
    if not get_now() > monitoring.eliminationPeriod.endDate:
        raise_operation_error(
            request,
            'Can\'t change status to completed before elimination period ends.'
        )
    if not request.validated.get('data', {}).get('eliminationResolution'):
        request.errors.status = 422
        request.errors.add('body', 'eliminationResolution',
                           'This field is required.')
示例#6
0
    def test_success_update_appeal(self):
        self.app.authorization = ('Basic', (self.broker_name,
                                            self.broker_pass))
        response = self.app.patch_json(
            '/monitorings/{}/appeal?acc_token={}'.format(
                self.monitoring_id, self.tender_owner_token), {
                    'data': {
                        'proceeding': {
                            'dateProceedings': get_now().isoformat(),
                            'proceedingNumber': 'somenumber',
                        }
                    }
                })
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content_type, 'application/json')
        self.assertIn("proceeding", response.json["data"])
        proceeding = response.json["data"]["proceeding"]
        self.assertEqual(proceeding["proceedingNumber"], "somenumber")

        response = self.app.patch_json(
            '/monitorings/{}/appeal?acc_token={}'.format(
                self.monitoring_id, self.tender_owner_token), {
                    "data": {
                        "proceeding": {
                            "dateProceedings": get_now().isoformat(),
                            "proceedingNumber": "somenumber",
                        }
                    }
                },
            status=403)
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(response.json["errors"],
                         [{
                             "location": "body",
                             "name": "data",
                             "description": "Can't post another proceeding."
                         }])
def validate_posting_elimination_resolution(request):
    monitoring = request.validated['monitoring']
    monitoring.eliminationResolution.datePublished = monitoring.eliminationResolution.dateCreated
    if not monitoring.eliminationReport:
        accelerator = get_monitoring_accelerator(request.context)
        allow_post_since = calculate_normalized_business_date(
            monitoring.conclusion.datePublished, RESOLUTION_WAIT_PERIOD,
            accelerator)
        if get_now() < allow_post_since:
            raise_operation_error(
                request,
                "Can't post eliminationResolution without eliminationReport "
                "earlier than {} business days since conclusion.datePublished".
                format(RESOLUTION_WAIT_PERIOD.days))
 def patch(self):
     obj = self.request.validated["request"]
     now = get_now()
     if obj.answer is not None:
         raise forbidden(self.request)
     apply_patch(self.request, src=self.request.validated["request_src"], save=False)
     if obj.answer:
         obj.dateAnswered = now
     save_request(self.request, date_modified=now)
     LOGGER.info(
         "Updated request {}".format(obj.id),
         extra=context_unpack(self.request, {"MESSAGE_ID": "request_patch"}),
     )
     return {"data": request_serialize_view(obj, self.request.authenticated_role)}
 def post(self):
     inspection = self.request.validated['inspection']
     inspection.id = generate_id()
     inspection.inspection_id = generate_inspection_id(
         get_now(), self.db, self.server_id)
     set_author(inspection.documents, self.request, 'author')
     save_inspection(self.request, date_modified=inspection.dateCreated)
     LOGGER.info('Created inspection {}'.format(inspection.id),
                 extra=context_unpack(self.request,
                                      {'MESSAGE_ID': 'inspection_create'},
                                      {'MONITORING_ID': inspection.id}))
     self.request.response.status = 201
     self.request.response.headers['Location'] = self.request.route_url(
         'Inspection', inspection_id=inspection.id)
     return {'data': inspection.serialize('view')}
示例#10
0
def save_inspection(request, date_modified=None):
    inspection = request.validated['inspection']
    patch = get_revision_changes(request.validated['inspection_src'], inspection.serialize("plain"))
    if patch:
        add_revision(request, inspection, patch)

        old_date_modified = inspection.dateModified
        inspection.dateModified = date_modified or get_now()
        try:
            inspection.store(request.registry.db)
        except ModelValidationError, e:  # pragma: no cover
            for i in e.message:
                request.errors.add('body', i, e.message[i])
            request.errors.status = 422
        except Exception, e:  # pragma: no cover
            request.errors.add('body', 'data', str(e))
示例#11
0
def save_monitoring(request, date_modified=None):
    monitoring = request.validated['monitoring']
    patch = get_revision_changes(request.validated['monitoring_src'],
                                 monitoring.serialize('plain'))
    if patch:
        add_revision(request, monitoring, patch)

        old_date_modified = monitoring.dateModified
        monitoring.dateModified = date_modified or get_now()
        try:
            monitoring.store(request.registry.db)
        except ModelValidationError, e:  # pragma: no cover
            for i in e.message:
                request.errors.add('body', i, e.message[i])
            request.errors.status = 422
        except Exception, e:  # pragma: no cover
            request.errors.add('body', 'data', str(e))
 def post(self):
     obj = self.request.validated["request"]
     obj.id = generate_id()
     obj.requestId = generate_request_id(get_now(), self.db, self.server_id)
     set_author(obj.documents, self.request, "author")
     upload_objects_documents(self.request, obj)
     save_request(self.request, date_modified=obj.dateCreated)
     LOGGER.info(
         "Created request {}".format(obj.id),
         extra=context_unpack(
             self.request,
             {"MESSAGE_ID": "request_create"},
             {"MONITORING_ID": obj.id},
         ),
     )
     self.request.response.status = 201
     self.request.response.headers["Location"] = self.request.route_url(
         "Request", request_id=obj.id
     )
     return {"data": request_serialize_view(obj, self.request.authenticated_role)}
示例#13
0
 def collection_post(self):
     """
     Post a post
     """
     monitoring = self.context
     post = self.request.validated['post']
     set_author(post, self.request, 'author')
     set_author(post.documents, self.request, 'author')
     upload_objects_documents(self.request, post)
     if post.author == get_monitoring_role('sas') and post.relatedPost is None:
         accelerator = get_monitoring_accelerator(self.context)
         post.dateOverdue = calculate_normalized_business_date(get_now(), POST_OVERDUE_TIME, accelerator)
     if monitoring.status in (ADDRESSED_STATUS, DECLINED_STATUS):
         post.postOf = CONCLUSION_OBJECT_TYPE
     monitoring.posts.append(post)
     if save_monitoring(self.request):
         self.LOGGER.info('Created monitoring post {}'.format(post.id),
                          extra=context_unpack(self.request,
                                               {'MESSAGE_ID': 'monitoring_post_create'},
                                               {'POST_ID': post.id}))
         self.request.response.status = 201
         self.request.response.headers['Location'] = self.request.route_url(
             'Monitoring Post', monitoring_id=monitoring.id, post_id=post.id)
         return {'data': post.serialize('view')}
示例#14
0
    def test_fail_patch_appeal_before_added(self):
        self.post_conclusion(publish=False)

        self.app.authorization = ('Basic', (self.broker_name,
                                            self.broker_pass))
        response = self.app.patch_json(
            '/monitorings/{}/appeal?acc_token={}'.format(
                self.monitoring_id, self.tender_owner_token), {
                    "data": {
                        "proceeding": {
                            "dateProceedings": get_now().isoformat(),
                            "proceedingNumber": "somenumber",
                        }
                    }
                },
            status=404)

        self.assertEqual(response.status_code, 404)
        self.assertEqual(response.json["errors"],
                         [{
                             'location': 'body',
                             'name': 'data',
                             'description': 'Appeal not found'
                         }])
def _validate_patch_monitoring_status_declined_to_closed(request):
    monitoring = request.validated['monitoring']
    if not get_now() > monitoring.eliminationPeriod.endDate:
        raise_operation_error(
            request,
            'Can\'t change status to closed before elimination period ends.')