def get_milestone(test_case, contract_id, milestone_id):
    response = test_case.app.get(ENDPOINTS['milestones'].format(
        contract_id=contract_id,
        milestone_id=milestone_id
        )
    )
    test_case.assertEqual(response.status, '200 OK', 'Cannot get milestone')
    return Milestone(response.json['data'])
Exemplo n.º 2
0
    def populate_milestones(self, contract):
        """Create group of ceasefire milestones

        :param contract: contract, related to milestone
        :type contract: openprocurement.contracting.ceasefire.models.Contract
        """
        financing = Milestone({
            'type': 'financing',
            'status': 'processing',
        })
        approval = Milestone({
            'type': 'approval',
            'status': 'scheduled',
        })
        reporting = Milestone({
            'type': 'reporting',
            'status': 'scheduled',
        })
        self.set_dueDate(financing, contract)
        return [financing, approval, reporting]
Exemplo n.º 3
0
 def test_patch_met_to_notMet(self):
     contract, milestones = prepare_milestones_approval(self)
     financing_milestone = Milestone(milestones[0])
     assert financing_milestone.type_ == 'financing'
     assert financing_milestone.status == 'met'
     patch_milestone(self,
                     contract,
                     financing_milestone.id, {'data': {
                         'status': 'notMet'
                     }},
                     status=403)
Exemplo n.º 4
0
    def test_patch_financing_milestone_without_document(self):
        contract, milestones = prepare_milestones(self, doc_preload=False)
        financing_milestone = Milestone(milestones[0])
        assert financing_milestone.type_ == 'financing'
        dateMet_to_set = financing_milestone.dueDate - timedelta(days=5)

        patch_milestone(self,
                        contract,
                        financing_milestone.id,
                        {'data': {
                            'dateMet': dateMet_to_set.isoformat()
                        }},
                        status=200)
Exemplo n.º 5
0
    def test_milestone_patch_financing_wrong_dateMet(self):
        contract, milestones = prepare_milestones(self)
        financing_milestone = Milestone(milestones[0])
        assert financing_milestone.type_ == 'financing'
        dateMet_to_set = financing_milestone.dueDate - timedelta(days=500)

        patch_milestone(self,
                        contract,
                        financing_milestone.id,
                        {'data': {
                            'dateMet': dateMet_to_set.isoformat()
                        }},
                        status=422)
Exemplo n.º 6
0
    def test_update_dateModified_forbidden(self):
        contract, milestones = prepare_milestones_approval(self)
        reporting_milestone = Milestone(milestones[2])
        assert reporting_milestone.type_ == 'reporting'
        old_dateModified = reporting_milestone.dateModified

        patch_milestone(self,
                        contract,
                        reporting_milestone.id,
                        {'data': {
                            'type_': '937-99-92'
                        }},
                        status=422)
        patched_milestone = get_milestone(self, contract.data.id,
                                          reporting_milestone.id)
        assert old_dateModified == patched_milestone.dateModified, 'dateModified must not be updated'
Exemplo n.º 7
0
    def test_patch_description(self):
        contract, milestones = prepare_milestones_approval(self)
        reporting_milestone = Milestone(milestones[2])
        assert reporting_milestone.type_ == 'reporting'

        patch_milestone(
            self,
            contract,
            reporting_milestone.id,
            {'data': {
                'description': '937-99-92'
            }},
        )
        patched_milestone = get_milestone(self, contract.data.id,
                                          reporting_milestone.id)
        self.assertEqual(patched_milestone.description, '937-99-92')
Exemplo n.º 8
0
    def test_patch_status(self):
        contract, milestones = prepare_milestones_approval(self)
        reporting_milestone = Milestone(milestones[2])
        assert reporting_milestone.type_ == 'reporting'

        patch_milestone(
            self,
            contract,
            reporting_milestone.id,
            {'data': {
                'status': 'met'
            }},
        )
        patched_milestone = get_milestone(self, contract.data.id,
                                          reporting_milestone.id)
        self.assertEqual(patched_milestone.status, 'scheduled')
Exemplo n.º 9
0
def prepare_milestones_approval(test_case, contract_data=None):
    """Prepares contract's milestones to make financing milestone have processing status
    """
    contract, milestones = prepare_milestones(test_case, contract_data)
    financing_milestone = Milestone(milestones[0])
    assert financing_milestone.type_ == 'financing'
    dateMet_to_set = financing_milestone.dueDate - timedelta(days=5)

    response = patch_milestone(
        test_case, contract, financing_milestone.id,
        {'data': {
            'dateMet': dateMet_to_set.isoformat()
        }})
    test_case.assertEqual(response.status, '200 OK')
    resp = get_contract(test_case, contract.data.id)
    contract.data.update(resp)
    return (contract, contract.data.milestones)
Exemplo n.º 10
0
    def test_update_dateModified(self):
        contract, milestones = prepare_milestones_approval(self)
        reporting_milestone = Milestone(milestones[2])
        assert reporting_milestone.type_ == 'reporting'
        old_dateModified = reporting_milestone.dateModified

        patch_milestone(
            self,
            contract,
            reporting_milestone['id'],
            {'data': {
                'description': '937-99-92'
            }},
        )
        patched_milestone = get_milestone(self, contract.data.id,
                                          reporting_milestone.id)
        assert old_dateModified != patched_milestone.dateModified, 'dateModified must be updated'
Exemplo n.º 11
0
    def test_patch_notMet(self):
        contract, milestones = prepare_milestones(self)
        financing_milestone = Milestone(milestones[0])
        assert financing_milestone.type_ == 'financing'

        response = patch_milestone(
            self,
            contract,
            financing_milestone.id,
            {'data': {
                'status': 'notMet'
            }},
        )

        self.assertEqual(response.status, '200 OK')
        related_contract = get_contract(self, contract.data.id)
        self.assertEqual(related_contract.status, 'pending.unsuccessful')
Exemplo n.º 12
0
def prepare_milestones_approval(test_case, contract_data=None):
    """Prepares contract's milestones to make financing milestone have processing status
    """
    contract, milestones = prepare_milestones(test_case, contract_data)
    financing_milestone = Milestone(milestones[0])
    assert financing_milestone.type_ == 'financing'
    dateMet_to_set = financing_milestone.dueDate - timedelta(days=5)

    response = test_case.app.patch_json(
        ENDPOINTS['milestones'].format(
            contract_id=contract.data.id,
            milestone_id=milestones[0]['id'],
        ) + "?acc_token={}".format(contract.access.token),
        {'data': {
            'dateMet': dateMet_to_set.isoformat()
        }})
    test_case.assertEqual(response.status, '200 OK')
    resp = get_contract(test_case, contract.data.id)
    contract.data.update(resp)
    return (contract, contract.data.milestones)
Exemplo n.º 13
0
    def test_milestone_patch_attrs(self):
        contract, milestones = prepare_milestones(self)
        financing_milestone = Milestone(milestones[0])
        assert financing_milestone.type_ == 'financing'
        attrs = (
            'description_en',
            'description_ru',
            'title_en',
            'title_ru',
        )

        for attr in attrs:
            target_attr = uuid4().hex[:7]  # generate unique attr value
            patch_milestone(self, contract, financing_milestone.id,
                            {'data': {
                                attr: target_attr
                            }})

            patched_financing_milestone = get_milestone(
                self, contract.data.id, financing_milestone.id)
            assert getattr(patched_financing_milestone, attr) == target_attr
Exemplo n.º 14
0
    def test_upload_documents_with_milestone_related_types(self):
        contract, milestones = prepare_milestones_approval(self)
        reporting_milestone = Milestone(milestones[2])
        assert reporting_milestone.type_ == 'reporting'
        protocol_types = ('approvalProtocol', 'rejectionProtocol')

        for protocol_type in protocol_types:
            doc_id = post_milestone_document(
                self,
                contract,
                reporting_milestone.id,
                documentType=protocol_type).json['data']['id']

            contract_after_post = get_contract(self, contract.data.id)

            found_doc = None
            for doc in contract_after_post.documents:
                if doc.id == doc_id:
                    found_doc = doc
            assert found_doc, 'document was not attached to the contract'
            assert found_doc.documentType == protocol_type
Exemplo n.º 15
0
    def test_milestone_patch_approval_dateMet(self):
        contract, milestones = prepare_milestones_approval(self)
        approval_milestone = Milestone(milestones[1])
        assert approval_milestone.type_ == 'approval'
        dateMet_to_set = approval_milestone.dueDate - timedelta(days=5)

        response = patch_milestone(
            self, contract, approval_milestone.id,
            {'data': {
                'dateMet': dateMet_to_set.isoformat()
            }})

        self.assertEqual(response.status, '200 OK')
        patched_approval_milestone = get_milestone(self, contract.data.id,
                                                   approval_milestone['id'])
        assert patched_approval_milestone.dateMet == dateMet_to_set, 'dateMet was not set'
        assert patched_approval_milestone.status == 'met'
        reporting_milestone = get_milestone(self, contract.data.id,
                                            milestones[2]['id'])
        assert reporting_milestone.status == 'processing', 'Reporting milestone status must be `processing`'
        assert reporting_milestone.dueDate is not None
        updated_contract = get_contract(self, contract.data.id)
        assert updated_contract.status == 'active', 'Contract status was not updated'
Exemplo n.º 16
0
    def test_milestone_patch_financing_dateMet_partially_met(self):
        contract, milestones = prepare_milestones(self)
        financing_milestone = Milestone(milestones[0])
        assert financing_milestone.type_ == 'financing'
        dateMet_to_set = financing_milestone.dueDate + timedelta(days=5)

        response = patch_milestone(
            self, contract, financing_milestone.id,
            {'data': {
                'dateMet': dateMet_to_set.isoformat()
            }})

        self.assertEqual(response.status, '200 OK')
        patched_financing_milestone = get_milestone(self, contract.data.id,
                                                    financing_milestone.id)
        assert patched_financing_milestone.dateMet == dateMet_to_set, 'dateMet was not set'
        assert patched_financing_milestone.status == 'partiallyMet', 'dateMet was not set'
        approval_milestone = get_milestone(self, contract.data.id,
                                           milestones[1]['id'])
        assert approval_milestone.status == 'processing'
        assert approval_milestone.dueDate is not None
        updated_contract = get_contract(self, contract.data.id)
        assert updated_contract.status == 'active.approval', 'Contract status was not updated'