Skip to content

Commit

Permalink
add requests tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Czechh committed Jun 8, 2023
1 parent 938b05d commit 896aa0a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
14 changes: 14 additions & 0 deletions tests/test_metal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import respx
from httpx import Response
from unittest import TestCase, mock
from src.metal_sdk.metal import Metal

Expand All @@ -15,6 +17,18 @@ def test_metal_instantiate(self):
self.assertEqual(metal.client_id, CLIENT_ID)
self.assertEqual(metal.index_id, index_id)

@respx.mock
def test_request(self):
url = 'https://api.getmetal.io/foo/bar'
method = 'GET'
respx.get(url).mock(return_value=Response(200))

index_id = "index-id"
metal = Metal(API_KEY, CLIENT_ID, index_id)

response = metal.request(method, "/foo/bar")
assert response.status_code == 200

def test_metal_index_without_index(self):
metal = Metal(API_KEY, CLIENT_ID)
with self.assertRaises(TypeError) as ctx:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_metal_async.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import respx
from httpx import Response
from unittest import IsolatedAsyncioTestCase, mock
from src.metal_sdk.metal_async import Metal

Expand All @@ -15,6 +17,18 @@ def test_metal_instantiate(self):
self.assertEqual(metal.client_id, CLIENT_ID)
self.assertEqual(metal.index_id, index_id)

@respx.mock
async def test_request(self):
url = 'https://api.getmetal.io/foo/bar'
method = 'GET'
respx.get(url).mock(return_value=Response(200))

index_id = "index-id"
metal = Metal(API_KEY, CLIENT_ID, index_id)

response = await metal.request(method, "/foo/bar")
assert response.status_code == 200

async def test_metal_index_without_index(self):
metal = Metal(API_KEY, CLIENT_ID)
with self.assertRaises(TypeError) as ctx:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_motorhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def test_request(self):
respx.get(url).mock(return_value=Response(200))

payload = {"api_key": "test_key", "client_id": "test_id", "base_url": "https://test_base_url"}
client = Motorhead(payload)
motorhead = Motorhead(payload)

response = client.request(method, "/test_endpoint")
response = motorhead.request(method, "/test_endpoint")
assert response.status_code == 200

def test_add_memory(self):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_motorhead_async.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import respx
from httpx import Response
from unittest import IsolatedAsyncioTestCase, mock
from src.metal_sdk.motorhead_async import Motorhead

Expand All @@ -15,6 +17,18 @@ async def test_initialization(self):
with self.assertRaises(ValueError):
Motorhead()

@respx.mock
async def test_request(self):
url = 'https://test_base_url/test_endpoint'
method = 'GET'
respx.get(url).mock(return_value=Response(200))

payload = {"api_key": "test_key", "client_id": "test_id", "base_url": "https://test_base_url"}
motorhead = Motorhead(payload)

response = await motorhead.request(method, "/test_endpoint")
assert response.status_code == 200

async def test_add_memory(self):
m = Motorhead({"api_key": API_KEY, "client_id": CLIENT_ID})
mock_response = mock.Mock()
Expand Down

0 comments on commit 896aa0a

Please sign in to comment.