def test_method_url_inputs(self): method = restfuzz.method.Method({ 'name': 'test', 'url': ['PUT', '%(test)s.json'], 'inputs': { 'url_input': {'test': {'type': 'string'}} } }, base_url='http://localhost:8080') api = FakeApi(resp_content='{"id": "42"}') event = method.call(api, {'url_input': {'typo': 42}}) self.assertTrue("%(test)s" in event.url) event = method.call(api, {'url_input': {'test': 42}}) self.assertTrue("42.json" in event.url)
def test_collect_and_use_resource(self): ig = restfuzz.input_generator.InputGenerator(False) method = restfuzz.method.Method( { 'name': 'list', 'url': ['GET', 'list.json'], 'outputs': { 'id': { 'json_extract': 'lambda x: [i["id"] for i in x]' } } }, base_url='http://localhost:8080') api = FakeApi(resp_content='[{"id": "42"}, {"id": "43"}]') event = method.call(api) ig.resources_add(event.outputs) method = restfuzz.method.Method( { 'name': 'update', 'url': ['PUT', 'put.json'], 'inputs': { 'id': { '_type': 'resource', 'required': 'True' } } }, base_url='http://localhost:8080') params = ig.generate_inputs(method.inputs) self.assertTrue(params['id'] in ('42', '43'))
def test_method_inputs(self): method = restfuzz.method.Method({ 'name': 'test', 'url': ['POST', 'create.json'], 'inputs': {'name': {'type': 'string'}} }, base_url='http://localhost:8080') api = FakeApi() event = method.call(api, params={'name': 'test_name'}) self.assertEquals(event.json_input, '{"name": "test_name"}')
def test_method_basic_call(self): method = restfuzz.method.Method({ 'name': 'test', 'url': ['GET', 'list.json'], }, base_url='http://localhost:8080') self.assertTrue("test" in str(method)) api = FakeApi() event = method.call(api) self.assertEquals(event.url, 'http://localhost:8080/list.json')
def test_method_url_inputs(self): method = restfuzz.method.Method( { 'name': 'test', 'url': ['PUT', '%(test)s.json'], 'inputs': { 'url_input': { 'test': { '_type': 'string' } } } }, base_url='http://localhost:8080') api = FakeApi(resp_content='{"id": "42"}') event = method.call(api, {'url_input': {'typo': 42}}) self.assertTrue("%(test)s" in event.url) event = method.call(api, {'url_input': {'test': 42}}) self.assertTrue("42.json" in event.url)
def test_method_basic_call(self): method = restfuzz.method.Method( { 'name': 'test', 'url': ['GET', 'list.json'], }, base_url='http://localhost:8080') self.assertTrue("test" in str(method)) api = FakeApi() event = method.call(api) self.assertEquals(event.url, 'http://localhost:8080/list.json')
def test_method_outputs(self): method = restfuzz.method.Method({ 'name': 'test', 'url': ['GET', 'list.json'], 'outputs': { 'id': {'type': 'resource', 'json_extract': 'lambda x: x["id"]'}, } }, base_url='http://localhost:8080') api = FakeApi(resp_content='{"id": "42"}') event = method.call(api) self.assertIsNotNone(event.outputs) self.assertEqual(event.outputs, {"id": ["42"]})
def test_method_inputs(self): method = restfuzz.method.Method( { 'name': 'test', 'url': ['POST', 'create.json'], 'inputs': { 'name': { '_type': 'string' } } }, base_url='http://localhost:8080') api = FakeApi() event = method.call(api, params={'name': 'test_name'}) self.assertEquals(event.json_input, '{"name": "test_name"}')
def test_method_outputs(self): method = restfuzz.method.Method( { 'name': 'test', 'url': ['GET', 'list.json'], 'outputs': { 'id': { '_type': 'resource', 'json_extract': 'lambda x: x["id"]' }, } }, base_url='http://localhost:8080') api = FakeApi(resp_content='{"id": "42"}') event = method.call(api) self.assertIsNotNone(event.outputs) self.assertEqual(event.outputs, {"id": ["42"]})
def test_collect_and_use_resource(self): ig = restfuzz.input_generator.InputGenerator(False) method = restfuzz.method.Method({ 'name': 'list', 'url': ['GET', 'list.json'], 'outputs': {'id': {'json_extract': 'lambda x: [i["id"] for i in x]'}} }, base_url='http://localhost:8080') api = FakeApi(resp_content='[{"id": "42"}, {"id": "43"}]') event = method.call(api) ig.resources_add(event.outputs) method = restfuzz.method.Method({ 'name': 'update', 'url': ['PUT', 'put.json'], 'inputs': {'id': {'type': 'resource', 'required': 'True'}} }, base_url='http://localhost:8080') params = ig.generate_inputs(method.inputs) self.assertTrue(params['id'] in ('42', '43'))