test_project_import_priority.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """An imported project gets a priority the project editor accepts.
  2. A file without one used to get the number 0: refused by PostgreSQL (a text
  3. column) and stored as a priority the editor itself refuses on SQLite.
  4. """
  5. from __future__ import annotations
  6. import io
  7. import json
  8. import pytest
  9. from httpx import AsyncClient
  10. pytestmark = [pytest.mark.asyncio, pytest.mark.integration]
  11. async def _import_file(client: AsyncClient, data: dict):
  12. files = {"file": ("project.json", io.BytesIO(json.dumps(data).encode()), "application/json")}
  13. return await client.post("/api/v1/projects/import/file", files=files)
  14. @pytest.mark.parametrize(
  15. ("given", "expected"),
  16. [(None, "normal"), ("high", "high"), ("urgent", "urgent"), (0, "normal"), ("whenever", "normal")],
  17. )
  18. async def test_a_file_import_gets_a_valid_priority(async_client: AsyncClient, given, expected):
  19. data = {"name": "Imported"} if given is None else {"name": "Imported", "priority": given}
  20. response = await _import_file(async_client, data)
  21. assert response.status_code == 200, response.text
  22. assert response.json()["priority"] == expected
  23. @pytest.mark.parametrize(("given", "expected"), [("low", "low"), ("whenever", "normal")])
  24. async def test_a_json_import_gets_a_valid_priority(async_client: AsyncClient, given, expected):
  25. response = await async_client.post("/api/v1/projects/import", json={"name": "Imported", "priority": given})
  26. assert response.status_code == 200, response.text
  27. assert response.json()["priority"] == expected