[mirror of https://git.0x0.st/mia/0x0] No-bullshit file hosting and URL shortening service https://0x0.st

Remove broken tests

Will be readded after some major refactoring and modernization.

Changed files
+7 -89
tests
+7 -8
fhost.py
··· 80 80 URL_ALPHABET = "DEQhd2uFteibPwq0SWBInTpA_jcZL5GKz3YCR14Ulk87Jors9vNHgfaOmMXy6Vx-", 81 81 ) 82 82 83 - if not app.config["TESTING"]: 84 - app.config.from_pyfile("config.py") 85 - app.jinja_loader = ChoiceLoader([ 86 - FileSystemLoader(str(Path(app.instance_path) / "templates")), 87 - app.jinja_loader 88 - ]) 83 + app.config.from_pyfile("config.py") 84 + app.jinja_loader = ChoiceLoader([ 85 + FileSystemLoader(str(Path(app.instance_path) / "templates")), 86 + app.jinja_loader 87 + ]) 89 88 90 - if app.config["DEBUG"]: 91 - app.config["FHOST_USE_X_ACCEL_REDIRECT"] = False 89 + if app.config["DEBUG"]: 90 + app.config["FHOST_USE_X_ACCEL_REDIRECT"] = False 92 91 93 92 if app.config["NSFW_DETECT"]: 94 93 from nsfw_detect import NSFWDetector
tests/__init__.py

This is a binary file and will not be displayed.

-81
tests/test_client.py
··· 1 - import pytest 2 - import tempfile 3 - import os 4 - from flask_migrate import upgrade as db_upgrade 5 - from io import BytesIO 6 - 7 - from fhost import app, db, url_for, File, URL 8 - 9 - @pytest.fixture 10 - def client(): 11 - with tempfile.TemporaryDirectory() as tmpdir: 12 - app.config["SQLALCHEMY_DATABASE_URI"] = f"sqlite:///{tmpdir}/db.sqlite" 13 - app.config["FHOST_STORAGE_PATH"] = os.path.join(tmpdir, "up") 14 - app.config["TESTING"] = True 15 - 16 - with app.test_client() as client: 17 - with app.app_context(): 18 - db_upgrade() 19 - yield client 20 - 21 - def test_client(client): 22 - payloads = [ 23 - ({ "file" : (BytesIO(b"hello"), "hello.txt") }, 200, b"https://localhost/E.txt\n"), 24 - ({ "file" : (BytesIO(b"hello"), "hello.ignorethis") }, 200, b"https://localhost/E.txt\n"), 25 - ({ "file" : (BytesIO(b"bye"), "bye.truncatethis") }, 200, b"https://localhost/Q.truncate\n"), 26 - ({ "file" : (BytesIO(b"hi"), "hi.tar.gz") }, 200, b"https://localhost/h.tar.gz\n"), 27 - ({ "file" : (BytesIO(b"lea!"), "lea!") }, 200, b"https://localhost/d.txt\n"), 28 - ({ "file" : (BytesIO(b"why?"), "balls", "application/x-dosexec") }, 415, None), 29 - ({ "shorten" : "https://0x0.st" }, 200, b"https://localhost/E\n"), 30 - ({ "shorten" : "https://localhost" }, 400, None), 31 - ({}, 400, None), 32 - ] 33 - 34 - for p, s, r in payloads: 35 - rv = client.post("/", buffered=True, 36 - content_type="multipart/form-data", 37 - data=p) 38 - assert rv.status_code == s 39 - if r: 40 - assert rv.data == r 41 - 42 - f = File.query.get(2) 43 - f.removed = True 44 - db.session.add(f) 45 - db.session.commit() 46 - 47 - rq = [ 48 - (200, [ 49 - "/", 50 - "robots.txt", 51 - "E.txt", 52 - "E.txt/test", 53 - "E.txt/test.py", 54 - "d.txt", 55 - "h.tar.gz", 56 - ]), 57 - (302, [ 58 - "E", 59 - ]), 60 - (404, [ 61 - "test.bin", 62 - "test.bin/test", 63 - "test.bin/test.py", 64 - "test", 65 - "test/test", 66 - "test.bin/test.py", 67 - "E.bin", 68 - "E/test", 69 - "E/test.bin", 70 - ]), 71 - (451, [ 72 - "Q.truncate", 73 - ]), 74 - ] 75 - 76 - for code, paths in rq: 77 - for p in paths: 78 - app.logger.info(f"GET {p}") 79 - rv = client.get(p) 80 - assert rv.status_code == code 81 -