Skip to content
This repository has been archived by the owner on Jan 29, 2021. It is now read-only.

Commit

Permalink
Add tests for updating cloud account names
Browse files Browse the repository at this point in the history
Updates #27
  • Loading branch information
elyezer committed Jul 16, 2018
1 parent 332ec1f commit b67e944
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
5 changes: 5 additions & 0 deletions integrade/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ def head(self, endpoint, **kwargs):
url = urljoin(self.url, endpoint)
return self.request('HEAD', url, **kwargs)

def patch(self, endpoint, payload, **kwargs):
"""Send an HTTP PATCH request."""
url = urljoin(self.url, endpoint)
return self.request('PATCH', url, json=payload, **kwargs)

def post(self, endpoint, payload, **kwargs):
"""Send an HTTP POST request."""
url = urljoin(self.url, endpoint)
Expand Down
40 changes: 25 additions & 15 deletions integrade/tests/api/v1/test_cloud_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def test_create_cloud_account(drop_account_data, cloudtrails_to_delete):
acct_arn = aws_profile['arn']
cloud_account = {
'account_arn': acct_arn,
'name': uuid4(),
'resourcetype': 'AwsAccount'
}
create_response = client.post(
Expand All @@ -71,27 +72,36 @@ def test_create_cloud_account(drop_account_data, cloudtrails_to_delete):
acct = create_response.json()

# get specific account
get_response = client.get(
urljoin(urls.CLOUD_ACCOUNT,
'{}/'.format(acct['id'])
), auth=auth)
account_url = urljoin(urls.CLOUD_ACCOUNT, '{}/'.format(acct['id']))
get_response = client.get(account_url, auth=auth)
assert acct == get_response.json()

# list cloud accounts associated with this user
list_response = client.get(urls.CLOUD_ACCOUNT, auth=auth)
assert acct in list_response.json()['results']

# TODO need to try and update name, but
# feature is not delivered yet.
# Nameing cloud accounts:
# https://github.com/cloudigrade/cloudigrade/issues/267
# Updating cloud accounts:
# https://github.com/cloudigrade/cloudigrade/issues/333

# TODO need to try and update arn, but
# feature is not delivered yet.
# Updating cloud accounts:
# https://github.com/cloudigrade/cloudigrade/issues/333
# Check if account name can be patched
for new_name in (None, acct['name']):
payload = {
'name': new_name,
'resourcetype': 'AwsAccount',
}
response = client.patch(
account_url, payload=payload, auth=auth)
response = client.get(account_url, auth=auth)
assert response.json()['name'] == new_name

# Check if an account can be updated
for new_name in (None, acct['name']):
payload = {
'account_arn': acct_arn,
'name': new_name,
'resourcetype': 'AwsAccount',
}
response = client.put(
account_url, payload=payload, auth=auth)
response = client.get(account_url, auth=auth)
assert response.json()['name'] == new_name

# assert we cannot create duplicate
client.response_handler = api.echo_handler
Expand Down
11 changes: 11 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ def test_response_handler_raises_no_json(
client.response_handler(bad_response)


def test_patch(good_response):
"""Test that the patch method sends a well formed request."""
with patch.object(config, '_CONFIG', VALID_CONFIG):
cl = api.Client()
cl.request = Mock(return_value=good_response)
r = cl.patch('api/v1/', {})
assert r == good_response
cl.request.assert_called_once_with(
'PATCH', urljoin(cl.url, 'api/v1/'), json={})


def test_post(good_response):
"""Test that when we use the post method, a well formed request is sent."""
with patch.object(config, '_CONFIG', VALID_CONFIG):
Expand Down

0 comments on commit b67e944

Please sign in to comment.