Skip to content

Commit 4826e98

Browse files
author
BrunoCiccarino
committed
feat(tests) adding unit testing to the new api's testing module
1 parent c046847 commit 4826e98

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

test/test_api.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from sheepy.sheeptest import SheepyTestCase
2+
3+
class TestHttpBinApi(SheepyTestCase):
4+
""" Expected output:
5+
6+
Test Results:
7+
TestHttpBinApi.test_delete_resource: OK
8+
TestHttpBinApi.test_get_json: OK
9+
TestHttpBinApi.test_get_status: OK
10+
TestHttpBinApi.test_post_data: OK
11+
TestHttpBinApi.test_put_data: OK
12+
13+
"""
14+
def __init__(self):
15+
super().__init__(base_url="https://httpbin.org")
16+
17+
def test_get_status(self):
18+
19+
response = self.api.get("/status/200")
20+
self.assertStatusCode(response, 200)
21+
22+
def test_get_json(self):
23+
24+
response = self.api.get("/json")
25+
self.assertStatusCode(response, 200)
26+
self.assertJsonResponse(response)
27+
self.assertResponseContains(response, "slideshow")
28+
29+
def test_post_data(self):
30+
31+
payload = {"name": "SheepyTest", "framework": "unittest"}
32+
response = self.api.post("/post", json=payload)
33+
self.assertStatusCode(response, 200)
34+
self.assertJsonResponse(response)
35+
self.assertResponseContains(response, "json")
36+
self.assertEqual(response.json()["json"], payload)
37+
38+
def test_put_data(self):
39+
40+
payload = {"key": "value"}
41+
response = self.api.put("/put", json=payload)
42+
self.assertStatusCode(response, 200)
43+
self.assertJsonResponse(response)
44+
self.assertResponseContains(response, "json")
45+
self.assertEqual(response.json()["json"], payload)
46+
47+
def test_delete_resource(self):
48+
49+
response = self.api.delete("/delete")
50+
self.assertStatusCode(response, 200)
51+
self.assertJsonResponse(response)

test/test_uni.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from sheepy.sheeptest import SheepyTestCase
2+
3+
class ExampleTest(SheepyTestCase):
4+
5+
"""Expected output
6+
7+
Test Results:
8+
ExampleTest.test_error: FAIL - Forced error
9+
ExampleTest.test_expected_failure: EXPECTED FAILURE
10+
ExampleTest.test_failure: FAIL - 1 != 2
11+
ExampleTest.test_skipped: SKIPPED -
12+
ExampleTest.test_success: OK
13+
"""
14+
15+
def test_success(self):
16+
self.assertTrue(True)
17+
18+
def test_failure(self):
19+
self.assertEqual(1, 2)
20+
21+
def test_error(self):
22+
raise Exception("Forced error")
23+
24+
@SheepyTestCase.skip("Reason to ignore")
25+
def test_skipped(self):
26+
pass
27+
28+
@SheepyTestCase.expectedFailure
29+
def test_expected_failure(self):
30+
self.assertEqual(1, 2)
31+

0 commit comments

Comments
 (0)