Add test coverage for construction of request body via AFHTTPClient. refs #989
This commit is contained in:
parent
bb4c19eab6
commit
5c81d90a4c
4 changed files with 81 additions and 39 deletions
|
|
@ -1,24 +0,0 @@
|
|||
//
|
||||
// AFHTTPClientTest.m
|
||||
// AFNetworking
|
||||
//
|
||||
// Created by Blake Watters on 5/10/13.
|
||||
// Copyright (c) 2013 AFNetworking. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AFNetworkingTests.h"
|
||||
|
||||
@interface AFHTTPClientTest : SenTestCase
|
||||
@end
|
||||
|
||||
@implementation AFHTTPClientTest
|
||||
|
||||
- (void)testThatTheDefaultStringEncodingIsUTF8
|
||||
{
|
||||
AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:AFNetworkingTestsBaseURLString]];
|
||||
expect(client.stringEncoding).to.equal(NSUTF8StringEncoding);
|
||||
}
|
||||
|
||||
// default value for header
|
||||
|
||||
@end
|
||||
66
Tests/AFHTTPClientTests.m
Normal file
66
Tests/AFHTTPClientTests.m
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
//
|
||||
// AFHTTPClientTests.m
|
||||
// AFNetworking
|
||||
//
|
||||
// Created by Blake Watters on 5/10/13.
|
||||
// Copyright (c) 2013 AFNetworking. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AFNetworkingTests.h"
|
||||
|
||||
@interface AFHTTPClientTests : SenTestCase
|
||||
@end
|
||||
|
||||
@implementation AFHTTPClientTests
|
||||
|
||||
- (void)testThatTheDefaultStringEncodingIsUTF8
|
||||
{
|
||||
AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:AFNetworkingTestsBaseURLString]];
|
||||
expect(client.stringEncoding).to.equal(NSUTF8StringEncoding);
|
||||
}
|
||||
|
||||
- (void)testConstructingPOSTRequestWithParametersInFormURLParameterEncoding
|
||||
{
|
||||
AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:AFNetworkingTestsBaseURLString]];
|
||||
client.parameterEncoding = AFFormURLParameterEncoding;
|
||||
NSMutableURLRequest *request = [client requestWithMethod:@"POST" path:@"/post" parameters:@{ @"key": @"value" }];
|
||||
NSString *requestBody = [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding];
|
||||
expect(requestBody).to.equal(@"key=value");
|
||||
}
|
||||
|
||||
- (void)testConstructingPOSTRequestWithParametersInJSONParameterEncoding
|
||||
{
|
||||
AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:AFNetworkingTestsBaseURLString]];
|
||||
client.parameterEncoding = AFJSONParameterEncoding;
|
||||
NSMutableURLRequest *request = [client requestWithMethod:@"POST" path:@"/post" parameters:@{ @"key": @"value" }];
|
||||
NSString *requestBody = [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding];
|
||||
expect(requestBody).to.equal(@"{\"key\":\"value\"}");
|
||||
}
|
||||
|
||||
- (void)testConstructingPOSTRequestWithParametersInPropertyListParameterEncoding
|
||||
{
|
||||
AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:AFNetworkingTestsBaseURLString]];
|
||||
client.parameterEncoding = AFPropertyListParameterEncoding;
|
||||
NSMutableURLRequest *request = [client requestWithMethod:@"POST" path:@"/post" parameters:@{ @"key": @"value" }];
|
||||
NSString *requestBody = [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding];
|
||||
expect(requestBody).to.equal(@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n <key>key</key>\n <string>value</string>\n</dict>\n</plist>\n");
|
||||
}
|
||||
|
||||
- (void)testPostWithParameters
|
||||
{
|
||||
__block id blockResponseObject = nil;
|
||||
AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:AFNetworkingTestsBaseURLString]];
|
||||
[client postPath:@"/post" parameters:@{ @"key": @"value" } success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
||||
blockResponseObject = responseObject;
|
||||
} failure:nil];
|
||||
expect([client.operationQueue operationCount]).will.equal(0);
|
||||
expect(blockResponseObject).notTo.beNil();
|
||||
expect(blockResponseObject).to.beKindOf([NSData class]);
|
||||
NSError *error = nil;
|
||||
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:blockResponseObject options:0 error:&error];
|
||||
expect(responseDictionary[@"form"]).to.equal(@{ @"key": @"value" });
|
||||
}
|
||||
|
||||
// default value for header
|
||||
|
||||
@end
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// AFHTTPRequestOperationTest.m
|
||||
// AFHTTPRequestOperationTests.m
|
||||
// AFNetworking
|
||||
//
|
||||
// Created by Blake Watters on 5/10/13.
|
||||
|
|
@ -8,10 +8,10 @@
|
|||
|
||||
#import "AFNetworkingTests.h"
|
||||
|
||||
@interface AFHTTPRequestOperationTest : SenTestCase
|
||||
@interface AFHTTPRequestOperationTests : SenTestCase
|
||||
@end
|
||||
|
||||
@implementation AFHTTPRequestOperationTest
|
||||
@implementation AFHTTPRequestOperationTests
|
||||
|
||||
- (void)testThatOperationInvokesSuccessCompletionBlockWithResponseObjectOnSuccess
|
||||
{
|
||||
|
|
@ -13,10 +13,10 @@
|
|||
2544EC48173BE382004117E8 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2544EC35173BE382004117E8 /* Foundation.framework */; };
|
||||
2544EC96173BFAA8004117E8 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2544EC44173BE382004117E8 /* SenTestingKit.framework */; };
|
||||
2544EC97173BFAA8004117E8 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2544EC80173BFAA8004117E8 /* Cocoa.framework */; };
|
||||
25801540173EB3A70026AA6E /* AFHTTPClientTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 2580153A173EB3A70026AA6E /* AFHTTPClientTest.m */; };
|
||||
25801541173EB3A70026AA6E /* AFHTTPClientTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 2580153A173EB3A70026AA6E /* AFHTTPClientTest.m */; };
|
||||
25801542173EB3A70026AA6E /* AFHTTPRequestOperationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 2580153B173EB3A70026AA6E /* AFHTTPRequestOperationTest.m */; };
|
||||
25801543173EB3A70026AA6E /* AFHTTPRequestOperationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 2580153B173EB3A70026AA6E /* AFHTTPRequestOperationTest.m */; };
|
||||
25801540173EB3A70026AA6E /* AFHTTPClientTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2580153A173EB3A70026AA6E /* AFHTTPClientTests.m */; };
|
||||
25801541173EB3A70026AA6E /* AFHTTPClientTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2580153A173EB3A70026AA6E /* AFHTTPClientTests.m */; };
|
||||
25801542173EB3A70026AA6E /* AFHTTPRequestOperationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2580153B173EB3A70026AA6E /* AFHTTPRequestOperationTests.m */; };
|
||||
25801543173EB3A70026AA6E /* AFHTTPRequestOperationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2580153B173EB3A70026AA6E /* AFHTTPRequestOperationTests.m */; };
|
||||
25801546173EB3A70026AA6E /* AFNetworkingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2580153F173EB3A70026AA6E /* AFNetworkingTests.m */; };
|
||||
25801547173EB3A70026AA6E /* AFNetworkingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2580153F173EB3A70026AA6E /* AFNetworkingTests.m */; };
|
||||
2580154B173EB62E0026AA6E /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 25C4EC2A173D7DB30083E116 /* SystemConfiguration.framework */; };
|
||||
|
|
@ -54,8 +54,8 @@
|
|||
2544EC84173BFAA8004117E8 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
|
||||
2544EC85173BFAA8004117E8 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
|
||||
2544EC95173BFAA8004117E8 /* OS X Tests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "OS X Tests.octest"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
2580153A173EB3A70026AA6E /* AFHTTPClientTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFHTTPClientTest.m; sourceTree = "<group>"; };
|
||||
2580153B173EB3A70026AA6E /* AFHTTPRequestOperationTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFHTTPRequestOperationTest.m; sourceTree = "<group>"; };
|
||||
2580153A173EB3A70026AA6E /* AFHTTPClientTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFHTTPClientTests.m; sourceTree = "<group>"; };
|
||||
2580153B173EB3A70026AA6E /* AFHTTPRequestOperationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFHTTPRequestOperationTests.m; sourceTree = "<group>"; };
|
||||
2580153E173EB3A70026AA6E /* AFNetworkingTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFNetworkingTests.h; sourceTree = "<group>"; };
|
||||
2580153F173EB3A70026AA6E /* AFNetworkingTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFNetworkingTests.m; sourceTree = "<group>"; };
|
||||
25801549173EB4B40026AA6E /* Pods-ios.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = "Pods-ios.xcconfig"; path = "Pods/Pods-ios.xcconfig"; sourceTree = "<group>"; };
|
||||
|
|
@ -199,8 +199,8 @@
|
|||
25801548173EB3B00026AA6E /* Tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2580153A173EB3A70026AA6E /* AFHTTPClientTest.m */,
|
||||
2580153B173EB3A70026AA6E /* AFHTTPRequestOperationTest.m */,
|
||||
2580153A173EB3A70026AA6E /* AFHTTPClientTests.m */,
|
||||
2580153B173EB3A70026AA6E /* AFHTTPRequestOperationTests.m */,
|
||||
2580153E173EB3A70026AA6E /* AFNetworkingTests.h */,
|
||||
2580153F173EB3A70026AA6E /* AFNetworkingTests.m */,
|
||||
);
|
||||
|
|
@ -333,8 +333,8 @@
|
|||
25DE601A173EB13C00422571 /* AFURLConnectionOperation.m in Sources */,
|
||||
25DE601C173EB13C00422571 /* AFXMLRequestOperation.m in Sources */,
|
||||
25DE601E173EB13C00422571 /* UIImageView+AFNetworking.m in Sources */,
|
||||
25801540173EB3A70026AA6E /* AFHTTPClientTest.m in Sources */,
|
||||
25801542173EB3A70026AA6E /* AFHTTPRequestOperationTest.m in Sources */,
|
||||
25801540173EB3A70026AA6E /* AFHTTPClientTests.m in Sources */,
|
||||
25801542173EB3A70026AA6E /* AFHTTPRequestOperationTests.m in Sources */,
|
||||
25801546173EB3A70026AA6E /* AFNetworkingTests.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
@ -352,8 +352,8 @@
|
|||
25DE601B173EB13C00422571 /* AFURLConnectionOperation.m in Sources */,
|
||||
25DE601D173EB13C00422571 /* AFXMLRequestOperation.m in Sources */,
|
||||
25DE601F173EB13C00422571 /* UIImageView+AFNetworking.m in Sources */,
|
||||
25801541173EB3A70026AA6E /* AFHTTPClientTest.m in Sources */,
|
||||
25801543173EB3A70026AA6E /* AFHTTPRequestOperationTest.m in Sources */,
|
||||
25801541173EB3A70026AA6E /* AFHTTPClientTests.m in Sources */,
|
||||
25801543173EB3A70026AA6E /* AFHTTPRequestOperationTests.m in Sources */,
|
||||
25801547173EB3A70026AA6E /* AFNetworkingTests.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue