Big unit test with a complete delivery payload
This commit is contained in:
parent
9c1d438eb1
commit
284fdf44b1
|
@ -0,0 +1,202 @@
|
||||||
|
from datetime import datetime, date
|
||||||
|
from unittest import TestCase
|
||||||
|
from urbantz.base import Coordinates
|
||||||
|
from urbantz.delivery import Location, Delivery
|
||||||
|
from urbantz.items import LogEntry, Item
|
||||||
|
from urbantz.utils import DictObject
|
||||||
|
import os.path
|
||||||
|
import json
|
||||||
|
|
||||||
|
FOLDER = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
|
|
||||||
|
class TestFull(TestCase):
|
||||||
|
"""
|
||||||
|
Unit tests with a full delivery payload
|
||||||
|
"""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
with open(os.path.join(FOLDER, 'test_payload.json')) as f:
|
||||||
|
cls.delivery = Delivery.fromJSON(json.load(f))
|
||||||
|
|
||||||
|
def test_types(self):
|
||||||
|
self.assertIsNone(self.delivery.tracking_code)
|
||||||
|
self.assertIsNone(self.delivery.last_updated)
|
||||||
|
self.assertIsInstance(self.delivery.payload, dict)
|
||||||
|
self.assertIsInstance(self.delivery.id, str)
|
||||||
|
self.assertIsInstance(self.delivery.date, date)
|
||||||
|
self.assertIsInstance(self.delivery.task_id, str)
|
||||||
|
self.assertIsInstance(self.delivery.platform_id, str)
|
||||||
|
self.assertIsInstance(self.delivery.driver_id, str)
|
||||||
|
self.assertIsInstance(self.delivery.round_id, str)
|
||||||
|
self.assertIsInstance(self.delivery.instructions, str)
|
||||||
|
self.assertIsInstance(self.delivery.progress, str)
|
||||||
|
self.assertIsInstance(self.delivery.status, str)
|
||||||
|
self.assertIsInstance(self.delivery.arrival_time, datetime)
|
||||||
|
self.assertIsInstance(self.delivery.eta_margin, int)
|
||||||
|
self.assertIsInstance(self.delivery.eta_rounding, int)
|
||||||
|
self.assertIsInstance(self.delivery.time_window, list)
|
||||||
|
for dt in self.delivery.time_window:
|
||||||
|
self.assertIsInstance(dt, datetime)
|
||||||
|
self.assertIsInstance(self.delivery.position, Coordinates)
|
||||||
|
self.assertIsInstance(self.delivery.destination, Location)
|
||||||
|
self.assertIsInstance(self.delivery.recipient, DictObject)
|
||||||
|
self.assertIsInstance(self.delivery.features, DictObject)
|
||||||
|
self.assertIsInstance(self.delivery.items, list)
|
||||||
|
for item in self.delivery.items:
|
||||||
|
self.assertIsInstance(item, Item)
|
||||||
|
self.assertIsInstance(self.delivery.logs, list)
|
||||||
|
for log in self.delivery.logs:
|
||||||
|
self.assertIsInstance(log, LogEntry)
|
||||||
|
self.assertIsInstance(self.delivery.theme, DictObject)
|
||||||
|
self.assertIsInstance(self.delivery.template, DictObject)
|
||||||
|
|
||||||
|
def test_attributes(self):
|
||||||
|
self.assertEqual(self.delivery.id, "cafe1234")
|
||||||
|
self.assertEqual(self.delivery.date, date(2019, 2, 3))
|
||||||
|
self.assertEqual(self.delivery.task_id, "123456789")
|
||||||
|
self.assertEqual(self.delivery.platform_id, "934")
|
||||||
|
self.assertEqual(self.delivery.driver_id, "987654e")
|
||||||
|
self.assertEqual(self.delivery.round_id, "552bc6f")
|
||||||
|
self.assertEqual(self.delivery.instructions, "Third floor")
|
||||||
|
self.assertEqual(self.delivery.progress, "COMPLETED")
|
||||||
|
self.assertEqual(self.delivery.status, "DELIVERED")
|
||||||
|
self.assertEqual(self.delivery.arrival_time,
|
||||||
|
datetime(2019, 2, 3, 6, 45, 7))
|
||||||
|
self.assertEqual(self.delivery.eta_margin, 20)
|
||||||
|
self.assertEqual(self.delivery.eta_rounding, 5)
|
||||||
|
self.assertEqual(self.delivery.time_window, [
|
||||||
|
datetime(2019, 2, 3, 8, 0, 0),
|
||||||
|
datetime(2019, 2, 3, 10, 0, 0),
|
||||||
|
])
|
||||||
|
|
||||||
|
def test_dictobjects(self):
|
||||||
|
self.assertEqual(self.delivery.recipient.account, "54321")
|
||||||
|
self.assertIsNone(self.delivery.recipient.name)
|
||||||
|
self.assertEqual(self.delivery.recipient.person, "M. Chuck Norris")
|
||||||
|
self.assertEqual(self.delivery.recipient.phone, "33800772424")
|
||||||
|
self.assertEqual(self.delivery.recipient.language, "fr")
|
||||||
|
self.assertTrue(self.delivery.features.driver_round_resequence)
|
||||||
|
self.assertTrue(self.delivery.features.driver_ratings)
|
||||||
|
self.assertFalse(self.delivery.features.consumer_modify_instructions)
|
||||||
|
self.assertTrue(self.delivery.features.allow_virtual_fleet)
|
||||||
|
self.assertFalse(self.delivery.features.cancel_optimization)
|
||||||
|
self.assertEqual(self.delivery.theme.primary, "#efefef")
|
||||||
|
self.assertEqual(self.delivery.theme.secondary, "rgb(30, 40, 50)")
|
||||||
|
self.assertEqual(self.delivery.template.map_availability, 60)
|
||||||
|
self.assertTrue(self.delivery.template.enabled)
|
||||||
|
self.assertEqual(self.delivery.template.email, "contact@example.com")
|
||||||
|
self.assertEqual(self.delivery.template.phone, "0999999999")
|
||||||
|
self.assertEqual(self.delivery.template.background_color,
|
||||||
|
"rgba(50, 40, 20, 0.95)")
|
||||||
|
self.assertEqual(self.delivery.template.primary_color, "#ffffff")
|
||||||
|
self.assertEqual(self.delivery.template.secondary_color, "#731246")
|
||||||
|
self.assertEqual(self.delivery.template.background_picture, "bg.png")
|
||||||
|
self.assertEqual(self.delivery.template.logo, "logo.png")
|
||||||
|
self.assertEqual(
|
||||||
|
self.delivery.template.image_path,
|
||||||
|
"https://backend.urbantz.com/pictures/platforms/934/",
|
||||||
|
)
|
||||||
|
self.assertEqual(self.delivery.template.name, "Something")
|
||||||
|
self.assertEqual(self.delivery.template.icon, "icon.png")
|
||||||
|
self.assertEqual(self.delivery.destination.address_lines, [
|
||||||
|
"Baker Street", "742", "GU16 7HF", "Nowhere", "UK",
|
||||||
|
])
|
||||||
|
self.assertEqual(self.delivery.destination.geocode_score, 98)
|
||||||
|
self.assertEqual(self.delivery.destination.clean_score, 0)
|
||||||
|
self.assertEqual(self.delivery.destination.number, "742")
|
||||||
|
self.assertEqual(self.delivery.destination.street, "Baker Street")
|
||||||
|
self.assertEqual(self.delivery.destination.city, "Nowhere")
|
||||||
|
self.assertEqual(self.delivery.destination.zip, "GU16 7HF")
|
||||||
|
self.assertEqual(self.delivery.destination.country, "UK")
|
||||||
|
self.assertEqual(self.delivery.destination.origin, "ARCGIS")
|
||||||
|
self.assertEqual(self.delivery.destination.precision, "point")
|
||||||
|
|
||||||
|
def test_objects(self):
|
||||||
|
self.assertEqual(self.delivery.position,
|
||||||
|
Coordinates(lat=32.2135467, lng=0.1234567))
|
||||||
|
self.assertEqual(self.delivery.destination.coordinates, Coordinates(
|
||||||
|
lat=42.18906577220902, lng=2.21154054884875))
|
||||||
|
self.assertListEqual(self.delivery.logs, [
|
||||||
|
LogEntry(
|
||||||
|
to="GEOCODED",
|
||||||
|
by=None,
|
||||||
|
when="2019-02-01T23:07:22.997Z",
|
||||||
|
),
|
||||||
|
LogEntry(
|
||||||
|
to="ASSIGNED",
|
||||||
|
by="65dc8",
|
||||||
|
when="2019-02-02T05:16:22.557Z",
|
||||||
|
),
|
||||||
|
LogEntry(
|
||||||
|
to="ONGOING",
|
||||||
|
by="f3251c86513d",
|
||||||
|
when="2019-02-03T07:08:32.107Z",
|
||||||
|
),
|
||||||
|
LogEntry(
|
||||||
|
_id="5416a321",
|
||||||
|
to="COMPLETED",
|
||||||
|
by="6513d54e",
|
||||||
|
when="2019-02-03T07:56:47.814Z",
|
||||||
|
),
|
||||||
|
])
|
||||||
|
self.assertEqual(len(self.delivery.items), 1)
|
||||||
|
item = self.delivery.items[0]
|
||||||
|
self.assertFalse(item.damage_confirmed)
|
||||||
|
self.assertListEqual(item.damage_pictures, [])
|
||||||
|
self.assertEqual(item.status, "DELIVERED")
|
||||||
|
self.assertEqual(item.quantity, 1)
|
||||||
|
self.assertListEqual(item.labels, [])
|
||||||
|
self.assertListEqual(item.skills, [])
|
||||||
|
self.assertEqual(item.id, "cafe1")
|
||||||
|
self.assertEqual(item.type, "COFFEE")
|
||||||
|
self.assertEqual(item.barcode, "133742133742")
|
||||||
|
self.assertEqual(item.barcode_encoding, "upc")
|
||||||
|
self.assertIsInstance(item.dimensions, DictObject)
|
||||||
|
self.assertEqual(item.dimensions.weight, 19.01)
|
||||||
|
self.assertEqual(item.dimensions.cardboard, 2)
|
||||||
|
self.assertIsInstance(item.metadata, DictObject)
|
||||||
|
self.assertIsNone(item.metadata.package_number)
|
||||||
|
self.assertEqual(item.metadata.quantity, 0)
|
||||||
|
self.assertEqual(item.metadata.order_id_ext, "5255887")
|
||||||
|
self.assertEqual(item.metadata.new_client, "No")
|
||||||
|
self.assertListEqual(item.logs, [
|
||||||
|
LogEntry(
|
||||||
|
by=None,
|
||||||
|
when="2019-02-02T10:32:27.621Z",
|
||||||
|
to="ARRIVED",
|
||||||
|
),
|
||||||
|
LogEntry(
|
||||||
|
by="dead",
|
||||||
|
when="2019-02-03T07:08:32.107Z",
|
||||||
|
to="DEPARTED",
|
||||||
|
),
|
||||||
|
LogEntry(
|
||||||
|
_id="106",
|
||||||
|
by="c0fe",
|
||||||
|
when="2019-02-03T07:56:47.814Z",
|
||||||
|
to="DELIVERED",
|
||||||
|
),
|
||||||
|
])
|
||||||
|
|
||||||
|
def test_properties(self):
|
||||||
|
self.assertListEqual(self.delivery.eta, [
|
||||||
|
datetime(2019, 2, 3, 6, 35, 0),
|
||||||
|
datetime(2019, 2, 3, 6, 55, 0),
|
||||||
|
])
|
||||||
|
self.assertListEqual([log.datetime for log in self.delivery.logs], [
|
||||||
|
datetime(2019, 2, 1, 23, 7, 22, 997000),
|
||||||
|
datetime(2019, 2, 2, 5, 16, 22, 557000),
|
||||||
|
datetime(2019, 2, 3, 7, 8, 32, 107000),
|
||||||
|
datetime(2019, 2, 3, 7, 56, 47, 814000),
|
||||||
|
])
|
||||||
|
self.assertListEqual(
|
||||||
|
[log.datetime for log in self.delivery.items[0].logs],
|
||||||
|
[
|
||||||
|
datetime(2019, 2, 2, 10, 32, 27, 621000),
|
||||||
|
datetime(2019, 2, 3, 7, 8, 32, 107000),
|
||||||
|
datetime(2019, 2, 3, 7, 56, 47, 814000),
|
||||||
|
]
|
||||||
|
)
|
|
@ -0,0 +1,152 @@
|
||||||
|
{
|
||||||
|
"_id": "cafe1234",
|
||||||
|
"date": "2019-02-03T00:00:00.000Z",
|
||||||
|
"taskId": "123456789",
|
||||||
|
"type": "delivery",
|
||||||
|
"by": "beef",
|
||||||
|
"contact": {
|
||||||
|
"account": "54321",
|
||||||
|
"name": null,
|
||||||
|
"person": "M. Chuck Norris",
|
||||||
|
"phone": "33800772424",
|
||||||
|
"language": "fr"
|
||||||
|
},
|
||||||
|
"instructions": "Third floor",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"damaged": {
|
||||||
|
"confirmed": false,
|
||||||
|
"pictures": []
|
||||||
|
},
|
||||||
|
"status": "DELIVERED",
|
||||||
|
"quantity": 1,
|
||||||
|
"labels": [],
|
||||||
|
"skills": [],
|
||||||
|
"_id": "cafe1",
|
||||||
|
"type": "COFFEE",
|
||||||
|
"barcode": "133742133742",
|
||||||
|
"barcodeEncoding": "upc",
|
||||||
|
"dimensions": {
|
||||||
|
"weight": 19.01,
|
||||||
|
"cardboard": 2
|
||||||
|
},
|
||||||
|
"log": [
|
||||||
|
{
|
||||||
|
"by": null,
|
||||||
|
"when": "2019-02-02T10:32:27.621Z",
|
||||||
|
"to": "ARRIVED"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"by": "dead",
|
||||||
|
"when": "2019-02-03T07:08:32.107Z",
|
||||||
|
"to": "DEPARTED"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_id": "106",
|
||||||
|
"by": "c0fe",
|
||||||
|
"when": "2019-02-03T07:56:47.814Z",
|
||||||
|
"to": "DELIVERED"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"packageNumber": null,
|
||||||
|
"quantity": 0,
|
||||||
|
"orderIdExt": "5255887",
|
||||||
|
"newClient": "No"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"location": {
|
||||||
|
"location": {
|
||||||
|
"type": "Point",
|
||||||
|
"geometry": [
|
||||||
|
2.21154054884875,
|
||||||
|
42.18906577220902
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"addressLines": [
|
||||||
|
"Baker Street",
|
||||||
|
"742",
|
||||||
|
"GU16 7HF",
|
||||||
|
"Nowhere",
|
||||||
|
"UK"
|
||||||
|
],
|
||||||
|
"geocodeScore": 98,
|
||||||
|
"cleanScore": 0,
|
||||||
|
"number": "742",
|
||||||
|
"street": "Baker Street",
|
||||||
|
"city": "Nowhere",
|
||||||
|
"zip": "GU16 7HF",
|
||||||
|
"country": "UK",
|
||||||
|
"origin": "ARCGIS",
|
||||||
|
"precision": "point"
|
||||||
|
},
|
||||||
|
"log": [
|
||||||
|
{
|
||||||
|
"to": "GEOCODED",
|
||||||
|
"when": "2019-02-01T23:07:22.997Z",
|
||||||
|
"by": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"by": "65dc8",
|
||||||
|
"when": "2019-02-02T05:16:22.557Z",
|
||||||
|
"to": "ASSIGNED"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"by": "f3251c86513d",
|
||||||
|
"when": "2019-02-03T07:08:32.107Z",
|
||||||
|
"to": "ONGOING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_id": "5416a321",
|
||||||
|
"by": "6513d54e",
|
||||||
|
"when": "2019-02-03T07:56:47.814Z",
|
||||||
|
"to": "COMPLETED"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"platform": "934",
|
||||||
|
"progress": "COMPLETED",
|
||||||
|
"serviceTime": 13,
|
||||||
|
"status": "DELIVERED",
|
||||||
|
"timeWindow": {
|
||||||
|
"start": "2019-02-03T08:00:00.000Z",
|
||||||
|
"stop": "2019-02-03T10:00:00.000Z"
|
||||||
|
},
|
||||||
|
"when": "2019-02-01T23:07:16.734Z",
|
||||||
|
"arriveTime": "2019-02-03T06:45:07.000Z",
|
||||||
|
"driver": "987654e",
|
||||||
|
"round": "552bc6f",
|
||||||
|
"position": [
|
||||||
|
0.1234567,
|
||||||
|
32.2135467
|
||||||
|
],
|
||||||
|
"template": {
|
||||||
|
"mapAvailability": 60,
|
||||||
|
"enabled": true,
|
||||||
|
"email": "contact@example.com",
|
||||||
|
"phone": "0999999999",
|
||||||
|
"backgroundColor": "rgba(50, 40, 20, 0.95)",
|
||||||
|
"primaryColor": "#ffffff",
|
||||||
|
"secondaryColor": "#731246",
|
||||||
|
"backgroundPicture": "bg.png",
|
||||||
|
"logo": "logo.png",
|
||||||
|
"imagePath": "https://backend.urbantz.com/pictures/platforms/934/",
|
||||||
|
"name": "Something",
|
||||||
|
"icon": "icon.png"
|
||||||
|
},
|
||||||
|
"features": {
|
||||||
|
"driverRoundResequence": true,
|
||||||
|
"driverRatings": true,
|
||||||
|
"consumerModifyInstructions": false,
|
||||||
|
"allowVirtualFleet": true,
|
||||||
|
"cancelOptimization": false
|
||||||
|
},
|
||||||
|
"eta": {
|
||||||
|
"margin": 20,
|
||||||
|
"rounding": 5
|
||||||
|
},
|
||||||
|
"theme": {
|
||||||
|
"primary": "#efefef",
|
||||||
|
"secondary": "rgb(30, 40, 50)"
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue