コード例 #1
0
    def test_get_api_request_object(self):
        objects_json = {
            '$postRequest': {"body": "string", "title": "string"},
            '$postResponse': {"body": "string", "title": "string"}
        }
        urls_json = [
            {
                "url": "post/:id/favorites/",
                "patch": {
                    "request": "$postRequest",
                    "response": {
                        "200+": "$postResponse"
                    }
                }
            }
        ]
        schema = create_dynamic_schema(objects_json, urls_json)
        self.assertEqual(BaseTemplateMethods.get_api_request_object(schema.urls[0].patch),
                         schema.urls[0].patch.request_object)

        objects_json = {
            '$followResponse': {"body": "string", "title": "string"}
        }
        urls_json = [
            {
                "url": "follow/",
                "get": {
                    "response": {
                        "200+": "$followResponse"
                    }
                }
            }
        ]
        schema = create_dynamic_schema(objects_json, urls_json)
        self.assertIsNone(BaseTemplateMethods.get_api_request_object(schema.urls[0].get))
コード例 #2
0
ファイル: test_template.py プロジェクト: yeti/signals
 def test_methods_request_template_with_media_fields(self):
     objects_json = {
         '$postRequest': {
             'body': 'string',
             'title': 'string',
             'video': 'video',
             'thumbnail': 'image'
         },
         '$postResponse': {
             "body": "string",
             "title": "string"
         }
     }
     urls_json = [{
         "url": "post/",
         "post": {
             "request": "$postRequest",
             "response": {
                 "200+": "$postResponse"
             }
         }
     }]
     schema = create_dynamic_schema(objects_json, urls_json)
     self.assertTemplateEqual(
         'methods/request.j2', 'MethodRequestWithMediaFields.swift', {
             'api': schema.urls[0].post,
             'schema': schema,
             'VIDEO_FIELD': Field.VIDEO,
             'IMAGE_FIELD': Field.IMAGE,
         })
コード例 #3
0
ファイル: test_template.py プロジェクト: yeti/signals
 def test_methods_request_template(self):
     objects_json = {
         '$postRequest': {
             "body": "string",
             "title": "string"
         },
         '$postResponse': {
             "body": "string",
             "title": "string"
         }
     }
     urls_json = [{
         "url": "post/",
         "post": {
             "request": "$postRequest",
             "response": {
                 "200+": "$postResponse"
             }
         }
     }]
     schema = create_dynamic_schema(objects_json, urls_json)
     self.assertTemplateEqual(
         'methods/request.j2', 'MethodRequest.swift', {
             'api': schema.urls[0].post,
             'schema': schema,
             'VIDEO_FIELD': Field.VIDEO,
             'IMAGE_FIELD': Field.IMAGE,
         })
コード例 #4
0
ファイル: test_template.py プロジェクト: yeti/signals
 def test_methods_parameters_template(self):
     objects_json = {
         '$postResponse': {
             "body": "string",
             "title": "string"
         },
         "$postParameters": {
             'user_id': 'int',
             'title': 'string'
         }
     }
     urls_json = [{
         "url": "post/",
         "get": {
             "parameters": "$postParameters",
             "response": {
                 "200+": "$postResponse"
             }
         }
     }]
     schema = create_dynamic_schema(objects_json, urls_json)
     self.assertTemplateEqual('methods/parameters.j2',
                              'MethodParameters.swift', {
                                  'api': schema.urls[0].get,
                                  'schema': schema
                              })
コード例 #5
0
ファイル: test_template.py プロジェクト: brianleungwh/signals
 def test_methods_request_template_with_media_fields(self):
     objects_json = {
         '$postRequest': {
             'body': 'string',
             'title': 'string',
             'video': 'video',
             'thumbnail': 'image'
         },
         '$postResponse': {"body": "string", "title": "string"}
     }
     urls_json = [
         {
             "url": "post/",
             "post": {
                 "request": "$postRequest",
                 "response": {
                     "200+": "$postResponse"
                 }
             }
         }
     ]
     schema = create_dynamic_schema(objects_json, urls_json)
     self.assertTemplateEqual('methods/request.j2', 'MethodRequestWithMediaFields.swift', {
         'api': schema.urls[0].post,
         'schema': schema,
         'VIDEO_FIELD': Field.VIDEO,
         'IMAGE_FIELD': Field.IMAGE,
     })
コード例 #6
0
    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")
コード例 #7
0
    def test_get_api_request_object(self):
        objects_json = {
            '$postRequest': {
                "body": "string",
                "title": "string"
            },
            '$postResponse': {
                "body": "string",
                "title": "string"
            }
        }
        urls_json = [{
            "url": "post/:id/favorites/",
            "patch": {
                "request": "$postRequest",
                "response": {
                    "200+": "$postResponse"
                }
            }
        }]
        schema = create_dynamic_schema(objects_json, urls_json)
        self.assertEqual(
            BaseTemplateMethods.get_api_request_object(schema.urls[0].patch),
            schema.urls[0].patch.request_object)

        objects_json = {
            '$followResponse': {
                "body": "string",
                "title": "string"
            }
        }
        urls_json = [{
            "url": "follow/",
            "get": {
                "response": {
                    "200+": "$followResponse"
                }
            }
        }]
        schema = create_dynamic_schema(objects_json, urls_json)
        self.assertIsNone(
            BaseTemplateMethods.get_api_request_object(schema.urls[0].get))
コード例 #8
0
ファイル: test_template.py プロジェクト: yeti/signals
    def test_descriptors_request_template(self):
        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.assertTemplateEqual('descriptors/request.j2',
                                 'PatchRequestDescriptor.swift',
                                 {'api': schema.urls[0].patch})

        urls_json = [{
            "url": "post/",
            "post": {
                "request": "$postRequest",
                "response": {
                    "200+": "$postResponse"
                }
            }
        }]
        schema = create_dynamic_schema(objects_json, urls_json)
        self.assertTemplateEqual('descriptors/request.j2',
                                 'PostRequestDescriptor.swift',
                                 {'api': schema.urls[0].post})
コード例 #9
0
 def test_objective_c_method_parameters(self):
     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)
     parameter_signature = ObjectiveCTemplateMethods.method_parameters(schema.urls[0].patch)
     expected = (
         "(NSString*)body title:(NSString*)title theID:(NSNumber*)theID "
         "success:(void (^)(RKObjectRequestOperation *operation, RKMappingResult *mappingResult))success "
         "failure:(void (^)(RKObjectRequestOperation *operation, NSError *error))failure"
     )
     self.assertEqual(parameter_signature, expected)
コード例 #10
0
    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")
コード例 #11
0
ファイル: test_template.py プロジェクト: yeti/signals
    def test_descriptors_response_template(self):
        objects_json = {'$postResponse': {"body": "string", "title": "string"}}
        urls_json = [{
            "url": "post/",
            "get": {
                "response": {
                    "200+": "$postResponse"
                }
            }
        }]
        schema = create_dynamic_schema(objects_json, urls_json)

        self.assertTemplateEqual('descriptors/response.j2',
                                 'GetResponseDescriptor.swift',
                                 {'api': schema.urls[0].get})
コード例 #12
0
ファイル: test_template.py プロジェクト: brianleungwh/signals
    def test_descriptors_request_template(self):
        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.assertTemplateEqual('descriptors/request.j2', 'PatchRequestDescriptor.swift', {
            'api': schema.urls[0].patch
        })

        urls_json = [
            {
                "url": "post/",
                "post": {
                    "request": "$postRequest",
                    "response": {
                        "200+": "$postResponse"
                    }
                }
            }
        ]
        schema = create_dynamic_schema(objects_json, urls_json)
        self.assertTemplateEqual('descriptors/request.j2', 'PostRequestDescriptor.swift', {
            'api': schema.urls[0].post
        })
コード例 #13
0
 def test_generate_objc_relationship_parameters(self):
     schema = create_dynamic_schema({
         "$userRequest": {
             "username": "******",
             "profile": "O2O,$profileRequest",
             "tags": "M2M,$tagRequest"
         },
         "$profileRequest": {},
         "$tagRequest": {}
     }, [])
     request_object = schema.data_objects['$userRequest']
     parameters = ObjCParameter.generate_relationship_parameters(request_object)
     self.assertEqual(parameters[0].name, "profile")
     self.assertEqual(parameters[0].objc_type, "ProfileRequest")
     self.assertEqual(parameters[1].name, "tags")
     self.assertEqual(parameters[1].objc_type, "NSOrderedSet*")
コード例 #14
0
ファイル: test_parameters.py プロジェクト: yeti/signals
 def test_generate_objc_relationship_parameters(self):
     schema = create_dynamic_schema(
         {
             "$userRequest": {
                 "username": "******",
                 "profile": "O2O,$profileRequest",
                 "tags": "M2M,$tagRequest"
             },
             "$profileRequest": {},
             "$tagRequest": {}
         }, [])
     request_object = schema.data_objects['$userRequest']
     parameters = ObjCParameter.generate_relationship_parameters(
         request_object)
     self.assertEqual(parameters[0].name, "profile")
     self.assertEqual(parameters[0].objc_type, "ProfileRequest")
     self.assertEqual(parameters[1].name, "tags")
     self.assertEqual(parameters[1].objc_type, "NSOrderedSet*")
コード例 #15
0
ファイル: test_template.py プロジェクト: brianleungwh/signals
    def test_descriptors_response_template(self):
        objects_json = {
            '$postResponse': {"body": "string", "title": "string"}
        }
        urls_json = [
            {
                "url": "post/",
                "get": {
                    "response": {
                        "200+": "$postResponse"
                    }
                }
            }
        ]
        schema = create_dynamic_schema(objects_json, urls_json)

        self.assertTemplateEqual('descriptors/response.j2', 'GetResponseDescriptor.swift', {
            'api': schema.urls[0].get
        })
コード例 #16
0
ファイル: test_template.py プロジェクト: brianleungwh/signals
 def test_methods_parameters_template(self):
     objects_json = {
         '$postResponse': {"body": "string", "title": "string"},
         "$postParameters": {'user_id': 'int', 'title': 'string'}
     }
     urls_json = [
         {
             "url": "post/",
             "get": {
                 "parameters": "$postParameters",
                 "response": {
                     "200+": "$postResponse"
                 }
             }
         }
     ]
     schema = create_dynamic_schema(objects_json, urls_json)
     self.assertTemplateEqual('methods/parameters.j2', 'MethodParameters.swift', {
         'api': schema.urls[0].get,
         'schema': schema
     })
コード例 #17
0
 def test_swift_method_parameters(self):
     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)
     parameter_signature = SwiftTemplateMethods.method_parameters(schema.urls[0].patch)
     expected = "body: String, title: String, theID: Int, " \
                "success: RestKitSuccess, " \
                "failure: RestKitError"
     self.assertEqual(parameter_signature, expected)
コード例 #18
0
ファイル: test_template.py プロジェクト: brianleungwh/signals
 def test_methods_request_template(self):
     objects_json = {
         '$postRequest': {"body": "string", "title": "string"},
         '$postResponse': {"body": "string", "title": "string"}
     }
     urls_json = [
         {
             "url": "post/",
             "post": {
                 "request": "$postRequest",
                 "response": {
                     "200+": "$postResponse"
                 }
             }
         }
     ]
     schema = create_dynamic_schema(objects_json, urls_json)
     self.assertTemplateEqual('methods/request.j2', 'MethodRequest.swift', {
         'api': schema.urls[0].post,
         'schema': schema,
         'VIDEO_FIELD': Field.VIDEO,
         'IMAGE_FIELD': Field.IMAGE,
     })