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()