pykeydelivery/test.py
Kumi fbb1a9d46c
Add test for listing carriers and assert that at least one carrier has a code equal to "gls".
- Add test for listing carriers
- Assert that at least one carrier has a code equal to "gls"
2023-08-31 09:03:57 +02:00

42 lines
No EOL
1.5 KiB
Python

from unittest import TestCase, main
from configparser import ConfigParser
import json
from pykeydelivery import *
class TestHTTPRequest(TestCase):
def test_http_request(self):
http = HTTPRequest("https://httpbin.kumi.systems/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.kumi.systems/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")
class TestKeyDelivery(TestCase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.config = ConfigParser()
self.config.read("config.ini")
self.keydelivery = KeyDelivery.from_config(self.config)
def test_detect_carrier(self):
response = self.keydelivery.detect_carrier("483432314669")
self.assertEqual(response["code"], 200)
def test_realtime(self):
response = self.keydelivery.realtime("gls", "483432314669")
self.assertEqual(response["code"], 200)
def test_list_carriers(self):
response = self.keydelivery.list_carriers()
self.assertTrue(any([carrier["code"] == "gls" for carrier in response["data"]]))
if __name__ == "__main__":
main()