init CTFd source
Some checks are pending
Linting / Linting (3.11) (push) Waiting to run
Mirror core-theme / mirror (push) Waiting to run

This commit is contained in:
gkr
2025-12-25 09:39:21 +08:00
commit 2e06f92c64
1047 changed files with 150349 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
from CTFd.constants import JinjaEnum, JSEnum, RawEnum
from tests.helpers import create_ctfd, destroy_ctfd
def test_RawEnum():
class Colors(str, RawEnum):
RED = "red"
GREEN = "green"
BLUE = "blue"
class Numbers(str, RawEnum):
ONE = 1
TWO = 2
THREE = 3
assert Colors.RED == "red"
assert Colors.GREEN == "green"
assert Colors.BLUE == "blue"
assert Colors.test("red") is True
assert Colors.test("purple") is False
assert str(Numbers.ONE) == "1"
assert sorted(Colors.keys()) == sorted(["RED", "GREEN", "BLUE"])
assert sorted(Colors.values()) == sorted(["red", "green", "blue"])
def test_JSEnum():
import json
from CTFd.constants import JS_ENUMS # noqa: I001
@JSEnum
class Colors(str, RawEnum):
RED = "red"
GREEN = "green"
BLUE = "blue"
assert JS_ENUMS["Colors"] == {"RED": "red", "GREEN": "green", "BLUE": "blue"}
assert json.dumps(JS_ENUMS)
def test_JinjaEnum():
@JinjaEnum
class Colors(str, RawEnum):
RED = "red"
GREEN = "green"
BLUE = "blue"
app = create_ctfd()
with app.app_context():
assert app.jinja_env.globals["Colors"] is Colors
assert app.jinja_env.globals["Colors"].RED == "red"
destroy_ctfd(app)

9
tests/constants/time.py Normal file
View File

@@ -0,0 +1,9 @@
from CTFd.constants import RawEnum
class FreezeTimes(str, RawEnum):
NOT_STARTED = "2017-10-3" # Tuesday, October 3, 2017
STARTED = "2017-10-5" # Thursday, October 5, 2017
ENDED = "2017-10-7" # Saturday, October 7, 2017
START = "1507089600" # Wednesday, October 4, 2017 12:00:00 AM GMT-04:00 DST
END = "1507262400" # Friday, October 6, 2017 12:00:00 AM GMT-04:00 DST