Spaces:
Build error
Build error
File size: 4,122 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 |
from fastapi.encoders import jsonable_encoder
import models
from core.config import settings
from . import test_department
headers = {
"accept": "application/json",
"Content-Type": "application/json",
}
def test_post_program(super_user_client, db):
test_department.test_post_department(super_user_client, db)
department_id = (
db.query(models.Department)
.filter(models.Department.name == "Test Department")
.first()
.id
)
data = {"name": "Test Program", "department_id": department_id, "max_sems": 8}
post_req = super_user_client.post(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/program/",
json=data,
)
assert post_req.status_code == 200, "Program post request failed"
def test_get_program(super_user_client):
get_req = super_user_client.get(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/program/",
)
assert get_req.status_code == 200
programs = get_req.json()
created_program = [
program for program in programs if (program.get("name") == "Test Program")
]
assert len(created_program) == 1
def test_get_specific_program(super_user_client):
get_req = super_user_client.get(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/program/",
)
assert get_req.status_code == 200
programs = get_req.json()
created_program = [
program for program in programs if (program.get("name") == "Test Program")
]
specific_get_req = super_user_client.get(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/program/{created_program[0]['id']}/",
)
assert specific_get_req.status_code == 200
created_program_specific = specific_get_req.json()
assert created_program_specific
assert created_program_specific.get("name") == "Test Program"
def test_put_specific_program(super_user_client):
get_req = super_user_client.get(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/program/",
)
assert get_req.status_code == 200
programs = get_req.json()
created_program = [
program for program in programs if (program.get("name") == "Test Program")
]
data = {
"name": "Updated Program",
}
put_req = super_user_client.put(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/program/{created_program[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}/program/{created_program[0]['id']}/",
)
assert specific_get_req.status_code == 200
created_program_specific = specific_get_req.json()
assert created_program_specific
assert created_program_specific.get("name") == "Updated Program"
def test_delete_program(super_user_client, program_id=None):
get_req = super_user_client.get(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/program/",
)
assert get_req.status_code == 200
programs = get_req.json()
if not program_id:
created_program = [
program
for program in programs
if (program.get("name") == "Updated Program")
]
else:
created_program = [
program for program in programs if (program.get("id") == program_id)
]
delete_req = super_user_client.delete(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/program/{created_program[0]['id']}/",
)
assert delete_req.status_code == 200
get_req = super_user_client.get(
f"{settings.BACKEND_URL_BASE}{settings.API_V1_STR}/program/",
)
assert get_req.status_code == 200
programs = get_req.json()
filtered_program = [
program
for program in programs
if (
program.get("name") == "Updated Program"
or program.get("name") == "Test Program"
)
]
print(filtered_program)
assert not filtered_program
test_department.test_delete_department(
super_user_client, department_id=created_program[0]["department_id"]
)
|