def test_purchase(self): BATCH = DUMMY_BATCH.copy() batch = shippo.Batch.create(**BATCH) while batch.status == 'VALIDATING': batch = shippo.Batch.retrieve(batch.object_id) purchase = shippo.Batch.purchase(batch.object_id) self.assertEqual(purchase.status, 'PURCHASING')
def test_invalid_add(self): BATCH = DUMMY_BATCH.copy() batch = shippo.Batch.create(**BATCH) self.assertEqual(batch.status, 'VALIDATING') mock_shipment = create_mock_shipment() self.assertRaises(shippo.error.APIError, shippo.Batch.add, 'INVALID_OBJECT_KEY', [{ 'shipment': [mock_shipment] }])
def test_retrieve(self): BATCH = DUMMY_BATCH.copy() batch = shippo.Batch.create(**BATCH) retrieve = shippo.Batch.retrieve(batch.object_id) self.assertItemsEqual(batch, retrieve) # Leave enough time for the batch to be processed retrieve = shippo.Batch.retrieve( batch.object_id, **{'object_results': 'creation_succeeded'}) self.assertGreater(len(retrieve['batch_shipments']['results']), 0)
def test_invalid_remove(self): BATCH = DUMMY_BATCH.copy() batch = shippo.Batch.create(**BATCH) self.assertEqual(batch.status, 'VALIDATING') retrieve = shippo.Batch.retrieve(batch.object_id) to_remove = [] for shipment in retrieve.batch_shipments.results: to_remove.append(shipment.object_id) self.assertRaises(shippo.error.APIError, shippo.Batch.add, 'INVALID_OBJECT_KEY', to_remove)
def test_add(self): BATCH = DUMMY_BATCH.copy() batch = shippo.Batch.create(**BATCH) # Leave enough time for the batch to be processed retrieve = shippo.Batch.retrieve(batch.object_id) batch_size = len(retrieve.batch_shipments.results) self.assertEqual(batch.status, 'VALIDATING') addon = [] for i in range(BATCH_ADD_SIZE): mock_shipment = create_mock_shipment() addon.append({'shipment': mock_shipment.object_id}) added = shippo.Batch.add(batch.object_id, addon) added_size = len(added.batch_shipments.results) self.assertEqual(batch_size + len(addon), added_size)
def test_create(self): BATCH = DUMMY_BATCH.copy() batch = shippo.Batch.create(**BATCH) self.assertEqual(batch.status, 'VALIDATING')