radiac / nanodjango

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

pytest integration #20

Open radiac opened 4 days ago

radiac commented 4 days 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 2 days ago

@marcgibbons is looking at this in #28