def test_read_non_existent_user_superuser( client: TestClient, superuser_token_headers: dict[str, str], db: Session ) -> None: user_id = generate_uuid() while crud.user.get(db, id=user_id): user_id = generate_uuid() r = client.get(f"{settings.API_V1_STR}/users/{user_id}", headers=superuser_token_headers) assert r.status_code == 404
def test_update_non_existent_user_superuser( client: TestClient, superuser_token_headers: dict[str, str], db: Session ) -> None: user_id = generate_uuid() while crud.user.get(db, id=user_id): user_id = generate_uuid() full_name = random_lower_string() data = {"full_name": full_name} r = client.put( f"{settings.API_V1_STR}/users/{user_id}", headers=superuser_token_headers, json=data, ) assert r.status_code == 404
def test_update_profile_picture_superuser_non_existent_user( client: TestClient, superuser_token_headers: dict[str, str], db: Session ) -> None: user_id = generate_uuid() while crud.user.get(db, id=user_id): user_id = generate_uuid() response = client.get("https://media.rev-amp.tech/logo/revamp.png") with open("/tmp/profile_picture.png", "wb") as f: f.write(response.content) r = client.put( f"{settings.API_V1_STR}/users/{user_id}/profile_picture", headers=superuser_token_headers, files={"image": ("profile_picture.png", open("/tmp/profile_picture.png", "rb").read(), "image/png")}, ) assert r.status_code == 404
def generate_link(): # TODO: add data validation forward_url = request.form.get("forward_url", "", str) if not forward_url: return jsonify({ "status_msg": "A forward_url must be supplied for link generation." }), 400 slug = request.form.get("slug", "", str) if not slug: slug = generate_uuid() if URL.query.filter_by(slug=slug).first(): return jsonify({"status_msg": "Slug already in use :/"}), 400 db.session.add(URL(slug, forward_url)) db.session.commit() return jsonify({ "slug": slug, "forward_url": forward_url, "short_url": urllib.parse.urljoin(request.base_url, slug) }), 200
def test_get_non_existing_lecture_superuser(client: TestClient, superuser_token_headers: dict[str, str], db: Session) -> None: lecture_id = generate_uuid() r = client.get(f"{settings.API_V1_STR}/lectures/{lecture_id}", headers=superuser_token_headers) assert r.status_code == 404
def test_add_division_students_not_a_user(client: TestClient, superuser_token_headers: dict[str, str], db: Session) -> None: division = create_random_division(db) new_user_id = generate_uuid() data = [new_user_id] r = client.post(f"{settings.API_V1_STR}/divisions/{division.id}/students", headers=superuser_token_headers, json=data) assert r.status_code == 207 response = r.json() assert response.get("errors").get("not a user")[0] == new_user_id
def test_add_term_students_not_a_user(client: TestClient, superuser_token_headers: dict[str, str], db: Session) -> None: term = create_random_term(db) students = [ create_random_user(db, type="student", school_id=term.year.school_id), create_random_user(db, type="student", school_id=term.year.school_id), ] data = [user.id for user in students] new_user_id = generate_uuid() data.append(new_user_id) r = client.post(f"{settings.API_V1_STR}/terms/{term.id}/students", headers=superuser_token_headers, json=data) assert r.status_code == 207 response = r.json() assert response.get("errors").get("not a user")[0] == new_user_id for user in students: student = crud.student.get(db, id=user.id) assert student assert student.user_id in response.get("success") assert student.term_id == term.id
def __init__(self, board=None): self.id = generate_uuid() self.size = Config.BOGGLE_BOARD_DIMENSION self.gen_nodes(board)