Пример #1
0
 def test_to_string(self):
     request = create_delivery_request()
     self.assertEqual(
         str(request),
         "Delivery request TEST | item, from: Location: (59.51224, 17.93536) Odenvägen 1, SE-194 63 Ode"
         +
         "nslunda, Sweden -> to: Location: (56.64989, 15.16624) Rolsmo 1, SE-360 24 Linneryd, Sweden, rew"
         +
         "ard: 10, money_lock: 0, weight: 2, fragile: True, status: 0, description: This a test, feel fre"
         + "e to remove., image_path: ")
Пример #2
0
    def test_upload(self):
        request = utils.create_delivery_request()

        try:
            DeliveryRequestUploader.upload(request)
        except Exception:
            return

        self.assertEqual(
            1, 1,
            "This assert will only be called if the test doesn't error out earlier."
        )
Пример #3
0
    def test_subscription(self):
        event = threading.Event()

        callback_with_event = functools.partial(lambda *_: event.set(), event)
        Firestore.subscribe("packages", callback_with_event)

        request = create_delivery_request()
        self.assertIsNotNone(request)
        DeliveryRequestUploader.upload(request)

        event.wait()

        self.assertTrue(event.is_set())

        Firestore.unsubscribe("packages")

        Firestore.unsubscribe("some_invalid_thing_to_unsubscribe_from")
Пример #4
0
    def test_conversion(self):
        request = create_delivery_request()

        request_dict = request.to_dict()

        expected = {
            'uid': 'TEST',
            'item': 'item',
            'description': 'This a test, feel free to remove.',
            'origin': {
                'name': 'Odenvägen 1, SE-194 63 Odenslunda, Sweden',
                'latitude': 59.51224,
                'longitude': 17.93536
            },
            'destination': {
                'name': 'Rolsmo 1, SE-360 24 Linneryd, Sweden',
                'latitude': 56.64989,
                'longitude': 15.16624
            },
            'reward': 10,
            'weight': 2,
            'fragile': True,
            'status': 0,
            'money_lock': 0,
            'owner': {
                'name': '',
                'mail': '',
                'phonenumber': '',
                'uid': 'xUQeyplJshTzco4vyHHVoytT3FD2'
            },
            'assistant': {
                'name': '',
                'mail': '',
                'phonenumber': '',
                'uid': ''
            },
            'image_path': ''
        }

        self.assertDictEqual(
            request_dict,
            expected,
            msg="The converted dict should equal the expected dict. "
            "You may want to check the data definition in the team "
            "GDrive to confirm all data is present and correct.")
Пример #5
0
    def test_batching(self):
        delivery_request = create_delivery_request()

        with Firestore.batch('packages') as batch:
            dr_dict = delivery_request.to_dict()
            uid = batch.create_with_random_id(dr_dict)
            batch.update(uid, {
                'status': Status.ACCEPTED,
                'assistant': 'pIAeLAvHXp0KZKWDzTMz'
            })
            batch.set(uid, dr_dict)

        self.assertTrue(
            any(request.to_dict()['uid'] == "TEST"
                for request in Firestore.get('packages')))

        with Firestore.batch('packages') as batch:
            batch.delete(uid)
Пример #6
0
 def test_has_assistant(self):
     request = create_delivery_request()
     self.assertTrue(request.has_assistant())
Пример #7
0
 def test_reward_pretty(self):
     request = create_delivery_request()
     self.assertEqual(request.reward_pretty, "10 kr")
Пример #8
0
 def test_distance_pretty(self):
     request = create_delivery_request()
     self.assertEqual(request.distance_pretty, "358.2 km")
Пример #9
0
 def test_distance_km(self):
     request = create_delivery_request()
     self.assertEqual(request.distance_km, 358.15690351620367)