Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,37 @@ def test_prepare_body_form(self):
# Assert
self.assertTrue(content_type.startswith("multipart/form-data"))
self.assertIsInstance(body, bytes)

def test_prepare_body_file(self):
baseClient = BaseClient(TestClientId, TestClientSecret, TestEndpoint)
file_content = b"test file content"

content_type, body = baseClient.prepare_body(file_content, True, True)

self.assertTrue(content_type.startswith("multipart/form-data"))
self.assertIsInstance(body, bytes)
self.assertIn(b"test file content", body)

def test_do_get_bytes_raw_without_check(self):
baseClient = BaseClient(TestClientId, TestClientSecret, TestEndpoint)
mock_response = b'{"key": "value"}'
url = f"{TestEndpoint}/api/test"

with requests_mock.Mocker() as m:
m.get(url, content=mock_response)
result = baseClient.do_get_bytes_raw_without_check(url)

self.assertEqual(result, mock_response)

def test_do_post_bytes_raw(self):
baseClient = BaseClient(TestClientId, TestClientSecret, TestEndpoint)
mock_response = b'{"status": "success"}'
url = f"{TestEndpoint}/api/test"
content_type = "application/json"
body = b'{"test": "data"}'

with requests_mock.Mocker() as m:
m.post(url, content=mock_response)
result = baseClient.do_post_bytes_raw(url, content_type, body)

self.assertEqual(result, mock_response)
29 changes: 29 additions & 0 deletions src/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,32 @@ def test_casvisor_sdk_initialization(self):
self.assertEqual(sdk.organizationName, organization_name)
self.assertEqual(sdk.applicationName, application_name)
self.assertIsInstance(sdk.baseClient, BaseClient)

def test_casvisor_sdk_inheritance(self):
sdk = CasvisorSDK(
endpoint=TestEndpoint,
clientId=TestClientId,
clientSecret=TestClientSecret,
organizationName=TestOrganization,
applicationName=TestApplication,
)

self.assertTrue(hasattr(sdk, "get_records"))
self.assertTrue(hasattr(sdk, "get_record"))
self.assertTrue(hasattr(sdk, "add_record"))
self.assertTrue(hasattr(sdk, "update_record"))
self.assertTrue(hasattr(sdk, "delete_record"))

def test_casvisor_sdk_base_client_initialization(self):
sdk = CasvisorSDK(
endpoint=TestEndpoint,
clientId=TestClientId,
clientSecret=TestClientSecret,
organizationName=TestOrganization,
applicationName=TestApplication,
)

self.assertIsInstance(sdk.baseClient, BaseClient)
self.assertEqual(sdk.baseClient.endpoint, TestEndpoint)
self.assertEqual(sdk.baseClient.clientId, TestClientId)
self.assertEqual(sdk.baseClient.clientSecret, TestClientSecret)