Skip to content

Commit

Permalink
create functional tests for httpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Aureliano da Silva Maia committed Sep 28, 2023
1 parent ad4dd68 commit 910b603
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/functional_test_http_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# vim: set filetype=python ts=4 sw=4
# -*- coding: utf-8 -*-
import unittest
from tokendito.http_client import HTTPClient

class TestHTTPClientFunctional(unittest.TestCase):

def setUp(self):
# Initialize the HTTPClient with a test user-agent
self.client = HTTPClient(user_agent="test-agent")

def test_get_request(self):
# Make a GET request to the /get endpoint of httpbin which reflects the sent request data
response = self.client.get("https://httpbin.org/get")
json_data = response.json()

# Assert that the request was successful and the returned User-Agent matches the one we set
self.assertEqual(response.status_code, 200)
self.assertEqual(json_data['headers']['User-Agent'], "test-agent")

def test_post_request(self):
# Make a POST request to the /post endpoint of httpbin with sample data
response = self.client.post("https://httpbin.org/post", json={"key": "value"})
json_data = response.json()

# Assert that the request was successful and the returned json data matches the data we sent
self.assertEqual(response.status_code, 200)
self.assertEqual(json_data['json'], {"key": "value"})

def test_set_cookies(self):
# Set a test cookie for the client
self.client.set_cookies({"test_cookie": "cookie_value"})

# Make a request to the /cookies endpoint of httpbin which returns set cookies
response = self.client.get("https://httpbin.org/cookies")
json_data = response.json()

# Assert that the cookie we set is correctly returned by the server
self.assertEqual(json_data['cookies'], {"test_cookie": "cookie_value"})

def test_custom_header(self):
# Make a GET request with a custom header
response = self.client.get("https://httpbin.org/get", headers={"X-Test-Header": "TestValue"})
json_data = response.json()

# Assert that the custom header was correctly sent
self.assertEqual(json_data['headers']['X-Test-Header'], "TestValue")

if __name__ == '__main__':
unittest.main()

0 comments on commit 910b603

Please sign in to comment.