From c19d34f336d1d04d1dc9a69a13d8bab63f2ea40b Mon Sep 17 00:00:00 2001 From: Joe Kaufeld Date: Mon, 16 Sep 2024 18:34:55 -0400 Subject: [PATCH] :rotating_light: fix ruff errors --- example.py | 2 +- spiderweb/db.py | 6 ++-- spiderweb/main.py | 8 +++++- spiderweb/routes.py | 2 +- spiderweb/tests/__init__.py | 4 --- spiderweb/tests/test_middleware.py | 2 +- spiderweb/tests/test_responses.py | 4 +-- spiderweb/tests/test_variable_urls.py | 5 ---- test.py | 40 --------------------------- 9 files changed, 15 insertions(+), 58 deletions(-) delete mode 100644 test.py diff --git a/example.py b/example.py index f071d0b..8a315bc 100644 --- a/example.py +++ b/example.py @@ -37,7 +37,7 @@ def index(request): @app.route("/example//") -def example(request, id, name): +def example_with_multiple_values(request, id, name): return HttpResponse(body=f"Example with id {id} and name {name}") diff --git a/spiderweb/db.py b/spiderweb/db.py index 602b6b0..ace5eb5 100644 --- a/spiderweb/db.py +++ b/spiderweb/db.py @@ -1,4 +1,4 @@ -from peewee import Model, Field, SchemaManager, DatabaseProxy +from peewee import Model, Field, SchemaManager from spiderweb.constants import DATABASE_PROXY @@ -67,7 +67,7 @@ class SpiderwebModel(Model): ) ) if field_obj.__class__.__name__ == "BooleanField": - if field_obj.default == False and db_version["default"] not in ( + if field_obj.default is False and db_version["default"] not in ( False, None, 0, @@ -77,7 +77,7 @@ class SpiderwebModel(Model): f"BooleanField `{field_name}` has changed the default value." ) ) - elif field_obj.default == True and db_version["default"] not in ( + elif field_obj.default is True and db_version["default"] not in ( True, 1, ): diff --git a/spiderweb/main.py b/spiderweb/main.py index d7d3c5c..ddc6a37 100644 --- a/spiderweb/main.py +++ b/spiderweb/main.py @@ -23,7 +23,13 @@ from spiderweb.constants import ( DEFAULT_ALLOWED_METHODS, ) from spiderweb.db import SpiderwebModel -from spiderweb.default_views import * # noqa: F403 +from spiderweb.default_views import ( + http403, # noqa: F401 + http404, # noqa: F401 + http405, # noqa: F401 + http500, # noqa: F401 + send_file, +) from spiderweb.exceptions import ( ConfigError, NotFound, diff --git a/spiderweb/routes.py b/spiderweb/routes.py index a22a21a..8286957 100644 --- a/spiderweb/routes.py +++ b/spiderweb/routes.py @@ -1,5 +1,5 @@ import re -from typing import Callable, Any, Optional, Sequence +from typing import Callable, Any, Sequence from spiderweb.constants import DEFAULT_ALLOWED_METHODS from spiderweb.converters import * # noqa: F403 diff --git a/spiderweb/tests/__init__.py b/spiderweb/tests/__init__.py index cec2bf9..e69de29 100644 --- a/spiderweb/tests/__init__.py +++ b/spiderweb/tests/__init__.py @@ -1,4 +0,0 @@ -from spiderweb.tests.middleware import ( - ExplodingResponseMiddleware, - ExplodingRequestMiddleware, -) diff --git a/spiderweb/tests/test_middleware.py b/spiderweb/tests/test_middleware.py index b42fa61..7b49c46 100644 --- a/spiderweb/tests/test_middleware.py +++ b/spiderweb/tests/test_middleware.py @@ -171,7 +171,7 @@ def test_csrf_middleware(): assert "bob" in resp2 # test that it raises a CSRF error on wrong token - formdata = f"name=bob&csrf_token=badtoken" + formdata = "name=bob&csrf_token=badtoken" b_handle = BytesIO() b_handle.write(formdata.encode(DEFAULT_ENCODING)) b_handle.seek(0) diff --git a/spiderweb/tests/test_responses.py b/spiderweb/tests/test_responses.py index f135825..cffa607 100644 --- a/spiderweb/tests/test_responses.py +++ b/spiderweb/tests/test_responses.py @@ -104,7 +104,7 @@ def test_redirect_on_append_slash(): def index(request): pass - environ["PATH_INFO"] = f"/hello" + environ["PATH_INFO"] = "/hello" assert app(environ, start_response) == [b"None"] assert start_response.get_headers()["location"] == "/hello/" @@ -205,7 +205,7 @@ def test_view_can_be_reversed(): def index(request): ... @app.route("/", name="qwer") - def index(request, hi): ... + def index2(request, hi): ... assert app.reverse("asdfasdf") == "/" assert app.reverse("asdfasdf", {"id": 1}) == "/" diff --git a/spiderweb/tests/test_variable_urls.py b/spiderweb/tests/test_variable_urls.py index ce0ff76..44ec5a9 100644 --- a/spiderweb/tests/test_variable_urls.py +++ b/spiderweb/tests/test_variable_urls.py @@ -1,17 +1,12 @@ import pytest -from spiderweb import SpiderwebRouter from spiderweb.constants import DEFAULT_ENCODING from spiderweb.exceptions import ParseError, ConfigError from spiderweb.response import ( HttpResponse, - JsonResponse, - TemplateResponse, - RedirectResponse, ) from hypothesis import given, strategies as st, assume -from peewee import SqliteDatabase from spiderweb.tests.helpers import setup diff --git a/test.py b/test.py deleted file mode 100644 index 04eaa41..0000000 --- a/test.py +++ /dev/null @@ -1,40 +0,0 @@ -from peewee import * -from playhouse.migrate import SqliteMigrator, migrate - -from spiderweb.db import SpiderwebModel - -db = SqliteDatabase("people.db") -migrator = SqliteMigrator(db) - - -class Person(SpiderwebModel): - name = CharField() - birthday = DateField() - - class Meta: - database = db # This model uses the "people.db" database. - - -class Pet(SpiderwebModel): - owner = ForeignKeyField(Person, backref="pets") - name = CharField(max_length=40) - animal_type = CharField() - age = IntegerField(null=True) - favorite_color = CharField(null=True) - - class Meta: - database = db # this model uses the "people.db" database - - -if __name__ == "__main__": - db.connect() - Pet.check_for_needed_migration() - # try: - # Pet.check_for_needed_migration() - # except: - # migrate( - # migrator.add_column( - # Pet._meta.table_name, 'favorite_color', CharField(null=True) - # ), - # ) - db.create_tables([Person, Pet])