def test_method_name(self): api = GetAPI("post/", {"response": {"200+": "$postResponse"}}) self.assertEqual(iOSTemplateMethods.method_name(api), "PostWithSuccess") api = GetAPI("post/:id/", {"response": {"200+": "$postResponse"}}) self.assertEqual(iOSTemplateMethods.method_name(api), "PostWithTheID") objects_json = { '$postRequest': { "body": "string", "title": "string" }, '$postResponse': { "body": "string", "title": "string" } } urls_json = [{ "url": "post/:id/", "patch": { "request": "$postRequest", "response": { "200+": "$postResponse" } } }] schema = create_dynamic_schema(objects_json, urls_json) self.assertEqual(iOSTemplateMethods.method_name(schema.urls[0].patch), "PostWithBody")
def test_content_type(self): api = GetAPI("post/", {"response": {"200+": "$postResponse"}}) self.assertEqual(iOSTemplateMethods.content_type(api), "RKMIMETypeJSON") api.content_type = API.CONTENT_TYPE_FORM self.assertEqual(iOSTemplateMethods.content_type(api), "RKMIMETypeFormURLEncoded")
def test_objective_c_key_path(self): api = GetAPI("post/", {"response": {"200+": "$postResponse"}}) self.assertEqual(ObjectiveCTemplateMethods.key_path(api), '@"results"') api.resource_type = GetAPI.RESOURCE_DETAIL self.assertEqual(ObjectiveCTemplateMethods.key_path(api), "nil") api = GetAPI("post/:id/favorite/", {"response": {"200+": "$postResponse"}}) self.assertEqual(ObjectiveCTemplateMethods.key_path(api), "nil")
def test_is_oauth(self): api = GetAPI("post/", { "response": { "200+": "$postResponse" } }) self.assertFalse(BaseTemplateMethods.is_oauth(api)) api.set_authorization({"#meta": API.OAUTH2}) self.assertTrue(BaseTemplateMethods.is_oauth(api))
def test_api_method_template(self): api = GetAPI( "post/", { "#meta": "oauth2", "request": "$postRequest", "response": { "200+": "$postResponse" } }) # Mock schema object schema = { 'data_objects': { '$postRequest': DataObject("$postRequest", { 'body': 'string', 'title': 'string' }) } } self.assertTemplateEqual( 'api_method.j2', 'APIMethod.swift', { 'api': api, 'schema': schema, 'VIDEO_FIELD': Field.VIDEO, 'IMAGE_FIELD': Field.IMAGE, })
def test_swift_key_path(self): api = GetAPI("post/", { "response": { "200+": "$postResponse" } }) self.assertEqual(SwiftTemplateMethods.key_path(api), '"results"') api.resource_type = GetAPI.RESOURCE_DETAIL self.assertEqual(SwiftTemplateMethods.key_path(api), 'nil') api = GetAPI("post/:id/favorite/", { "response": { "200+": "$postResponse" } }) self.assertEqual(SwiftTemplateMethods.key_path(api), 'nil')
def test_create_get_api_detail_override(self): api = GetAPI("post/:id/favorites/", { "resource_type": "list", "response": { "200+": "$postResponse" } }) self.assertEqual(api.response_object, "$postResponse") self.assertEqual(api.resource_type, GetAPI.RESOURCE_LIST)
def test_create_get_api_detail(self): api = GetAPI("post/:id/", {"response": {"200+": "$postResponse"}}) self.assertEqual(api.response_object, "$postResponse") self.assertEqual(api.resource_type, GetAPI.RESOURCE_DETAIL)
def test_is_oauth(self): api = GetAPI("post/", {"response": {"200+": "$postResponse"}}) self.assertFalse(BaseTemplateMethods.is_oauth(api)) api.set_authorization({"#meta": API.OAUTH2}) self.assertTrue(BaseTemplateMethods.is_oauth(api))