-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pdct 313 Added endpoint for deleting events (#28)
- Loading branch information
1 parent
b1ef7cf
commit 6c993a4
Showing
11 changed files
with
242 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
from fastapi.testclient import TestClient | ||
from fastapi import status | ||
from sqlalchemy.orm import Session | ||
from app.clients.db.models.law_policy import FamilyEvent, EventStatus | ||
from integration_tests.setup_db import setup_db | ||
import app.repository.event as event_repo | ||
|
||
|
||
def test_delete_event(client: TestClient, test_db: Session, admin_user_header_token): | ||
setup_db(test_db) | ||
response = client.delete("/api/v1/events/E.0.0.2", headers=admin_user_header_token) | ||
assert response.status_code == status.HTTP_200_OK | ||
assert test_db.query(FamilyEvent).count() == 3 | ||
assert ( | ||
test_db.query(FamilyEvent) | ||
.filter(FamilyEvent.status == EventStatus.DELETED) | ||
.count() | ||
== 1 | ||
) | ||
assert test_db.query(FamilyEvent).count() == 3 | ||
|
||
|
||
def test_delete_event_when_not_authenticated( | ||
client: TestClient, test_db: Session, mocker | ||
): | ||
setup_db(test_db) | ||
mocker.spy(event_repo, "delete") | ||
response = client.delete( | ||
"/api/v1/events/E.0.0.2", | ||
) | ||
assert response.status_code == status.HTTP_401_UNAUTHORIZED | ||
assert test_db.query(FamilyEvent).count() == 3 | ||
assert ( | ||
test_db.query(FamilyEvent) | ||
.filter(FamilyEvent.status == EventStatus.DELETED) | ||
.count() | ||
== 0 | ||
) | ||
assert test_db.query(FamilyEvent).count() == 3 | ||
assert event_repo.delete.call_count == 0 | ||
|
||
|
||
def test_delete_event_rollback( | ||
client: TestClient, | ||
test_db: Session, | ||
rollback_event_repo, | ||
admin_user_header_token, | ||
): | ||
setup_db(test_db) | ||
response = client.delete("/api/v1/events/E.0.0.2", headers=admin_user_header_token) | ||
assert response.status_code == status.HTTP_503_SERVICE_UNAVAILABLE | ||
assert test_db.query(FamilyEvent).count() == 3 | ||
assert ( | ||
test_db.query(FamilyEvent) | ||
.filter(FamilyEvent.status == EventStatus.DELETED) | ||
.count() | ||
== 0 | ||
) | ||
assert test_db.query(FamilyEvent).count() == 3 | ||
assert rollback_event_repo.delete.call_count == 1 | ||
|
||
|
||
def test_delete_event_when_not_found( | ||
client: TestClient, test_db: Session, admin_user_header_token | ||
): | ||
setup_db(test_db) | ||
response = client.delete("/api/v1/events/E.0.0.22", headers=admin_user_header_token) | ||
assert response.status_code == status.HTTP_404_NOT_FOUND | ||
data = response.json() | ||
assert data["detail"] == "Event not deleted: E.0.0.22" | ||
assert test_db.query(FamilyEvent).count() == 3 | ||
assert ( | ||
test_db.query(FamilyEvent) | ||
.filter(FamilyEvent.status == EventStatus.DELETED) | ||
.count() | ||
== 0 | ||
) | ||
assert test_db.query(FamilyEvent).count() == 3 | ||
|
||
|
||
def test_delete_event_when_db_error( | ||
client: TestClient, test_db: Session, bad_event_repo, admin_user_header_token | ||
): | ||
setup_db(test_db) | ||
response = client.delete("/api/v1/events/E.0.0.1", headers=admin_user_header_token) | ||
assert response.status_code == status.HTTP_503_SERVICE_UNAVAILABLE | ||
data = response.json() | ||
assert data["detail"] == "Bad Repo" | ||
assert bad_event_repo.delete.call_count == 1 |
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