Compare commits
No commits in common. "c19d34f336d1d04d1dc9a69a13d8bab63f2ea40b" and "1b7ceb900b98787b19cc3bae817ff1eba8162e0c" have entirely different histories.
c19d34f336
...
1b7ceb900b
@ -37,7 +37,7 @@ def index(request):
|
||||
|
||||
|
||||
@app.route("/example/<int:id>/<str:name>")
|
||||
def example_with_multiple_values(request, id, name):
|
||||
def example(request, id, name):
|
||||
return HttpResponse(body=f"Example with id {id} and name {name}")
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
from peewee import Model, Field, SchemaManager
|
||||
from peewee import Model, Field, SchemaManager, DatabaseProxy
|
||||
|
||||
from spiderweb.constants import DATABASE_PROXY
|
||||
|
||||
@ -67,7 +67,7 @@ class SpiderwebModel(Model):
|
||||
)
|
||||
)
|
||||
if field_obj.__class__.__name__ == "BooleanField":
|
||||
if field_obj.default is False and db_version["default"] not in (
|
||||
if field_obj.default == 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 is True and db_version["default"] not in (
|
||||
elif field_obj.default == True and db_version["default"] not in (
|
||||
True,
|
||||
1,
|
||||
):
|
||||
|
@ -23,13 +23,7 @@ from spiderweb.constants import (
|
||||
DEFAULT_ALLOWED_METHODS,
|
||||
)
|
||||
from spiderweb.db import SpiderwebModel
|
||||
from spiderweb.default_views import (
|
||||
http403, # noqa: F401
|
||||
http404, # noqa: F401
|
||||
http405, # noqa: F401
|
||||
http500, # noqa: F401
|
||||
send_file,
|
||||
)
|
||||
from spiderweb.default_views import * # noqa: F403
|
||||
from spiderweb.exceptions import (
|
||||
ConfigError,
|
||||
NotFound,
|
||||
@ -184,9 +178,7 @@ class SpiderwebRouter(LocalServerMixin, MiddlewareMixin, RoutesMixin, FernetMixi
|
||||
raise ConfigError
|
||||
if self.debug:
|
||||
# We don't need a log message here because this is the expected behavior
|
||||
self.add_route(
|
||||
rf"/{self.static_url}/<path:filename>", send_file
|
||||
) # noqa: F405
|
||||
self.add_route(rf"/{self.static_url}/<path:filename>", send_file) # noqa: F405
|
||||
else:
|
||||
self.log.warning(
|
||||
"`staticfiles_dirs` is set, but `debug` is set to FALSE. Static"
|
||||
|
@ -1,5 +1,5 @@
|
||||
import re
|
||||
from typing import Callable, Any, Sequence
|
||||
from typing import Callable, Any, Optional, Sequence
|
||||
|
||||
from spiderweb.constants import DEFAULT_ALLOWED_METHODS
|
||||
from spiderweb.converters import * # noqa: F403
|
||||
|
@ -0,0 +1,4 @@
|
||||
from spiderweb.tests.middleware import (
|
||||
ExplodingResponseMiddleware,
|
||||
ExplodingRequestMiddleware,
|
||||
)
|
@ -171,7 +171,7 @@ def test_csrf_middleware():
|
||||
assert "bob" in resp2
|
||||
|
||||
# test that it raises a CSRF error on wrong token
|
||||
formdata = "name=bob&csrf_token=badtoken"
|
||||
formdata = f"name=bob&csrf_token=badtoken"
|
||||
b_handle = BytesIO()
|
||||
b_handle.write(formdata.encode(DEFAULT_ENCODING))
|
||||
b_handle.seek(0)
|
||||
|
@ -104,7 +104,7 @@ def test_redirect_on_append_slash():
|
||||
def index(request):
|
||||
pass
|
||||
|
||||
environ["PATH_INFO"] = "/hello"
|
||||
environ["PATH_INFO"] = f"/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("/<int:hi>", name="qwer")
|
||||
def index2(request, hi): ...
|
||||
def index(request, hi): ...
|
||||
|
||||
assert app.reverse("asdfasdf") == "/"
|
||||
assert app.reverse("asdfasdf", {"id": 1}) == "/"
|
||||
|
@ -1,12 +1,17 @@
|
||||
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
|
||||
|
||||
|
40
test.py
Normal file
40
test.py
Normal file
@ -0,0 +1,40 @@
|
||||
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])
|
Loading…
Reference in New Issue
Block a user