Skip to content

Commit

Permalink
modify claim legacy return value to array to match find logins
Browse files Browse the repository at this point in the history
  • Loading branch information
AmandaBirmingham committed Apr 23, 2020
1 parent 141640a commit e61fbdd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
4 changes: 2 additions & 2 deletions microsetta_private_api/api/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ def claim_legacy_acct(token_info):
t.commit()

if acct is None:
return jsonify(code=404, message=ACCT_NOT_FOUND_MSG), 404
return jsonify([]), 200

return jsonify(acct.to_api()), 200
return jsonify([acct.to_api()]), 200


def register_account(body, token_info):
Expand Down
12 changes: 6 additions & 6 deletions microsetta_private_api/api/microsetta_private_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ paths:
operationId: microsetta_private_api.api.implementation.claim_legacy_acct
tags:
- Account
summary: Claim any matching legacy account for this user
description: Claim any matching legacy account for this user
summary: Claim any legacy accounts for this user's email and return an array of them
description: Claim any legacy accounts for this user's email and return an array of them
parameters:
- $ref: '#/components/parameters/language_tag'
responses:
'200':
description: Successfully claimed legacy account
description: Successfully claimed legacy account(s)
content:
application/json:
schema:
$ref: '#/components/schemas/account'
type: array
items:
$ref: '#/components/schemas/account'
'401':
$ref: '#/components/responses/401Unauthorized'
'403':
$ref: '#/components/responses/403Forbidden'
'404':
$ref: '#/components/responses/404NotFound'
'422':
$ref: '#/components/responses/422UnprocessableEntity'

Expand Down
38 changes: 24 additions & 14 deletions microsetta_private_api/api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,25 +435,30 @@ def test_accounts_legacies_post_success(self):

# execute accounts/legacies post (claim legacy account)
url = '/api/accounts/legacies?%s' % self.default_lang_querystring
response = self.client.post(url, headers=MOCK_HEADERS)
response_1 = self.client.post(url, headers=MOCK_HEADERS)

# check response code
self.assertEqual(200, response.status_code)
self.assertEqual(200, response_1.status_code)

# load the response body
response_obj = json.loads(response.data)
response_obj_1 = json.loads(response_1.data)
self.assertEqual(1, len(response_obj_1))

# check all elements of account object in body are correct
self.validate_dummy_acct_response_body(response_obj)
self.validate_dummy_acct_response_body(response_obj_1[0])

# try to reclaim the same account
response = self.client.post(url, headers=MOCK_HEADERS)
response_2 = self.client.post(url, headers=MOCK_HEADERS)

# check response is now a 404
self.assertEqual(404, response.status_code)
# check response is now a 200 but with an empty list
self.assertEqual(200, response_2.status_code)

# load the response body
response_obj_2 = json.loads(response_2.data)
self.assertEqual(0, len(response_obj_2))

def test_accounts_legacies_post_fail_404_no_such_email(self):
"""Return 404 if no account with provided email in token exists"""
def test_accounts_legacies_post_success_empty_no_email(self):
"""Return empty list if no account with given email in token exists"""

# do NOT create the dummy account--and check for a legacy account
# containing that email (via the MOCK_HEADERS, which link to a fake
Expand All @@ -464,19 +469,24 @@ def test_accounts_legacies_post_fail_404_no_such_email(self):
response = self.client.post(url, headers=MOCK_HEADERS)

# check response code
self.assertEqual(404, response.status_code)
self.assertEqual(200, response.status_code)

# load the response body
response_obj = json.loads(response.data)
self.assertEqual(0, len(response_obj))

def test_accounts_legacies_post_fail_404_already_claimed(self):
"""Return 404 if account with email already is claimed."""
def test_accounts_legacies_post_success_empty_already_claimed(self):
"""Return empty list if account with email already is claimed."""

create_dummy_acct(create_dummy_1=True)

# execute accounts/legacies post (claim legacy account)
url = '/api/accounts/legacies?%s' % self.default_lang_querystring
response = self.client.post(url, headers=MOCK_HEADERS)

# check response code
self.assertEqual(404, response.status_code)
# load the response body
response_obj = json.loads(response.data)
self.assertEqual(0, len(response_obj))

def test_accounts_legacies_post_fail_422(self):
"""Return 422 if info in db somehow prevents claiming legacy"""
Expand Down

0 comments on commit e61fbdd

Please sign in to comment.