Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

admin/api/accounts/{id}/users done #164

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Proxy, Backend, Metric, MappingRule,
BackendMappingRule, BackendUsage,
ActiveDoc, Webhooks, InvoiceState,
ApplicationKey, ApplicationPlans)
ApplicationKey, ApplicationPlans, AccountUser, AccountUsers)

load_dotenv()

Expand Down Expand Up @@ -109,6 +109,11 @@ def update_account_params():
return dict(org_name=name)


@pytest.fixture(scope='module')
def account_get_plan_params():
return dict(name="Default")


@pytest.fixture(scope='module')
def account_params():
suffix = get_suffix()
Expand All @@ -123,6 +128,26 @@ def account(account_params, api):
cleanup(entity)


@pytest.fixture(scope='module')
def account_user_update_params():
suffix = get_suffix()
name = f"test-update-{suffix}"
return dict(username=name, email=f"{name}@email.com")


@pytest.fixture(scope='module')
def account_user_params():
suffix = get_suffix()
name = f"test-{suffix}"
return dict(username=name, email=f"{name}@email.com")


@pytest.fixture(scope='module')
def account_user(account,account_user_params) -> AccountUser:
user = account.users.create(account_user_params)
yield user
cleanup(user)

@pytest.fixture(scope='module')
def application_plan_params() -> dict:
suffix = get_suffix()
Expand Down
46 changes: 46 additions & 0 deletions tests/integration/test_integration_account_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from tests.integration import asserts
from tests.integration.conftest import account

mkudlej marked this conversation as resolved.
Show resolved Hide resolved

def test_account_user_can_be_created(account_user, account_user_params):
asserts.assert_resource(account_user)
asserts.assert_resource_params(account_user, account_user_params)


def test_account_users_list(api,account, account_user):
users = account.users.list()
assert len(users) > 1
mkudlej marked this conversation as resolved.
Show resolved Hide resolved


def test_account_users_get_by_id(account, account_user, account_user_params):
account_user = account.users.read(account_user['id'])
asserts.assert_resource(account_user)
asserts.assert_resource_params(account_user, account_user_params)


def test_account_user_can_be_updated(account_user, account_user_update_params):
updated_user = account_user.update(account_user_update_params)
asserts.assert_resource(updated_user)
asserts.assert_resource_params(updated_user, account_user_update_params)


def test_account_user_change_status(account_user):
assert account_user['state'] == 'pending'
updated_account_user = account_user.activate()
assert updated_account_user['state'] == 'active'

updated_account_user = account_user.suspend()
assert updated_account_user['state'] == 'suspended'

updated_account_user = account_user.un_suspend()
assert updated_account_user['state'] == 'active'


def test_account_user_change_role(account_user):
assert account_user['role'] == 'member'

updated_account_user = account_user.set_as_admin()
assert updated_account_user['role'] == 'admin'

updated_account_user = account_user.set_as_member()
assert updated_account_user['role'] == 'member'
12 changes: 12 additions & 0 deletions tests/integration/test_integration_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,23 @@ def test_account_can_be_read_by_name(api, account, account_params):
asserts.assert_resource_params(read, account_params, ['org_name'])


def test_account_can_be_find_by_name(api, account_user, account_params):
account2 = api.accounts.find(dict(username=account_user['username']))
asserts.assert_resource(account2)
asserts.assert_resource_params(account2, account_params, ['org_name'])


def test_account_update(api,account, update_account_params):
updated_account = account.update(params=update_account_params)
asserts.assert_resource(updated_account)
asserts.assert_resource_params(updated_account, update_account_params)


def test_get_account_plan(account, account_get_plan_params):
plan = account.get_account_plan()
asserts.assert_resource(plan)
asserts.assert_resource_params(plan,account_get_plan_params, ['name'])


def test_users_list(api, account):
assert len(account.users.list()) >= 1
14 changes: 12 additions & 2 deletions threescale_api/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,16 @@ def suspend(self, **kwargs) -> 'DefaultUserResource':
"""
return self.set_state(state='suspend', **kwargs)

def un_suspend(self, **kwargs) -> 'DefaultUserResource':
"""Un suspends the user
Args:
**kwargs:
Optional arguments
Returns(DefaultUserResource): User instance

"""
return self.set_state(state='unsuspend', **kwargs)

def resume(self, **kwargs):
"""Resumes the user
Args:
Expand All @@ -541,7 +551,7 @@ def set_as_admin(self, **kwargs):
Returns(DefaultUserResource): User instance

"""
return self.set_state(state='set_as_admin', **kwargs)
return self.set_state(state='admin', **kwargs)

def set_as_member(self, **kwargs):
"""Demotes the user to s member
Expand All @@ -550,4 +560,4 @@ def set_as_member(self, **kwargs):
Returns(DefaultUserResource): User instance

"""
return self.set_state(state='set_as_member', **kwargs)
return self.set_state(state='member', **kwargs)
19 changes: 19 additions & 0 deletions threescale_api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ def create(self, params: dict = None, **kwargs) -> 'Account':
"""
return self.signup(params=params, **kwargs)

def find(self, params: dict, **kwargs) -> 'Account':
"""Find an account
Args:
params(dict): Parameters to used to find account (name, email, etc)
**kwargs: Optional args
Returns(Account): Account instance
"""
log.info("[FIND] Find accout: paramas:%s, kwarfs=%s", params, kwargs)
find_url = self.url + "/find"
response = self.rest.get(path=find_url, json=params, **kwargs)
instance = self._create_instance(response=response)
return instance

def signup(self, params: dict, **kwargs) -> 'Account':
"""Sign Up for an account
Args:
Expand Down Expand Up @@ -1470,6 +1483,12 @@ def credit_card_delete(self, params: dict = None, **kwargs):
response = self.client.rest.delete(url=url, json=params, **kwargs)
return response

def get_account_plan(self, params: dict = None, **kwargs):
account_plans = AccountPlans(self, ApplicationPlan)
url = self.url + "/plan"
response = self.client.rest.get(url=url, json=params, **kwargs)
return account_plans._create_instance(response=response)


class UserPermissions(DefaultResource):
pass
Expand Down
Loading