-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_libraries_request.py
More file actions
60 lines (48 loc) · 1.75 KB
/
test_libraries_request.py
File metadata and controls
60 lines (48 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from typing import Mapping
import pytest
from httpx import AsyncClient
from sqlmodel import select
from sqlmodel.ext.asyncio.session import AsyncSession
from app.services.database.models import Community, LibraryRequest
@pytest.mark.asyncio
async def test_insert_libraries(session: AsyncSession, community: Community):
library = LibraryRequest(
library_name="Flask",
user_email="teste@teste.com",
library_home_page="http://teste.com/",
community_id=community.id,
)
session.add(library)
await session.commit()
statement = select(LibraryRequest).where(
LibraryRequest.library_name == "Flask"
)
result = await session.exec(statement)
found = result.first()
assert found is not None
assert found.user_email == "teste@teste.com"
assert found.library_home_page == "http://teste.com/"
assert found.community_id == community.id
@pytest.mark.asyncio
async def test_post_libraries_endpoint(
async_client: AsyncClient,
session: AsyncSession,
community: Community,
valid_auth_headers: Mapping[str, str],
):
body = {"library_name": "FastAPI", "library_home_page": "http://teste.com/"}
response = await async_client.post(
"/api/libraries/request",
json=body,
headers=valid_auth_headers,
)
assert response.status_code == 200
assert response.json()["status"] == "Library requested successfully"
statement = select(LibraryRequest).where(
LibraryRequest.library_name == body["library_name"]
)
result = await session.exec(statement)
created_request = result.first()
assert created_request is not None
assert created_request.user_email == community.email
assert created_request.library_home_page == "http://teste.com/"