Azul | e297254 | 2015-03-29 14:06:28 +0100 | [diff] [blame^] | 1 | from lettuce import step, world |
| 2 | import requests |
| 3 | import os |
| 4 | |
| 5 | endpoint = "http://%s:5000" % os.environ['BOOT2DOCKERIP'] |
| 6 | |
| 7 | |
| 8 | @step("I create a new topic using POST /(.*)") |
| 9 | def create_topic(step, topic): |
| 10 | world.message_response = requests.post( |
| 11 | '%s/%s' % (endpoint, topic), data='subscribe') |
| 12 | assert world.message_response.status_code == 200, \ |
| 13 | "Got %s" % world.message_response.status_code |
| 14 | |
| 15 | |
| 16 | @step("I publish a message '(.*)' with a POST /(.*)") |
| 17 | def publish(step, message, topic): |
| 18 | world.message_response = requests.post( |
| 19 | '%s/%s' % (endpoint, topic), data=message) |
| 20 | assert world.message_response.status_code == 200, \ |
| 21 | "Got %s" % world.message_response.status_code |
| 22 | |
| 23 | |
| 24 | @step("I subscribe using POST /(.*)/(.*)") |
| 25 | def subscribe(step, topic, user): |
| 26 | world.message_response = requests.post( |
| 27 | '%s/%s/%s' % (endpoint, topic, user)) |
| 28 | assert world.message_response.status_code == 200, \ |
| 29 | "Got %s" % world.message_response.status_code |
| 30 | |
| 31 | |
| 32 | @step("I unsubscribe using DELETE /(.*)/(.*)") |
| 33 | def unsubscribe(step, topic, user): |
| 34 | world.message_response = requests.delete( |
| 35 | '%s/%s/%s' % (endpoint, topic, user)) |
| 36 | |
| 37 | |
| 38 | @step("get new messages using GET /(.*)/(.*)") |
| 39 | def read_next(step, topic, user): |
| 40 | world.message_response = requests.get( |
| 41 | '%s/%s/%s' % (endpoint, topic, user)) |
| 42 | |
| 43 | |
| 44 | @step("discard the first 'subscribe' message from /(.*)/(.*)") |
| 45 | def discard_next(step, topic, user): |
| 46 | world.message_response = requests.get( |
| 47 | '%s/%s/%s' % (endpoint, topic, user)) |
| 48 | |
| 49 | |
| 50 | @step("I should get a (.*) back") |
| 51 | def check_message_http_code(step, expected): |
| 52 | assert world.message_response.status_code == int(expected), \ |
| 53 | "Got %s" % world.message_response.status_code |
| 54 | |
| 55 | |
| 56 | @step("I should see '(.*)' in the body of the message") |
| 57 | def check_message_body(step, expected): |
| 58 | assert world.message_response.content == expected, \ |
| 59 | "Got %s" % world.message_response.content |
| 60 | |
| 61 | |
| 62 | @step("I should receive nothing") |
| 63 | def check_that_I_receive_nothing(step): |
| 64 | assert world.message_response.content == '', \ |
| 65 | "Got %s" % world.message_response.content |
| 66 | |
| 67 | |
| 68 | @step("The subscription does not exist") |
| 69 | def pass_the_subscription_does_not_exist(step): |
| 70 | pass |
| 71 | |