|
22 | 22 |
|
23 | 23 |
|
24 | 24 | @pytest.mark.smoke |
25 | | -class TestJSONCustomRestEndpointsApp(testlib.SDKTestCase): |
| 25 | +class TestJSONCustomRestEndpointsSpecialMethodHelpers(testlib.SDKTestCase): |
26 | 26 | app_name = "cre_app" |
27 | 27 |
|
28 | 28 | def test_GET(self): |
@@ -76,3 +76,67 @@ def test_DELETE(self): |
76 | 76 | "method": "DELETE", |
77 | 77 | }, |
78 | 78 | ) |
| 79 | + |
| 80 | + |
| 81 | +@pytest.mark.smoke |
| 82 | +class TestJSONCustomRestEndpointGenericRequest(testlib.SDKTestCase): |
| 83 | + app_name = "cre_app" |
| 84 | + |
| 85 | + def test_no_str_body_GET(self): |
| 86 | + def with_body(): |
| 87 | + self.service.request( |
| 88 | + app=self.app_name, method="GET", path_segment="execute", body="str" |
| 89 | + ) |
| 90 | + |
| 91 | + self.assertRaisesRegex( |
| 92 | + Exception, "unable to set string body on GET method request", with_body |
| 93 | + ) |
| 94 | + |
| 95 | + def test_GET(self): |
| 96 | + resp = self.service.request( |
| 97 | + app=self.app_name, |
| 98 | + method="GET", |
| 99 | + path_segment="execute", |
| 100 | + headers=[("x-bar", "baz")], |
| 101 | + ) |
| 102 | + self.assertIn(("x-foo", "bar"), resp.headers) |
| 103 | + self.assertEqual(resp.status, 200) |
| 104 | + self.assertEqual( |
| 105 | + json.loads(str(resp.body)), |
| 106 | + { |
| 107 | + "headers": {"x-bar": "baz"}, |
| 108 | + "method": "GET", |
| 109 | + }, |
| 110 | + ) |
| 111 | + |
| 112 | + def test_POST(self): |
| 113 | + self.method("POST") |
| 114 | + |
| 115 | + def test_PUT(self): |
| 116 | + self.method("PUT") |
| 117 | + |
| 118 | + def test_PATCH(self): |
| 119 | + self.method("PATCH") |
| 120 | + |
| 121 | + def test_DELETE(self): |
| 122 | + self.method("DELETE") |
| 123 | + |
| 124 | + def method(self, method: str): |
| 125 | + body = json.dumps({"foo": "bar"}) |
| 126 | + resp = self.service.request( |
| 127 | + app=self.app_name, |
| 128 | + method=method, |
| 129 | + path_segment="execute", |
| 130 | + body=body, |
| 131 | + headers=[("x-bar", "baz")], |
| 132 | + ) |
| 133 | + self.assertIn(("x-foo", "bar"), resp.headers) |
| 134 | + self.assertEqual(resp.status, 200) |
| 135 | + self.assertEqual( |
| 136 | + json.loads(str(resp.body)), |
| 137 | + { |
| 138 | + "payload": '{"foo": "bar"}', |
| 139 | + "headers": {"x-bar": "baz"}, |
| 140 | + "method": method, |
| 141 | + }, |
| 142 | + ) |
0 commit comments