def test_create_user_fails_when_no_role_given(kentik_api) -> None: user = User(email="*****@*****.**", email_service=True, email_product=True) with pytest.raises(AssertionError, match="User role has to be provided"): kentik_api.users.create(user)
def test_create_user_success(client, connector) -> None: # given create_response_payload = """ { "user": { "id":"145985", "username":"******", "user_full_name":"Test User", "user_email":"*****@*****.**", "role":"Member", "email_service":"true", "email_product":"true", "last_login":null, "created_date":"2020-12-09T14:33:28.330Z", "updated_date":"2020-12-09T14:33:28.369Z", "company_id":"74333", "user_api_token":null, "filters":{}, "saved_filters":[] } }""" connector.response_text = create_response_payload connector.response_code = HTTPStatus.CREATED # when user = User(full_name="Test User", email="*****@*****.**", role="Member", email_service=True, email_product=True) created = client.users.create(user) # then request properly formed assert connector.last_url_path == "/user" assert connector.last_method == APICallMethods.POST assert connector.last_payload is not None assert "user" in connector.last_payload assert connector.last_payload["user"]["user_full_name"] == "Test User" assert connector.last_payload["user"]["user_email"] == "*****@*****.**" assert connector.last_payload["user"]["role"] == "Member" assert connector.last_payload["user"]["email_service"] is True assert connector.last_payload["user"]["email_product"] is True # and response properly parsed assert created.id == ID(145985) assert created.username == "*****@*****.**" assert created.full_name == "Test User" assert created.email == "*****@*****.**" assert created.company_id == ID(74333) assert created.role == "Member" assert created.password is None assert created.email_service is True assert created.email_product is True assert created.api_token is None
def to_user(self) -> User: return User( id=convert(self.id, ID), username=self.username, full_name=self.user_full_name, email=self.user_email, role=self.role, email_service=bool(self.email_service), email_product=bool(self.email_product), last_login=self.last_login, created_date=self.created_date, updated_date=self.updated_date, company_id=convert(self.company_id, ID), api_token=self.user_api_token, filters=dict(self.filters), saved_filters=list(self.saved_filters), )
def test_update_user_success(client, connector) -> None: # given update_response_payload = """ { "user":{ "id":"146034", "username":"******", "user_full_name":"User Testing", "user_email":"*****@*****.**", "role":"Member", "email_service":true, "email_product":true, "last_login":null, "created_date":"2020-12-09T15:23:29.768Z", "updated_date":"2020-12-09T15:23:31.108Z", "company_id":"74333", "user_api_token":null, "filters":{}, "saved_filters":[] } }""" connector.response_text = update_response_payload connector.response_code = HTTPStatus.OK # when user_id = ID(146034) user = User( id=user_id, full_name="User Testing", ) updated = client.users.update(user) # then request properly formed assert connector.last_url_path == f"/user/{user_id}" assert connector.last_method == APICallMethods.PUT assert connector.last_payload is not None assert "user" in connector.last_payload assert connector.last_payload["user"]["user_full_name"] == "User Testing" # then response properly parsed assert updated.id == ID(146034) assert updated.full_name == "User Testing" assert updated.email == "*****@*****.**"
def test_create_user_fails_when_no_email_given(kentik_api) -> None: user = User(role="Member", email_service=True, email_product=True) with pytest.raises(AssertionError, match="User email has to be provided"): kentik_api.users.create(user)