radiac / nanodjango

Full Django in a single file - views, models, API ,with async support. Automatically convert it to a full project.
537 stars 23 forks source link

pytest integration #20

Open radiac opened 1 month ago

radiac commented 1 month ago

Idea:

from django.db import models
from nanodjango import Django

app = Django()

@app.admin
class CountLog(models.Model):
    # Standard Django model, registered with the admin site
    timestamp = models.DateTimeField(auto_now_add=True)

@app.route("/")
def count(request):
    # Standard Django function view
    CountLog.objects.create()
    return f"<p>Number of page loads: {CountLog.objects.count()}</p>"

def test_count():
    assert CountLog.objects.count() == 0
    CountLog.objects.create()
    assert CountLog.objects.count() == 1

then test with

nanodjango test counter.py
radiac commented 1 month ago

@marcgibbons is looking at this in #28