Exemplo n.º 1
0
 def test_migrate_from22to23(self):
     set_db_schema_version(self.db, 22)
     u = Tender(test_tender_data)
     u.tenderID = "UA-X"
     u.store(self.db)
     data = self.db.get(u.id)
     data["documents"] = [{
         "id":
         "ebcb5dd7f7384b0fbfbed2dc4252fa6e",
         "title":
         "name.txt",
         "documentOf":
         "tender",
         "url":
         "/tenders/{}/documents/ebcb5dd7f7384b0fbfbed2dc4252fa6e?download=10367238a2964ee18513f209d9b6d1d3"
         .format(u.id),
         "datePublished":
         "2016-06-01T00:00:00+03:00",
         "dateModified":
         "2016-06-01T00:00:00+03:00",
         "format":
         "text/plain",
     }]
     _id, _rev = self.db.save(data)
     self.app.app.registry.docservice_url = 'http://localhost'
     migrate_data(self.app.app.registry, 23)
     migrated_item = self.db.get(u.id)
     self.assertIn('http://localhost/get/10367238a2964ee18513f209d9b6d1d3?',
                   migrated_item['documents'][0]['url'])
     self.assertIn(
         'Prefix={}%2Febcb5dd7f7384b0fbfbed2dc4252fa6e'.format(u.id),
         migrated_item['documents'][0]['url'])
     self.assertIn('KeyID=', migrated_item['documents'][0]['url'])
     self.assertIn('Signature=', migrated_item['documents'][0]['url'])
    def test_simple_add_tender(self):
        u = Tender(test_tender_data)
        u.tenderID = "UA-X"

        assert u.id is None
        assert u.rev is None

        u.store(self.db)

        assert u.id is not None
        assert u.rev is not None

        fromdb = self.db.get(u.id)

        assert u.tenderID == fromdb['tenderID']
        assert u.doc_type == "Tender"

        u.delete_instance(self.db)
Exemplo n.º 3
0
    def test_simple_add_tender(self):
        u = Tender()
        u.tenderID = "UA-X"

        assert u.id is None
        assert u.rev is None

        u.store(self.db)

        assert u.id is not None
        assert u.rev is not None

        fromdb = self.db.get(u.id)

        assert u.tenderID == fromdb['tenderID']
        assert u.doc_type == "Tender"

        u.delete_instance(self.db)
Exemplo n.º 4
0
    def collection_post(self):
        """This API request is targeted to creating new Tenders by procuring organizations.

        Creating new Tender
        -------------------

        Example request to create tender:

        .. sourcecode:: http

            POST /tenders HTTP/1.1
            Host: example.com
            Accept: application/json

            {
                "data": {
                    "procuringEntity": {
                        "id": {
                            "name": "Державне управління справами",
                            "scheme": "https://ns.openprocurement.org/ua/edrpou",
                            "uid": "00037256",
                            "uri": "http://www.dus.gov.ua/"
                        },
                        "address": {
                            "countryName": "Україна",
                            "postalCode": "01220",
                            "region": "м. Київ",
                            "locality": "м. Київ",
                            "streetAddress": "вул. Банкова, 11, корпус 1"
                        }
                    },
                    "value": {
                        "amount": 500,
                        "currency": "UAH",
                        "valueAddedTaxIncluded": true
                    },
                    "itemsToBeProcured": [
                        {
                            "description": "футляри до державних нагород",
                            "primaryClassification": {
                                "scheme": "CPV",
                                "id": "44617100-9",
                                "description": "Cartons"
                            },
                            "additionalClassification": [
                                {
                                    "scheme": "ДКПП",
                                    "id": "17.21.1",
                                    "description": "папір і картон гофровані, паперова й картонна тара"
                                }
                            ],
                            "unitOfMeasure": "item",
                            "quantity": 5
                        }
                    ],
                    "enquiryPeriod": {
                        "endDate": "2014-10-31T00:00:00"
                    },
                    "tenderPeriod": {
                        "startDate": "2014-11-03T00:00:00",
                        "endDate": "2014-11-06T10:00:00"
                    },
                    "awardPeriod": {
                        "endDate": "2014-11-13T00:00:00"
                    },
                    "deliveryDate": {
                        "endDate": "2014-11-20T00:00:00"
                    },
                    "minimalStep": {
                        "amount": 35,
                        "currency": "UAH"
                    }
                }
            }

        This is what one should expect in response:

        .. sourcecode:: http

            HTTP/1.1 201 Created
            Location: http://localhost/api/0.1/tenders/64e93250be76435397e8c992ed4214d1
            Content-Type: application/json

            {
                "data": {
                    "id": "64e93250be76435397e8c992ed4214d1",
                    "tenderID": "UA-64e93250be76435397e8c992ed4214d1",
                    "dateModified": "2014-10-27T08:06:58.158Z",
                    "procuringEntity": {
                        "id": {
                            "name": "Державне управління справами",
                            "scheme": "https://ns.openprocurement.org/ua/edrpou",
                            "uid": "00037256",
                            "uri": "http://www.dus.gov.ua/"
                        },
                        "address": {
                            "countryName": "Україна",
                            "postalCode": "01220",
                            "region": "м. Київ",
                            "locality": "м. Київ",
                            "streetAddress": "вул. Банкова, 11, корпус 1"
                        }
                    },
                    "value": {
                        "amount": 500,
                        "currency": "UAH",
                        "valueAddedTaxIncluded": true
                    },
                    "itemsToBeProcured": [
                        {
                            "description": "футляри до державних нагород",
                            "primaryClassification": {
                                "scheme": "CPV",
                                "id": "44617100-9",
                                "description": "Cartons"
                            },
                            "additionalClassification": [
                                {
                                    "scheme": "ДКПП",
                                    "id": "17.21.1",
                                    "description": "папір і картон гофровані, паперова й картонна тара"
                                }
                            ],
                            "unitOfMeasure": "item",
                            "quantity": 5
                        }
                    ],
                    "enquiryPeriod": {
                        "endDate": "2014-10-31T00:00:00"
                    },
                    "tenderPeriod": {
                        "startDate": "2014-11-03T00:00:00",
                        "endDate": "2014-11-06T10:00:00"
                    },
                    "awardPeriod": {
                        "endDate": "2014-11-13T00:00:00"
                    },
                    "deliveryDate": {
                        "endDate": "2014-11-20T00:00:00"
                    },
                    "minimalStep": {
                        "amount": 35,
                        "currency": "UAH"
                    }
                }
            }

        """
        tender_data = self.request.validated['data']
        tender_id = generate_id()
        tender = Tender(tender_data)
        tender.id = tender_id
        tender.enquiryPeriod.startDate = get_now()
        tender.tenderID = generate_tender_id(tender.enquiryPeriod.startDate, self.db)
        if not tender.tenderPeriod.startDate:
            tender.tenderPeriod.startDate = tender.enquiryPeriod.endDate
        set_ownership(tender, self.request)
        self.request.validated['tender'] = tender
        self.request.validated['tender_src'] = {}
        save_tender(self.request)
        self.request.response.status = 201
        self.request.response.headers[
            'Location'] = self.request.route_url('Tender', tender_id=tender_id)
        return {
            'data': tender.serialize(tender.status),
            'access': {
                'token': tender.owner_token
            }
        }
Exemplo n.º 5
0
    def test_migrate_from23to24(self):
        set_db_schema_version(self.db, 23)
        self.app.app.registry.docservice_url = 'http://localhost.ds'
        u = Tender(test_tender_data)
        u.tenderID = "UA-X"
        u.dateModified = get_now().isoformat()
        u.store(self.db)
        tender_raw = self.db.get(u.id)
        date_modified_before = tender_raw['dateModified']
        bid = {"id": "1b4da15470e84c4d948a5d1660d29776"}
        bid["documents"] = [
            {
                # non-ds url. should be fixed (correct id in url) by migrator
                "id":
                "1801ca2749bd40b0944e58adc3e09c46",
                "title":
                "name.txt",
                "documentOf":
                "tender",
                "url":
                "/tenders/{}/bids/{}/documents/63073ea0da17414db9f13e1a8c347e11?download=a65ef5c688884931aed1a472620d3a00"
                .format(u.id, bid['id']),
                "datePublished":
                "2016-06-01T00:00:00+03:00",
                "dateModified":
                "2016-06-01T00:00:00+03:00",
                "format":
                "text/plain",
                "language":
                "uk",
            },
            {
                # non-ds url. should be fixed (correct id in url) by migrator
                "id":
                "f3e5470b76f84c66a89fd52ed871f645",
                "title":
                "name.txt",
                "documentOf":
                "tender",
                "url":
                "/tenders/{}/bids/{}/documents/512bd84155b145b99e0ac80894fe2b8f?download=d48723d7b4014599ac8d94fb0ac958b4"
                .format(u.id, bid['id']),
                "datePublished":
                "2016-06-01T00:00:00+03:00",
                "dateModified":
                "2016-06-01T00:00:00+03:00",
                "format":
                "text/plain",
            },
            {
                # ds url. should NOT be rewrited by migrator
                "id": "352d774608d749c996fc0e798ffef433",
                "title": "name.txt",
                "documentOf": "tender",
                "url":
                "http://localhost.ds/get/b893bf5d2fb44a26bd6896178afe5953?KeyID=i_am_ds_url_lalalalala",  # DS url
                "datePublished": "2016-06-01T00:00:00+03:00",
                "dateModified": "2016-06-01T00:00:00+03:00",
                "format": "text/plain",
            }
        ]

        # dirty eligibility documents container simulation
        bid["eligibilityDocuments"] = [{
            # non-ds url. should be fixed (correct id in url) by migrator
            "id":
            "73e728784f924518b07f16e34750df1b",
            "title":
            "name.txt",
            "documentOf":
            "tender",
            "url":
            "/tenders/{}/bids/{}/eligibility_documents/a109ca6b04d24bd5bccf57917a65e835?download=5443af5e910f46debe412fc36e69f1ad"
            .format(u.id, bid['id']),
            "datePublished":
            "2016-06-01T00:00:00+03:00",
            "dateModified":
            "2016-06-01T00:00:00+03:00",
            "format":
            "text/plain",
            "language":
            "uk",
            "confidentiality":
            "buyerOnly"  # documents for which url is not rewrited to ds url
        }]

        tender_raw['bids'] = [
            bid,
        ]

        _id, _rev = self.db.save(tender_raw)

        migrate_data(self.app.app.registry, 24)
        migrated = self.db.get(u.id)
        migrated_bid = migrated['bids'][0]

        self.assertGreater(migrated['dateModified'], date_modified_before)

        # url should be corrected
        self.assertIn(
            "/tenders/{}/bids/1b4da15470e84c4d948a5d1660d29776/documents/1801ca2749bd40b0944e58adc3e09c46?download=a65ef5c688884931aed1a472620d3a00"
            .format(u.id), migrated_bid['documents'][0]['url'])
        self.assertIn(
            "/tenders/{}/bids/1b4da15470e84c4d948a5d1660d29776/documents/f3e5470b76f84c66a89fd52ed871f645?download=d48723d7b4014599ac8d94fb0ac958b4"
            .format(u.id), migrated_bid['documents'][1]['url'])
        self.assertIn(
            "/tenders/{}/bids/1b4da15470e84c4d948a5d1660d29776/eligibility_documents/73e728784f924518b07f16e34750df1b?download=5443af5e910f46debe412fc36e69f1ad"
            .format(u.id), migrated_bid['eligibilityDocuments'][0]['url'])

        # url remained the same as before migration
        self.assertIn(
            "http://localhost.ds/get/b893bf5d2fb44a26bd6896178afe5953?KeyID=i_am_ds_url_lalalalala",
            migrated_bid['documents'][2]['url'])
Exemplo n.º 6
0
    def collection_post(self):
        """This API request is targeted to creating new Tenders by procuring organizations.

        Creating new Tender
        -------------------

        Example request to create tender:

        .. sourcecode:: http

            POST /tenders HTTP/1.1
            Host: example.com
            Accept: application/json

            {
                "data": {
                    "procuringEntity": {
                        "id": {
                            "name": "Державне управління справами",
                            "scheme": "https://ns.openprocurement.org/ua/edrpou",
                            "uid": "00037256",
                            "uri": "http://www.dus.gov.ua/"
                        },
                        "address": {
                            "countryName": "Україна",
                            "postalCode": "01220",
                            "region": "м. Київ",
                            "locality": "м. Київ",
                            "streetAddress": "вул. Банкова, 11, корпус 1"
                        }
                    },
                    "value": {
                        "amount": 500,
                        "currency": "UAH",
                        "valueAddedTaxIncluded": true
                    },
                    "itemsToBeProcured": [
                        {
                            "description": "футляри до державних нагород",
                            "primaryClassification": {
                                "scheme": "CPV",
                                "id": "44617100-9",
                                "description": "Cartons"
                            },
                            "additionalClassification": [
                                {
                                    "scheme": "ДКПП",
                                    "id": "17.21.1",
                                    "description": "папір і картон гофровані, паперова й картонна тара"
                                }
                            ],
                            "unitOfMeasure": "item",
                            "quantity": 5
                        }
                    ],
                    "enquiryPeriod": {
                        "endDate": "2014-10-31T00:00:00"
                    },
                    "tenderPeriod": {
                        "startDate": "2014-11-03T00:00:00",
                        "endDate": "2014-11-06T10:00:00"
                    },
                    "awardPeriod": {
                        "endDate": "2014-11-13T00:00:00"
                    },
                    "deliveryDate": {
                        "endDate": "2014-11-20T00:00:00"
                    },
                    "minimalStep": {
                        "amount": 35,
                        "currency": "UAH"
                    }
                }
            }

        This is what one should expect in response:

        .. sourcecode:: http

            HTTP/1.1 201 Created
            Location: http://localhost/api/0.1/tenders/64e93250be76435397e8c992ed4214d1
            Content-Type: application/json

            {
                "data": {
                    "id": "64e93250be76435397e8c992ed4214d1",
                    "tenderID": "UA-64e93250be76435397e8c992ed4214d1",
                    "dateModified": "2014-10-27T08:06:58.158Z",
                    "procuringEntity": {
                        "id": {
                            "name": "Державне управління справами",
                            "scheme": "https://ns.openprocurement.org/ua/edrpou",
                            "uid": "00037256",
                            "uri": "http://www.dus.gov.ua/"
                        },
                        "address": {
                            "countryName": "Україна",
                            "postalCode": "01220",
                            "region": "м. Київ",
                            "locality": "м. Київ",
                            "streetAddress": "вул. Банкова, 11, корпус 1"
                        }
                    },
                    "value": {
                        "amount": 500,
                        "currency": "UAH",
                        "valueAddedTaxIncluded": true
                    },
                    "itemsToBeProcured": [
                        {
                            "description": "футляри до державних нагород",
                            "primaryClassification": {
                                "scheme": "CPV",
                                "id": "44617100-9",
                                "description": "Cartons"
                            },
                            "additionalClassification": [
                                {
                                    "scheme": "ДКПП",
                                    "id": "17.21.1",
                                    "description": "папір і картон гофровані, паперова й картонна тара"
                                }
                            ],
                            "unitOfMeasure": "item",
                            "quantity": 5
                        }
                    ],
                    "enquiryPeriod": {
                        "endDate": "2014-10-31T00:00:00"
                    },
                    "tenderPeriod": {
                        "startDate": "2014-11-03T00:00:00",
                        "endDate": "2014-11-06T10:00:00"
                    },
                    "awardPeriod": {
                        "endDate": "2014-11-13T00:00:00"
                    },
                    "deliveryDate": {
                        "endDate": "2014-11-20T00:00:00"
                    },
                    "minimalStep": {
                        "amount": 35,
                        "currency": "UAH"
                    }
                }
            }

        """
        tender_data = self.request.validated['data']
        tender_id = generate_id()
        tender = Tender(tender_data)
        tender.id = tender_id
        if not tender.enquiryPeriod.startDate:
            tender.enquiryPeriod.startDate = get_now()
        tender.tenderID = generate_tender_id(tender.enquiryPeriod.startDate,
                                             self.db)
        if not tender.tenderPeriod.startDate:
            tender.tenderPeriod.startDate = tender.enquiryPeriod.endDate
        set_ownership(tender, self.request)
        self.request.validated['tender'] = tender
        self.request.validated['tender_src'] = {}
        if save_tender(self.request):
            update_journal_handler_params({
                'tender_id': tender_id,
                'tenderID': tender.tenderID
            })
            LOGGER.info('Created tender {} ({})'.format(
                tender_id, tender.tenderID),
                        extra={'MESSAGE_ID': 'tender_create'})
            self.request.response.status = 201
            self.request.response.headers['Location'] = self.request.route_url(
                'Tender', tender_id=tender_id)
            return {
                'data': tender.serialize(tender.status),
                'access': {
                    'token': tender.owner_token
                }
            }