dhltrack/test.py

35 lines
1.2 KiB
Python
Raw Normal View History

2023-08-16 09:28:38 +00:00
from unittest import TestCase, main
from configparser import ConfigParser
import json
2023-08-27 08:01:47 +00:00
from fedextrack import *
2023-08-16 09:28:38 +00:00
class TestHTTPRequest(TestCase):
def test_http_request(self):
http = HTTPRequest("https://httpbin.org/get")
response = http.execute()
self.assertEqual(response["headers"]["User-Agent"], http.USER_AGENT)
def test_http_request_with_json_payload(self):
http = HTTPRequest("https://httpbin.org/post")
http.add_json_payload({"foo": "bar"})
response = http.execute()
self.assertEqual(response["headers"]["User-Agent"], http.USER_AGENT)
self.assertEqual(response["headers"]["Content-Type"], "application/json")
self.assertEqual(response["json"]["foo"], "bar")
2023-08-27 08:01:47 +00:00
class TestFedEx(TestCase):
2023-08-16 09:28:38 +00:00
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.config = ConfigParser()
self.config.read("config.ini")
2023-08-27 08:01:47 +00:00
self.fedex = FedEx.from_config(self.config)
2023-08-16 09:28:38 +00:00
2023-08-27 08:01:47 +00:00
def test_tracking(self):
tracking_number = "702395541585"
response = self.fedex.tracking(tracking_number)
self.assertEqual(response["output"]["completeTrackResults"][0]["trackingNumber"], tracking_number)
2023-08-16 09:28:38 +00:00
if __name__ == "__main__":
main()