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)
def patch_auctions_with_lot(self):
    response = self.app.get('/{}'.format(self.resource_id))
    lot = response.json['data']
    move_lot_to_pending(self, lot, self.access_header)

    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]})
Beispiel #3
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'])
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)