Skip to content

Commit

Permalink
Source now returns source_id as specified in the api. test_integratio…
Browse files Browse the repository at this point in the history
…n now has two working tests
  • Loading branch information
dhakim87 committed Jan 29, 2020
1 parent c29c817 commit 0f6b05d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 31 deletions.
74 changes: 44 additions & 30 deletions microsetta_private_api/api/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,23 @@ def setup_test_data():
with Transaction() as t:
acct_repo = AccountRepo(t)
acct_repo.delete_account(ACCT_ID)

creation_time = None
update_time = None

acc = Account(ACCT_ID,
"foo@baz.com",
"globus",
"Dan",
"H",
'{"a":5, "b":7}',
"USER")
"foo@baz.com",
"standard",
"GLOBUS",
"Dan",
"H",
{
"street": "123 Dan Lane",
"city": "Danville",
"state": "CA",
"post_code": 12345,
"country_code": "US"
})
acct_repo.create_account(acc)

source_repo = SourceRepo(t)
Expand All @@ -42,8 +52,9 @@ def setup_test_data():
source_repo.create_source(Source.create_human(
HUMAN_ID,
ACCT_ID,
HumanInfo("Bo", "bo@bo.com", False, "Mr Bo", False, "Mrs Bo",
False, datetime.datetime.utcnow(), "TODO,WutDis?")
HumanInfo("Bo", "bo@bo.com", False, "Mr Bo", "Mrs Bo",
False, datetime.datetime.utcnow(), None, "Mr. Obtainer",
"18-plus")
))
source_repo.create_source(Source.create_animal(
DOGGY_ID,
Expand Down Expand Up @@ -86,25 +97,28 @@ def test_get_sources(client):
assert len([x for x in sources if x['source_name'] == 'Planty']) == 1


# BROKEN
# def test_external_surveys(client):
# # I can't even find a test that we can pass for demo purposes!
# resp = client.get('/api/accounts/%s/sources' % ACCT_ID).data
# sources = json.loads(resp)
# bobo = [x for x in sources if x['source_name'] == 'Bo'][0]
# doggy = [x for x in sources if x['source_name'] == 'Doggy'][0]
# env = [x for x in sources if x['source_name'] == 'Planty'][0]
#
# resp = client.get('/accounts/%s/sources/%s/survey_templates' %
# (ACCT_ID, bobo.id))
# bobo_surveys = json.loads(resp.data)
# resp = client.get('/accounts/%s/sources/%s/survey_templates' %
# (ACCT_ID, doggy.id))
# doggy_surveys = json.loads(resp.data)
# resp = client.get('/accounts/%s/sources/%s/survey_templates' %
# (ACCT_ID, env.id))
# env_surveys = json.loads(resp.data)
#
# assert bobo_surveys == [1, 3, 4, 5]
# assert doggy_surveys == [2]
# assert env_surveys == [3]
def test_surveys(client):
# I can't even find a test that we can pass for demo purposes!
resp = client.get('/api/accounts/%s/sources' % ACCT_ID).data

sources = json.loads(resp)
bobo = [x for x in sources if x['source_name'] == 'Bo'][0]
doggy = [x for x in sources if x['source_name'] == 'Doggy'][0]
env = [x for x in sources if x['source_name'] == 'Planty'][0]

resp = client.get(
'/api/accounts/%s/sources/%s/survey_templates?language_tag=en_us' %
(ACCT_ID, bobo['source_id']), )
bobo_surveys = json.loads(resp.data)
resp = client.get(
'/api/accounts/%s/sources/%s/survey_templates?language_tag=en_us' %
(ACCT_ID, doggy['source_id']))
doggy_surveys = json.loads(resp.data)
resp = client.get(
'/api/accounts/%s/sources/%s/survey_templates?language_tag=en_us' %
(ACCT_ID, env['source_id']))
env_surveys = json.loads(resp.data)

assert bobo_surveys == [1, 3, 4, 5]
assert doggy_surveys == [2]
assert env_surveys == []
3 changes: 2 additions & 1 deletion microsetta_private_api/model/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def __init__(self, source_id, account_id, source_type, source_data):
def to_api(self):
result = {
"source_type": self.source_type,
"source_name": self.source_data.name
"source_name": self.source_data.name,
"source_id": self.id
}

if self.source_type == Source.SOURCE_TYPE_HUMAN:
Expand Down

0 comments on commit 0f6b05d

Please sign in to comment.