Skip to content

Commit dd30701

Browse files
author
Mat Lord
committed
chore(tests): unit test more conditions
1 parent 49a7b9a commit dd30701

5 files changed

Lines changed: 25 additions & 5 deletions

File tree

staxapp/contract.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def validate(cls, data, component):
5454
@staticmethod
5555
def default_swagger_template() -> dict:
5656
# Get the default swagger template from https://api.au1.staxapp.cloud/20190206/public/api-document
57-
schema = requests.get(Config.schema_url()).json()
57+
schema_response = requests.get(Config.schema_url()).json()
5858
template = dict(
5959
openapi="3.0.0",
6060
info={
@@ -75,7 +75,7 @@ def default_swagger_template() -> dict:
7575
"x-amazon-apigateway-authtype": "awsSigv4",
7676
}
7777
},
78-
"schemas": schema,
78+
"schemas": schema_response.get("components").get("schemas"),
7979
"responses": dict(),
8080
"requestBodies": dict(),
8181
},

tests/test_api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,10 @@ def testFailedApiException(self):
207207
json=response_dict,
208208
status=500,
209209
)
210-
with self.assertRaises(ApiException):
210+
try:
211211
self.Api.get("/test/no/error")
212+
except ApiException as e:
213+
self.assertIn("Api Exception", str(e))
212214

213215
# Test an exception which has no json in response
214216
responses.add(

tests/test_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def testCredentialErrors(self):
8989
srp_client=self.aws_srp_client,
9090
)
9191
except InvalidCredentialsException as e:
92-
self.assertIn("Please check your Secret Key is correct", e.message)
92+
self.assertIn("Please check your Secret Key is correct", str(e))
9393
user_not_found_success = True
9494
self.assertTrue(user_not_found_success)
9595

@@ -103,7 +103,7 @@ def testCredentialErrors(self):
103103
except InvalidCredentialsException as e:
104104
self.assertIn(
105105
"Please check your Access Key, that you have created your Api Token and that you are using the right STAX REGION",
106-
e.message,
106+
str(e),
107107
)
108108
no_access_success = True
109109
self.assertTrue(no_access_success)

tests/test_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ def testStaxClient(self):
3636
self.assertTrue(client._initialized)
3737
self.assertTrue(client._admin)
3838

39+
def testInvalidStaxClient(self):
40+
"""
41+
Test an invalid Api class raises an error
42+
"""
43+
with self.assertRaises(ValidationException):
44+
StaxClient("fake")
45+
3946
def testLoadLiveSchema(self):
4047
"""
4148
Test loading live schema

tests/test_contract.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ class StaxContractTests(unittest.TestCase):
1919
def setUp(self):
2020
self.StaxContract = StaxContract
2121

22+
def testInvalidSchema(self):
23+
"""
24+
Test an error is thrown if no schema is found
25+
"""
26+
sc = StaxContract
27+
sc._swagger_doc = None
28+
data = {"Name": "Unit", "AccountType": "Test"}
29+
component = "accounts.CreateAccount"
30+
sc.validate(data, component)
31+
self.assertIsNotNone(sc._swagger_doc)
32+
2233
def testDefaultSchema(self):
2334
"""
2435
Test the default schema is valid

0 commit comments

Comments
 (0)