def putnoise(self): self.logger.debug(f"Putting Noise {self.noise_key()} ...") session_id = self.init_user() try: assert session_id except AssertionError: raise enochecker.BrokenServiceException("session_id could not be set.") if self.flag_idx % 2 == 0: payload = {'msg': self.noise_key(), 'state': json.dumps( {'mode': 'alarm', 'alarm_time': f"{random.randint(0, 23)}:{random.randint(0, 59)}"})} self.call_bot_response(payload, mode='alarm noise') payment_payload = {'state': json.dumps({'mode': 'alarm', 'payment': 'pending'}), 'msg': random.choice(['room-bill', 'cash'])} self.call_bot_response(payment_payload, mode='alarm noise payment') self.team_db[self.noise_key()] = (session_id,) else: payload = {'msg': self.noise_key(), 'state': json.dumps( {'mode': 'food_order', 'order_step': '2', 'order': random.choice(AVAILABLE_FOOD)})} message = self.call_bot_response(payload, mode='invoice noise') invoice_number = re.findall('invoice number is (\d*)', message) if len(invoice_number) != 1: return enochecker.Result.MUMBLE else: invoice_number = invoice_number[0] self.team_db[self.noise_key()] = (session_id, invoice_number)
def check_invoice_number(self, invoice_number, session_id, expected_text): self.http_session.cookies.set('session_id', session_id) payload = { 'state': json.dumps({'mode': 'invoice_info'}), 'msg': invoice_number } try: req = self.http_get('/get_bot_response', params=payload) except exceptions.RequestException: self.logger.debug( f"Could not get bot response. Payload: {payload}") raise enochecker.BrokenServiceException( "Could not check invoice number. Seems like the service is broken." ) enochecker.assert_equals( 200, req.status_code, "The request did not return with the expected response code. Verify, that the invoice service is returning the desired response." ) data = req.json() parsed_response = data['response'].replace('\\u200d', '\u200d') self.logger.debug( f"expected text: {expected_text}, data: {parsed_response}") enochecker.assert_in(expected_text, data['response'].replace('\\u200d', '\u200d'), f"Could not find expected invoice in response.")
def request_bill(self): payload = {'msg': 'y', 'state': json.dumps({'mode': 'invoice', 'invoice_step': '1'})} try: response = self.http_get("/get_bot_response", params=payload) except exceptions.RequestException: self.logger.debug(f"Could not request bill. Payload: {payload}") raise enochecker.BrokenServiceException("Could not request bill.") return response.text
def call_bot_response(self, payload, mode): self.logger.debug(f"Putting {mode}...") try: response = self.http_get("/get_bot_response", params=payload) except exceptions.RequestException: self.logger.debug(f"Could not get bot response. Payload: {payload}") raise enochecker.BrokenServiceException("Could not get bot response.") return response.text