Skip to content

Commit

Permalink
Defaulted emails to empty list rather than None, added unit test exer…
Browse files Browse the repository at this point in the history
…cising new route with no project, a valid project, and an invalid project
  • Loading branch information
dhakim87 committed Nov 14, 2020
1 parent bfcc93a commit c6e1553
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion microsetta_private_api/admin/admin_impl.py
Expand Up @@ -307,7 +307,7 @@ def get_daklapack_articles(token_info):
def query_email_stats(body, token_info):
validate_admin_access(token_info)

email_list = body.get("emails")
email_list = body.get("emails", [])
project = body.get("project")

results = []
Expand Down
28 changes: 28 additions & 0 deletions microsetta_private_api/admin/tests/test_admin_api.py
Expand Up @@ -716,6 +716,34 @@ def test_get_daklapack_articles(self):
self.assertEqual(len(article_dicts_list), len(response_obj))
self.assertEqual(FIRST_DAKLAPACK_ARTICLE, response_obj[0])

def test_email_stats(self):
with Transaction() as t:
accts = AccountRepo(t)
acct1 = accts.get_account("65dcd6c8-69fa-4de8-a33a-3de4957a0c79")
acct2 = accts.get_account("556f5dc4-8cf2-49ae-876c-32fbdfb005dd")

# execute articles get
for project in [None, "American Gut Project", "NotAProj"]:
response = self.client.post(
"/api/admin/account_email_summary",
headers=MOCK_HEADERS,
content_type='application/json',
data=json.dumps({
"emails": [acct1.email, acct2.email],
"project": project
})
)
self.assertEqual(200, response.status_code)
result = json.loads(response.data)
self.assertEqual(result[0]["account_id"],
"65dcd6c8-69fa-4de8-a33a-3de4957a0c79")
self.assertEqual(result[1]["account_id"],
"556f5dc4-8cf2-49ae-876c-32fbdfb005dd")
if project is None or project == "American Gut Project":
self.assertEqual(result[0]["sample-is-valid"], 1)
else:
self.assertEqual(result[0].get("sample-is-valid", 0), 0)

def test_metadata_qiita_compatible_invalid(self):
data = json.dumps({'sample_barcodes': ['bad']})
response = self.client.post('/api/admin/metadata/qiita-compatible',
Expand Down

0 comments on commit c6e1553

Please sign in to comment.