def execute(self, reporter): spec = self.spec if len(spec.assertions) == 0: # TODO: Reporter should say "zero assertions found / specified" return False # TODO: assert / tests the request happened without exceptions # act on __exit__ codes # with Assertion("response", spec.assertions, "http response", reporter) as a: if spec.body: response = requests.request(spec.method, spec.url, headers=spec.headers, data=spec.body) else: response = requests.request(spec.method, spec.url, headers=spec.headers) assertions = [] with Assertion("status_code", spec.assertions, "http response status_code", reporter) as a: assertions.append(a) a.actual_value = response.status_code with Assertion("body", spec.assertions, "http response body", reporter) as a: # a.result = event.json_deep_equals(a.expected, response.content) assertions.append(a) a.actual_value = response.content # TODO: depricate this, not functioally needed anymore return all([a.passed() for a in assertions])
def simulate(self, spec, reporter): kafka = KafkaConn() kafka.init_producer() with Assertion("events_produced", spec.assertions, "produced a event", reporter) as a: send = 0 for event in spec.events: kafka.produce_message(spec.topic, event) send += 1 a.actual_value = send
def validate(self, spec, reporter): kafka = KafkaConn() kafka.check_connection() consumed = kafka.consume(spec.topic, spec.assertions.get("timeout_after", 2.0)) with Assertion("total_events", spec.assertions, "total amount of received events", reporter) as a: # should not be needed to keep track here # assertions.append(a) a.actual_value = len(consumed) with UnorderedDiffAssertion("unordered", spec.assertions, "unordered events", reporter) as a: a.actual_value = consumed
def assertion(self, field, spec): return Assertion(field, spec, self)