class When_a_message_is_posted_without_password: stream = str(uuid4()) event_id = str(uuid4()) _host = 'fakehost' _port = 42 _username = '******' def given_a_publisher(self): self.publisher = EventPublisher(self._host, self._port, self._username, None) @httpretty.activate def because_an_event_is_published_on_a_stream(self): httpretty.register_uri(httpretty.POST, "http://{}:{}/streams/{}".format( self._host, self._port, self.stream), body='{}') data = {'foo': 'bar'} metadata = {'lorem': 'ipsum'} evt = Event(self.event_id, 'my-event-type', data, self.stream, None, metadata) self.publisher.post(evt) self.response_body = json.loads( httpretty.last_request().body.decode())[0] def request_should_not_have_auth_in_headers(self): headers = httpretty.last_request().headers assert 'Authorization' not in headers
class When_a_message_is_posted_to_eventstore: stream = str(uuid4()) event_id = str(uuid4()) correlation_id = str(uuid4()) _host = 'localhost' _port = 2113 def given_a_publisher(self): self.publisher = EventPublisher(self._host, self._port) @httpretty.activate def because_an_event_is_published_on_a_stream(self): httpretty.register_uri(httpretty.POST, "http://{}:{}/streams/{}".format( self._host, self._port, self.stream), body='{}') data = {'foo': 'bar'} metadata = {'lorem': 'ipsum'} evt = Event( id=self.event_id, type='my-event-type', data=data, stream=self.stream, sequence=None, metadata=metadata, ) self.publisher.post(evt, correlation_id=self.correlation_id) self.response_body = json.loads( httpretty.last_request().body.decode())[0] def it_should_be_a_POST(self): assert (httpretty.last_request().method == "POST") def it_should_have_sent_the_correct_id(self): assert (self.response_body["eventId"] == self.event_id) def it_should_have_sent_the_correct_type(self): assert (self.response_body["eventType"] == 'my-event-type') def it_should_have_sent_the_correct_body(self): assert (self.response_body["data"] == { "foo": "bar", "correlation_id": self.correlation_id }) def it_should_have_sent_the_correct_metadata(self): assert (self.response_body["metadata"] == {"lorem": "ipsum"})
class When_a_message_is_posted: stream = str(uuid4()) event_id = str(uuid4()) class TestConfig: def __init__(self, host, port): self.host = host self.port = port def given_a_publisher(self): cfg = When_a_message_is_posted.TestConfig('fakehost', '42') self.publisher = EventPublisher(cfg.host, cfg.port) @httpretty.activate def because_an_event_is_published_on_a_stream(self): httpretty.register_uri(httpretty.POST, "http://fakehost:42/streams/{}".format( self.stream), body='{}') data = {'foo': 'bar'} evt = Event(self.event_id, 'my-event-type', data, self.stream, None) self.publisher.post(evt) def it_should_be_a_POST(self): assert (httpretty.last_request().method == "POST") def it_should_have_sent_the_correct_id(self): assert ( httpretty.last_request().headers['ES-EventId'] == self.event_id) def it_should_have_sent_the_correct_type(self): assert (httpretty.last_request().headers['ES-EventType'] == 'my-event-type') def it_should_have_sent_the_correct_body(self): assert (httpretty.last_request().body == b'{"foo": "bar"}')
class When_a_message_is_posted: stream = str(uuid4()) event_id = str(uuid4()) class TestConfig: def __init__(self, host, port): self.host = host self.port = port def given_a_publisher(self): cfg = When_a_message_is_posted.TestConfig('fakehost', '42') self.publisher = EventPublisher(cfg.host, cfg.port) @httpretty.activate def because_an_event_is_published_on_a_stream(self): httpretty.register_uri( httpretty.POST, "http://fakehost:42/streams/{}".format(self.stream), body='{}') data = {'foo': 'bar'} evt = Event(self.event_id, 'my-event-type', data, self.stream, None) self.publisher.post(evt) def it_should_be_a_POST(self): assert(httpretty.last_request().method == "POST") def it_should_have_sent_the_correct_id(self): assert(httpretty.last_request().headers['ES-EventId'] == self.event_id) def it_should_have_sent_the_correct_type(self): assert(httpretty.last_request().headers['ES-EventType'] == 'my-event-type') def it_should_have_sent_the_correct_body(self): assert(httpretty.last_request().body == b'{"foo": "bar"}')