-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #378 from akvo/develop
Develop
- Loading branch information
Showing
8 changed files
with
269 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,9 @@ | |
from models.user_case_access import UserCaseAccess | ||
from models.user_business_unit import UserBusinessUnit | ||
from models.tag import Tag | ||
from models.question import Question | ||
from models.reference_data import ReferenceData | ||
from models.user import User | ||
|
||
|
||
pytestmark = pytest.mark.asyncio | ||
|
@@ -41,6 +44,16 @@ async def test_deleting_a_user_who_has_cases( | |
headers={"Authorization": f"Bearer {account.token}"}, | ||
) | ||
assert res.status_code == 409 | ||
res = res.json() | ||
assert res == { | ||
"detail": { | ||
"id": 1, | ||
"email": "[email protected]", | ||
"cases": [ | ||
{"label": "Bali Coffee Production (Private)", "value": 2} | ||
], | ||
} | ||
} | ||
|
||
@pytest.mark.asyncio | ||
async def test_deleting_a_user_who_doesnt_have_cases( | ||
|
@@ -100,6 +113,38 @@ async def test_deleting_a_user_who_doesnt_have_cases( | |
assert tag is not None | ||
assert tag.created_by == deleted_user | ||
|
||
# add question | ||
question_id = 1000 | ||
question = Question( | ||
id=question_id, text="Test Question 1000", created_by=deleted_user | ||
) | ||
session.add(question) | ||
session.commit() | ||
session.flush() | ||
session.refresh(question) | ||
assert question is not None | ||
assert question.created_by == deleted_user | ||
|
||
# add reference_data | ||
reference_id = 10000 | ||
reference = ReferenceData( | ||
id=reference_id, | ||
country=1, | ||
commodity=1, | ||
region="asia", | ||
currency="usd", | ||
year="2020", | ||
source="source", | ||
link="link", | ||
created_by=deleted_user, | ||
) | ||
session.add(reference) | ||
session.commit() | ||
session.flush() | ||
session.refresh(reference) | ||
assert reference is not None | ||
assert reference.created_by == deleted_user | ||
|
||
# delete user | ||
res = await client.delete( | ||
app.url_path_for("user:delete", user_id=deleted_user), | ||
|
@@ -132,3 +177,22 @@ async def test_deleting_a_user_who_doesnt_have_cases( | |
# make sure tag created_by removed | ||
tag = session.query(Tag).filter(Tag.created_by == deleted_user).first() | ||
assert tag is None | ||
|
||
# make sure question created_by is None | ||
question = ( | ||
session.query(Question).filter(Question.id == question_id).first() | ||
) | ||
assert question is not None | ||
assert question.id == question_id | ||
assert question.created_by is None | ||
|
||
# make sure reference data created by is None | ||
reference_data = ( | ||
session.query(ReferenceData) | ||
.filter(ReferenceData.created_by == deleted_user) | ||
.all() | ||
) | ||
assert reference_data == [] | ||
|
||
user = session.query(User).filter(User.id == deleted_user).first() | ||
assert user is None |
Oops, something went wrong.