Skip to content

Commit

Permalink
Replace httpstat.us with local mock server
Browse files Browse the repository at this point in the history
  • Loading branch information
peritus committed Aug 13, 2011
1 parent 022964f commit 104a2e1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 28 deletions.
25 changes: 25 additions & 0 deletions tests/mockserver.py
@@ -0,0 +1,25 @@
#!/usr/bin/env python

import BaseHTTPServer

class WebRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/200':
self.send_response(200, "OK")
elif self.path == '/302':
self.send_response(302, "Redirect")
self.send_header('Location', '/200')
self.end_headers()
elif self.path == '/404':
self.send_response(404, "Not Found")
elif self.path == '/418':
self.send_response(418, "I'm a teapot")
elif self.path == '/503':
self.send_response(503, "Some error")
else:
self.send_error(500)

server = BaseHTTPServer.HTTPServer(('localhost', 36503), WebRequestHandler)
server.serve_forever()

print 'Listening on http://localhost:36503/'
65 changes: 37 additions & 28 deletions tests/simple.txt
@@ -1,6 +1,13 @@
*** Setting ***

Library robotframework_httplib.HTTP
Library OperatingSystem

Suite Setup Start Mockserver

*** Variables ***

${HOST} localhost:36503

*** Test Cases ***

Expand All @@ -9,91 +16,93 @@ Error if GET before connect
Should Start With ${msg} Not connected to any HTTP Host

Test Should Work
[Setup] Connect httpstat.us
[Setup] Connect ${HOST}
GET /

GET 200
[Setup] Connect httpstat.us
GET /200
Response Status Code Should Equal 200

GET 200, Port 80
[Setup] Connect httpstat.us:80
[Setup] Connect ${HOST}
GET /200
Response Status Code Should Equal 200

GET 302
[Setup] Connect httpstat.us
[Setup] Connect ${HOST}
GET /302
Response Status Code Should Equal 302

GET 302 with follow
[Setup] Connect httpstat.us
[Setup] Connect ${HOST}
GET /302
Follow Response
Response Status Code Should Equal 200

GET 418
[Setup] Connect httpstat.us
[Setup] Connect ${HOST}
GET /418
Response Status Code Should Equal 418 Unknown Error
Response Status Code Should Equal 418 I'm a teapot

Response Should Succeed OK
[Setup] Connect httpstat.us
[Setup] Connect ${HOST}
GET /200
Response Should Succeed

Response Should Succeed FAIL
[Setup] Connect httpstat.us
[Setup] Connect ${HOST}
GET /404
Run Keyword And Expect Error * Response Should Succeed

Response Should Not Succeed OK
[Setup] Connect httpstat.us
[Setup] Connect ${HOST}
GET /503
Response Should Not Succeed

Response Should Not Succeed FAIL
[Setup] Connect httpstat.us
GET /201
[Setup] Connect ${HOST}
GET /200
Run Keyword And Expect Error * Response Should Not Succeed

Response Should Have Header OK
[Setup] Connect httpstat.us
[Setup] Connect ${HOST}
GET /302
Response Should Have Header Location

Response Should Have Header FAIL
[Setup] Connect httpstat.us
[Setup] Connect ${HOST}
GET /200
Run Keyword And Expect Error * Response Should Have Header Krytzmyk

Response Should Not Have Header OK
[Setup] Connect httpstat.us
[Setup] Connect ${HOST}
GET /404
Response Should Not Have Header Location

Response Should Not Have Header FAIL
[Setup] Connect httpstat.us
[Setup] Connect ${HOST}
GET /302
Run Keyword And Expect Error * Response Should Not Have Header Location

Response Header Should Equal OK
[Setup] Connect httpstat.us
[Setup] Connect ${HOST}
GET /302
Response Header Should Equal Location http://httpstat.us
Response Header Should Equal Location /200

Response Header Should Equal FAIL
[Setup] Connect httpstat.us
[Setup] Connect ${HOST}
GET /302
Run Keyword And Expect Error * Response Header Should Equal Location http://some.other.host/

Response Header Should Not Equal OK
[Setup] Connect httpstat.us
GET /302
[Setup] Connect ${HOST}
GET /302
Response Header Should Not Equal Location http://and.another.host/

Response Header Should Not Equal FAIL
[Setup] Connect httpstat.us
GET /302
Run Keyword And Expect Error * Response Header Should Not Equal Location http://httpstat.us
[Setup] Connect ${HOST}
GET /302
Run Keyword And Expect Error * Response Header Should Not Equal Location /200


*** Keywords ***

Start Mockserver
Start Process tests/mockserver.py
Sleep 0.2

0 comments on commit 104a2e1

Please sign in to comment.