Ejemplo n.º 1
0
def create_or_patch_decision_in_not_allowed_status(self):
    self.app.authorization = ('Basic', ('broker', ''))
    self.initial_status = 'draft'
    self.create_resource()

    check_patch_status_200(self, '/{}'.format(self.resource_id), 'composing',
                           self.access_header)
    lot = add_lot_decision(self, self.resource_id, self.access_header)
    add_lot_related_process(self, self.resource_id, self.access_header)
    add_auctions(self, lot, self.access_header)
    check_patch_status_200(self, '/{}'.format(self.resource_id),
                           'verification', self.access_header)

    decision_data = {
        'decisionDate': get_now().isoformat(),
        'decisionID': 'decisionLotID'
    }
    response = self.app.post_json('/{}/decisions'.format(self.resource_id),
                                  {"data": decision_data},
                                  headers=self.access_header,
                                  status=403)
    self.assertEqual(response.status, '403 Forbidden')
    self.assertEqual(
        response.json['errors'][0]['description'],
        'Can\'t update decisions in current (verification) lot status')
Ejemplo n.º 2
0
def patch_decisions_with_lot_by_concierge(self):
    self.app.authorization = ('Basic', ('broker', ''))
    self.initial_status = 'draft'
    self.create_resource()

    decision_data = [{
        'decisionID': 'decID',
        'decisionDate': get_now().isoformat(),
        'relatedItem': '1' * 32,
        'decisionOf': 'asset'
    }]
    decision_data = {'decisions': decision_data}

    check_patch_status_200(self, '/{}'.format(self.resource_id), 'composing',
                           self.access_header)
    add_lot_decision(self, self.resource_id, self.access_header)
    lot = add_lot_related_process(self, self.resource_id, self.access_header)
    add_auctions(self, lot, self.access_header)
    check_patch_status_200(self, '/{}'.format(self.resource_id),
                           'verification', self.access_header)

    self.app.authorization = ('Basic', ('concierge', ''))
    response = self.app.patch_json('/{}'.format(self.resource_id),
                                   params={'data': decision_data},
                                   headers=self.access_header)
    decision = response.json['data']['decisions'][0]
    self.assertEqual(decision['decisionID'],
                     decision_data['decisions'][0]['decisionID'])
    self.assertEqual(decision['decisionDate'],
                     decision_data['decisions'][0]['decisionDate'])
    self.assertEqual(decision['relatedItem'],
                     decision_data['decisions'][0]['relatedItem'])
    self.assertEqual(decision['decisionOf'],
                     decision_data['decisions'][0]['decisionOf'])
    decision_id = decision['id']

    response = self.app.get('/{}/decisions/{}'.format(self.resource_id,
                                                      decision_id))
    self.assertEqual(response.json['data']['id'], decision_id)
    self.assertEqual(response.json['data']['decisionID'],
                     decision_data['decisions'][0]['decisionID'])
    self.assertEqual(response.json['data']['decisionDate'],
                     decision_data['decisions'][0]['decisionDate'])
    self.assertEqual(response.json['data']['relatedItem'],
                     decision_data['decisions'][0]['relatedItem'])
    self.assertEqual(response.json['data']['decisionOf'],
                     decision_data['decisions'][0]['decisionOf'])
Ejemplo n.º 3
0
def patch_auctions_with_lot(self):
    response = self.app.get('/{}'.format(self.resource_id))
    lot = response.json['data']
    self.set_status('draft')
    add_auctions(self, lot, access_header=self.access_header)
    self.set_status('pending')

    self.app.authorization = ('Basic', ('broker', ''))

    response = create_single_lot(self, self.initial_data)
    lot = response.json['data']
    token = response.json['access']['token']
    access_header = {'X-Access-Token': str(token)}

    # Move from 'draft' to 'pending' status
    check_patch_status_200(self, '/{}'.format(lot['id']), 'composing',
                           access_header)
    lot = add_lot_decision(self, lot['id'], access_header)
    add_lot_related_process(self, lot['id'], access_header)
    add_auctions(self, lot, access_header)
    check_patch_status_200(self, '/{}'.format(lot['id']), 'verification',
                           access_header)

    self.app.authorization = ('Basic', ('concierge', ''))

    check_patch_status_200(self, '/{}'.format(lot['id']), 'verification')
    add_decisions(self, lot)
    check_patch_status_200(self,
                           '/{}'.format(lot['id']),
                           'pending',
                           extra={'items': [test_loki_item_data]})

    self.app.authorization = ('Basic', ('broker', ''))

    data = deepcopy(lot)
    del data['decisions']
    del data['status']
    data['auctions'][0]['tenderAttempts'] = 3
    data['auctions'][0]['procurementMethodType'] = 'sellout.insider'
    response = self.app.patch_json(
        '/{}'.format(lot['id']),
        headers=access_header,
        params={'data': data},
    )
    self.assertEqual(response.status, '200 OK')
    self.assertEqual(response.content_type, 'application/json')
    self.assertEqual(response.json['data']['auctions'][0]['tenderAttempts'], 1)
    self.assertEqual(
        response.json['data']['auctions'][0]['procurementMethodType'],
        'sellout.english')

    response = self.app.get('/{}/auctions'.format(lot['id']))
    auctions = sorted(response.json['data'], key=lambda a: a['tenderAttempts'])
    english = auctions[0]
    self.assertEqual(english['tenderAttempts'], 1)
    self.assertEqual(english['procurementMethodType'], 'sellout.english')
Ejemplo n.º 4
0
def patch_decisions_with_lot_by_broker(self):
    self.app.authorization = ('Basic', ('broker', ''))
    self.initial_status = 'draft'
    self.create_resource()

    decision_data = [{
        'decisionID': 'decID',
        'decisionDate': get_now().isoformat()
    }, {
        'decisionID': 'decID2',
        'decisionDate': get_now().isoformat()
    }]
    decision_data = {'decisions': decision_data}

    check_patch_status_200(self, '/{}'.format(self.resource_id), 'composing',
                           self.access_header)
    response = self.app.patch_json('/{}'.format(self.resource_id),
                                   params={'data': decision_data},
                                   headers=self.access_header)
    self.assertNotIn('decisions', response.json)
Ejemplo n.º 5
0
def patch_decision(self):
    self.app.authorization = ('Basic', ('broker', ''))
    self.initial_status = 'draft'
    self.create_resource()

    check_patch_status_200(self, '/{}'.format(self.resource_id), 'composing',
                           self.access_header)
    add_lot_decision(self, self.resource_id, self.access_header)
    lot = add_lot_related_process(self, self.resource_id, self.access_header)
    add_auctions(self, lot, self.access_header)
    check_patch_status_200(self, '/{}'.format(self.resource_id),
                           'verification', self.access_header)

    self.app.authorization = ('Basic', ('concierge', ''))
    add_decisions(self, lot)
    check_patch_status_200(self,
                           '/{}'.format(self.resource_id),
                           'pending',
                           extra={'items': [test_loki_item_data]})

    self.app.authorization = ('Basic', ('broker', ''))
    decisions = self.app.get('/{}/decisions'.format(
        self.resource_id)).json['data']
    asset_decision_id = filter(lambda d: d['decisionOf'] == 'asset',
                               decisions)[0]['id']
    lot_decision_id = filter(lambda d: d['decisionOf'] == 'lot',
                             decisions)[0]['id']

    decision_data = {'title': 'Some Title'}
    response = self.app.patch_json('/{}/decisions/{}'.format(
        self.resource_id, asset_decision_id),
                                   params={'data': decision_data},
                                   status=403,
                                   headers=self.access_header)
    self.assertEqual(response.status, '403 Forbidden')
    self.assertEqual(
        response.json['errors'][0]['description'],
        'Can edit only decisions which have decisionOf equal to \'lot\'.')

    response = self.app.patch_json('/{}/decisions/{}'.format(
        self.resource_id, lot_decision_id),
                                   params={'data': decision_data},
                                   headers=self.access_header)
    self.assertEqual(response.status, '200 OK')
    self.assertEqual(response.json['data']['id'], lot_decision_id)
    self.assertEqual(response.json['data']['title'], decision_data['title'])
Ejemplo n.º 6
0
def patch_contracts_with_lot(self):
    self.app.authorization = ('Basic', ('broker', ''))

    response = create_single_lot(self, self.initial_data)
    lot = response.json['data']
    token = response.json['access']['token']
    access_header = {'X-Access-Token': str(token)}

    check_patch_status_200(self, '/{}'.format(lot['id']), 'composing',
                           access_header)

    # With two contracts
    data = {
        'contracts': [{
            'contractID': 'newContractID'
        }, {
            'contractID': 'newContractID2'
        }]
    }

    response = self.app.patch_json(
        '/{}'.format(lot['id']),
        headers=access_header,
        params={'data': data},
    )
    self.assertEqual(response.status, '200 OK')
    self.assertEqual(response.content_type, 'application/json')
    self.assertEqual(len(response.json['data']['contracts']), 1)

    response = self.app.get('/{}'.format(lot['id']))
    self.assertEqual(len(response.json['data']['contracts']), 1)
    contracts = response.json['data']['contracts']
    contract = contracts[0]
    self.assertEqual(len(contracts), 1)
    self.assertEqual(contract['type'], CONTRACT_TYPE)
    self.assertNotIn('contractID', contract)
    self.assertNotIn('relatedProcessID', contract)

    # With one contract
    data = {
        'contracts': [{
            'contractID': 'newContractID',
            'relatedProcessID': 'newRelatedProcessID',
            'type': 'new_type'
        }]
    }

    response = self.app.patch_json(
        '/{}'.format(lot['id']),
        headers=access_header,
        params={'data': data},
    )
    self.assertEqual(response.status, '200 OK')
    self.assertEqual(response.content_type, 'application/json')
    self.assertEqual(len(response.json['data']['contracts']), 1)

    response = self.app.get('/{}'.format(lot['id']))
    self.assertEqual(len(response.json['data']['contracts']), 1)
    contracts = response.json['data']['contracts']
    contract = contracts[0]
    self.assertEqual(len(contracts), 1)
    self.assertEqual(contract['type'], CONTRACT_TYPE)
    self.assertNotIn('contractID', contract)
    self.assertNotIn('relatedProcessID', contract)
Ejemplo n.º 7
0
def patch_items_with_lot(self):
    response = self.app.get('/{}'.format(self.resource_id))
    lot = response.json['data']

    self.set_status('draft')
    add_auctions(self, lot, access_header=self.access_header)
    self.set_status('pending')

    # Create lot in 'draft' status and move it to 'pending'
    initial_item_data = deepcopy(self.initial_item_data)
    del initial_item_data['id']

    response = create_single_lot(self, self.initial_data)
    lot = response.json['data']
    token = response.json['access']['token']
    access_header = {'X-Access-Token': str(token)}

    response = self.app.get('/{}'.format(lot['id']), headers=access_header)
    self.assertEqual(response.status, '200 OK')
    self.assertEqual(response.content_type, 'application/json')
    self.assertEqual(response.json['data'], lot)

    # Move from 'draft' to 'pending' status
    check_patch_status_200(self, '/{}'.format(lot['id']), 'composing',
                           access_header)
    add_lot_decision(self, lot['id'], access_header)
    lot = add_lot_related_process(self, lot['id'], access_header)
    add_auctions(self, lot, access_header)
    check_patch_status_200(self, '/{}'.format(lot['id']), 'verification',
                           access_header)

    self.app.authorization = ('Basic', ('concierge', ''))

    check_patch_status_200(self, '/{}'.format(lot['id']), 'verification')
    add_decisions(self, lot)
    check_patch_status_200(self,
                           '/{}'.format(lot['id']),
                           'pending',
                           extra={'items': [test_loki_item_data]})

    self.app.authorization = ('Basic', ('broker', ''))

    # Move from 'pending' to 'pending' status
    check_patch_status_200(self, '/{}'.format(lot['id']), 'pending',
                           access_header)

    response = self.app.post_json('/{}/items'.format(lot['id']),
                                  headers=access_header,
                                  params={'data': initial_item_data})
    self.assertEqual(response.status, '201 Created')
    self.assertEqual(response.content_type, 'application/json')
    item_id = response.json["data"]['id']
    self.assertIn(item_id, response.headers['Location'])
    self.assertEqual(self.initial_item_data['description'],
                     response.json["data"]["description"])
    self.assertEqual(self.initial_item_data['quantity'],
                     response.json["data"]["quantity"])
    self.assertEqual(self.initial_item_data['address'],
                     response.json["data"]["address"])

    response = self.app.post_json('/{}/items'.format(lot['id']),
                                  headers=access_header,
                                  params={'data': initial_item_data})
    self.assertEqual(response.status, '201 Created')
    self.assertEqual(response.content_type, 'application/json')
    item_id = response.json["data"]['id']
    self.assertIn(item_id, response.headers['Location'])
    self.assertEqual(self.initial_item_data['description'],
                     response.json["data"]["description"])
    self.assertEqual(self.initial_item_data['quantity'],
                     response.json["data"]["quantity"])
    self.assertEqual(self.initial_item_data['address'],
                     response.json["data"]["address"])

    response = self.app.get('/{}'.format(lot['id']))
    self.assertEqual(response.status, '200 OK')
    self.assertEqual(response.content_type, 'application/json')
    self.assertEqual(len(response.json['data']['items']), 3)

    data = {'items': [initial_item_data]}
    response = self.app.patch_json('/{}'.format(lot['id']),
                                   headers=access_header,
                                   params={'data': data})
    self.assertEqual(response.status, '200 OK')
    self.assertEqual(response.content_type, 'application/json')
    self.assertEqual(len(response.json['data']['items']), 1)

    item_data = deepcopy(self.initial_item_data)
    item_data['id'] = uuid4().hex
    data = {'items': [item_data, item_data]}
    response = self.app.patch_json('/{}'.format(lot['id']),
                                   headers=access_header,
                                   params={'data': data},
                                   status=422)
    self.assertEqual(response.status, '422 Unprocessable Entity')
    self.assertEqual(response.content_type, 'application/json')
    self.assertEqual(response.json['errors'][0]['description'][0],
                     u'Item id should be uniq for all items')

    data = {'items': [item_data]}
    response = self.app.patch_json('/{}'.format(lot['id']),
                                   headers=access_header,
                                   params={'data': data})
    self.assertEqual(response.status, '200 OK')
    self.assertEqual(response.content_type, 'application/json')
    self.assertNotEqual(response.json['data']['id'], item_data['id'])