def test_perform_delete_action(): fake_payload["text"] = ["delete 2019-01-01"] fake_payload["user_name"] = "fake_username" action = Action(fake_payload, fake_config) when(action).send_response(message="").thenReturn() assert action.perform_action() == "" unstub()
def test_perform_edit_action(): fake_payload["text"] = ["edit fake argument"] action = Action(fake_payload, fake_config) when(action).send_response( message="Edit not implemented yet").thenReturn("") assert action.perform_action() == "" unstub()
def test_perform_help_action(): fake_payload["text"] = ["help"] fake_payload["user_name"] = "fake_username" action = Action(fake_payload, fake_config) when(action).send_response( message=action.perform_action.__doc__).thenReturn("") assert action.perform_action() == "" unstub()
def test_perform_empty_action(): fake_payload.pop("text", None) fake_payload["user_name"] = "fake_username" action = Action(fake_payload, fake_config) when(action).send_response( message=action.perform_action.__doc__).thenReturn("") assert action.perform_action() == "" assert action.action == "help" unstub()
def index(): req = app.current_request.raw_body.decode() req_headers = app.current_request.headers if not verify_token(req_headers, req, config['signing_secret']): return 'Slack signing secret not valid' payload = slack_payload_extractor(req) logger.info(f'payload is: {payload}') action = Action(payload, config) action.perform_action() return ''
def test_perform_list_action(): fake_payload["text"] = ["list"] fake_payload["user_name"] = "fake_username" action = Action(fake_payload, fake_config) when(action).send_response(message="fake list output").thenReturn("") when(requests).get( url=f"{fake_config['backend_url']}/event/users/fake_userid", params={ "startDate": datetime.now().strftime("%Y-%m-01"), "endDate": datetime.now().strftime("%Y-%m-31"), }).thenReturn(mock({ "status_code": 200, "text": "fake list output" })) assert action.perform_action() == "" unstub()
def _handle_message(payload): action_instance = Action.create(payload, config) if action_instance.is_valid(): send_message( config["enable_queue"], config["command_queue"], payload, command_handler, )
def test_perform_lock(): fake_payload["text"] = ["lock 2019-01"] action = Action(fake_payload, fake_config) action.user_id = "fake_userid" when(action).send_response( message='Lock successful! :lock: :+1:').thenReturn() when(requests).post( url=f"{fake_config['backend_url']}/lock", data=json.dumps({ 'user_id': 'fake_userid', 'event_date': '2019-01' }), headers={ 'Content-Type': 'application/json' }, ).thenReturn(mock({"status_code": 200})) assert action.perform_action() == "" unstub()
def test_perform_lock_check(): fake_payload["text"] = ["fake"] action = Action(fake_payload, fake_config) action.user_id = "fake_user" action.date_start = "2019-01-01" action.date_end = "2019-01-02" when(requests).get( url=f"{fake_config['backend_url']}/event/users/{action.user_id}", params={ "startDate": action.date_start, "endDate": action.date_end, }).thenReturn(mock({ "status_code": 200, "text": '[{"lock":false}]' })) test = action.check_lock_state() assert test is False unstub()
def test_perform_add_action(): fake_payload["text"] = ["add vab 2019-01-01"] fake_payload["user_name"] = "fake username" action = Action(fake_payload, fake_config) action.user_id = "fake_userid" action.date_start = "2019-01-01" action.date_end = "2019-01-01" when(action).send_response(message="").thenReturn() when(requests).get( url=f"{fake_config['backend_url']}/event/users/{action.user_id}", params={ "startDate": action.date_start, "endDate": action.date_end, }).thenReturn(mock({ "status_code": 200, "text": '[{"lock": false}]' })) assert action.perform_action() == "" unstub()
def interactive_handler(event): for record in event: action = Action.create(json.loads(record.body), config) action.perform_interactive()
def command_handler(event): for record in event: action = Action.create(json.loads(record.body), config) action.perform_action()
def test_valid_number_of_args(): fake_action = Action(fake_payload, fake_config) fake_action.arguments = ["fake_arg_1"] # Should be valid since we have provided the minimum amount fake_action.min_arguments = 1 fake_action.max_arguments = 1 assert fake_action.is_valid() is True fake_action.arguments.append("fake_arg_2") # Should be valid since we have provided the miniumum and maxiumum amount fake_action.min_arguments = 1 fake_action.max_arguments = 2 assert fake_action.is_valid() is True # Should be false since we don't have the minimum amount fake_action.min_arguments = 3 fake_action.max_arguments = 3 assert fake_action.is_valid() is False # Should be false since we don't have the maximum amount fake_action.min_arguments = 1 fake_action.max_arguments = 1 assert fake_action.is_valid() is False
def test_perform_unsupported_action(): action = Action(fake_payload, fake_config) when(action).send_response( message="Unsupported action: unsupported").thenReturn("") assert action.perform_action() == "" unstub()