Spaces:
Build error
Build error
File size: 3,998 Bytes
b7a7f32 |
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
import json
import base64
import pytest
import requests
from core.config import settings
import email
from cruds import crud_user
import re
headers = {
"accept": "application/json",
"Content-Type": "application/json",
}
def test_post_school(super_user_client):
data = {"name": "Test School", "address": "Testland"}
post_req = super_user_client.post(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/school/",
json=data,
)
assert post_req.status_code == 200, "School post request failed"
def test_get_school(super_user_client):
get_req = super_user_client.get(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/school/",
)
assert get_req.status_code == 200
schools = get_req.json()
created_school = [
school
for school in schools
if (school.get("name") == "Test School")
and (school.get("address") == "Testland")
]
assert len(created_school) == 1
def test_get_specific_school(super_user_client):
get_req = super_user_client.get(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/school/",
)
assert get_req.status_code == 200
schools = get_req.json()
created_school = [
school
for school in schools
if (school.get("name") == "Test School")
and (school.get("address") == "Testland")
]
specific_get_req = super_user_client.get(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/school/{created_school[0]['id']}/",
)
assert specific_get_req.status_code == 200
created_school_specific = specific_get_req.json()
assert created_school_specific
assert created_school_specific.get("name") == "Test School"
assert created_school_specific.get("address") == "Testland"
def test_put_specific_school(super_user_client):
get_req = super_user_client.get(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/school/",
)
assert get_req.status_code == 200
schools = get_req.json()
created_school = [
school
for school in schools
if (school.get("name") == "Test School")
and (school.get("address") == "Testland")
]
data = {
"name": "Updated School",
"address": "Newland",
}
put_req = super_user_client.put(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/school/{created_school[0]['id']}/",
json=data,
)
assert put_req.status_code == 200
specific_get_req = super_user_client.get(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/school/{created_school[0]['id']}/",
)
assert specific_get_req.status_code == 200
created_school_specific = specific_get_req.json()
assert created_school_specific
assert created_school_specific.get("name") == "Updated School"
assert created_school_specific.get("address") == "Newland"
def test_delete_school(super_user_client, school_id=None):
if not school_id:
get_req = super_user_client.get(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/school/",
)
assert get_req.status_code == 200
schools = get_req.json()
created_school = [
school
for school in schools
if (school.get("name") == "Updated School")
and (school.get("address") == "Newland")
]
else:
created_school = [{"id": school_id}]
delete_req = super_user_client.delete(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/school/{created_school[0]['id']}/",
)
assert delete_req.status_code == 200
get_req = super_user_client.get(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/school/",
)
assert get_req.status_code == 200
schools = get_req.json()
filtered_school = [
school
for school in schools
if (school.get("name") == "Updated School")
and (school.get("address") == "Newland")
]
assert not filtered_school
|