Permalink
Browse files

Added new testcases to get the 100% coverage

  • Loading branch information...
1 parent 7137d13 commit 910568726123b75820b30bfd302999c5a993868e @bulkan committed Aug 31, 2011
Showing with 34 additions and 31 deletions.
  1. +2 −0 .gitignore
  2. +10 −30 src/RequestsLibrary.py
  3. +22 −1 tests/testcase.txt
View
@@ -9,6 +9,8 @@ debug.txt
report.html
~*
.DS_Store
+htmlcov
+.coverage
build/
@@ -69,15 +69,12 @@ def get(self, alias, uri, headers=None):
return resp
- def post(self, alias, uri, data=None, headers=None):
+ def post(self, alias, uri, data=(), headers=None):
''' Post: send a POST request on the session object found using the given alias
'''
- if data:
- data = urlencode(data)
-
session = self._cache.switch(alias)
- resp = session.post(uri, data=data, headers=headers)
+ resp = session.post(uri, data=urlencode(data), headers=headers)
# store the last response object
session.last_resp = resp
@@ -97,12 +94,12 @@ def put(self, alias, uri, data=None, headers=None):
return resp
- def delete(self, alias, uri, headers=None):
+ def delete(self, alias, uri, data=(), headers=None):
''' Delete: send a DELETE request on the session object found using the given alias
'''
session = self._cache.switch(alias)
- resp = session.delete(uri, headers=headers)
+ resp = session.delete("%s?%s" %(uri, urlencode(data)), headers=headers)
# store the last response object
session.last_resp = resp
@@ -120,27 +117,10 @@ def head(self, alias, uri, headers=None):
session.last_resp = resp
return resp
-
-
-if __name__ == '__main__':
- rl = RequestsLibrary()
- session = rl.create_session('github', 'http://github.com/api/v2/json')
- #resp = rl.get('github', '/user/search/bulkan')
- #jsondata = rl.to_json(resp.content)
-
-
- auth = ('user', 'passwd')
- session = rl.create_session('httpbin', 'http:/httpbin.org', auth=auth)
- resp = rl.get('httpbin', '/basic-auth/user/passwd')
- import pdb; pdb.set_trace()
-
-
-
- #with requests.session(auth=auth) as c:
- # resp = c.get('http://httpbin.org/basic-auth/user/passwd')
- # print resp
-
-
-
- # sometimes you just need pdb
+#if __name__ == '__main__':
+# rl = RequestsLibrary()
+# session = rl.create_session('github', 'http://github.com/api/v2/json')
+# auth = ('user', 'passwd')
+# session = rl.create_session('httpbin', 'http:/httpbin.org', auth=auth)
+# resp = rl.get('httpbin', '/basic-auth/user/passwd')
View
@@ -28,6 +28,12 @@ Get With Auth
Should Be Equal As Strings ${jsondata['authenticated']} True
+Post Request With No Data
+ Create Session httpbin http://httpbin.org
+ ${resp} Post httpbin /post
+ Should Be Equal As Strings ${resp.status_code} 200
+
+
Post Requests
Create Session httpbin http://httpbin.org
@@ -39,7 +45,6 @@ Post Requests
Dictionary Should Contain Value ${jsondata['form']} evcimen
-
Put Requests
Create Session httpbin http://httpbin.org
@@ -55,3 +60,19 @@ Head Request
Create Session httpbin http://httpbin.org
${resp} Head httpbin /headers
Should Be Equal As Strings ${resp.status_code} 200
+
+
+Delete Request With No Data
+ Create Session httpbin http://httpbin.org
+ ${resp} Delete httpbin /delete
+ Should Be Equal As Strings ${resp.status_code} 200
+
+
+Delete Request With Data
+ Create Session httpbin http://httpbin.org
+ ${data} Create Dictionary name bulkan surname evcimen
+ ${resp} Delete httpbin /delete data=${data}
+ Should Be Equal As Strings ${resp.status_code} 200
+ ${jsondata}= To Json ${resp.content}
+ Dictionary Should Contain Value ${jsondata['args']} bulkan
+ Dictionary Should Contain Value ${jsondata['args']} evcimen

0 comments on commit 9105687

Please sign in to comment.