|
| 1 | +"""Tests for DataRemovalManager.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +# --------------------------------------------------------------------------- |
| 6 | +# Shared fixture data |
| 7 | +# --------------------------------------------------------------------------- |
| 8 | + |
| 9 | +REMOVAL = {"ID": 42, "Status": "Pending"} |
| 10 | +REMOVAL_DONE = {"ID": 42, "Status": "Done"} |
| 11 | + |
| 12 | + |
| 13 | +# --------------------------------------------------------------------------- |
| 14 | +# Create data removal |
| 15 | +# --------------------------------------------------------------------------- |
| 16 | + |
| 17 | + |
| 18 | +class TestCreateDataRemoval: |
| 19 | + @pytest.mark.asyncio |
| 20 | + async def test_create_success(self, data_removals): |
| 21 | + manager, fake = data_removals |
| 22 | + fake.mock_post_response(REMOVAL) |
| 23 | + |
| 24 | + result = await manager.create( |
| 25 | + requested_by="admin@example.com", |
| 26 | + requested_for="user@example.com", |
| 27 | + ) |
| 28 | + |
| 29 | + assert result.id == 42 |
| 30 | + assert result.status == "Pending" |
| 31 | + |
| 32 | + @pytest.mark.asyncio |
| 33 | + async def test_create_calls_correct_endpoint(self, data_removals): |
| 34 | + manager, fake = data_removals |
| 35 | + fake.mock_post_response(REMOVAL) |
| 36 | + |
| 37 | + await manager.create( |
| 38 | + requested_by="admin@example.com", |
| 39 | + requested_for="user@example.com", |
| 40 | + ) |
| 41 | + |
| 42 | + fake.post.assert_called_once_with( |
| 43 | + "/data-removals", |
| 44 | + json={ |
| 45 | + "RequestedBy": "admin@example.com", |
| 46 | + "RequestedFor": "user@example.com", |
| 47 | + "NotifyWhenCompleted": False, |
| 48 | + }, |
| 49 | + ) |
| 50 | + |
| 51 | + @pytest.mark.asyncio |
| 52 | + async def test_create_with_notify(self, data_removals): |
| 53 | + manager, fake = data_removals |
| 54 | + fake.mock_post_response(REMOVAL) |
| 55 | + |
| 56 | + await manager.create( |
| 57 | + requested_by="admin@example.com", |
| 58 | + requested_for="user@example.com", |
| 59 | + notify_when_completed=True, |
| 60 | + ) |
| 61 | + |
| 62 | + body = fake.post.call_args[1]["json"] |
| 63 | + assert body["NotifyWhenCompleted"] is True |
| 64 | + |
| 65 | + |
| 66 | +# --------------------------------------------------------------------------- |
| 67 | +# Get data removal |
| 68 | +# --------------------------------------------------------------------------- |
| 69 | + |
| 70 | + |
| 71 | +class TestGetDataRemoval: |
| 72 | + @pytest.mark.asyncio |
| 73 | + async def test_get_success(self, data_removals): |
| 74 | + manager, fake = data_removals |
| 75 | + fake.mock_get_response(REMOVAL_DONE) |
| 76 | + |
| 77 | + result = await manager.get(42) |
| 78 | + |
| 79 | + assert result.id == 42 |
| 80 | + assert result.status == "Done" |
| 81 | + |
| 82 | + @pytest.mark.asyncio |
| 83 | + async def test_get_calls_correct_endpoint(self, data_removals): |
| 84 | + manager, fake = data_removals |
| 85 | + fake.mock_get_response(REMOVAL) |
| 86 | + |
| 87 | + await manager.get(42) |
| 88 | + |
| 89 | + fake.get.assert_called_once_with("/data-removals/42") |
0 commit comments