Skip to content

Commit

Permalink
Get first functioning test (#23)
Browse files Browse the repository at this point in the history
* Functioning test for checking viable python versions

* Remove Python 3.8 support
  • Loading branch information
pydanny committed Sep 25, 2023
1 parent b30affa commit 22348fa
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# dj-notebook

A Jupyter notebook with access to objects from the Django ORM is a powerful tool to introspect data and run ad-hoc queries.
A Jupyter notebook with access to objects from the Django ORM is a powerful tool to introspect data and run ad-hoc queries. This works with modern Django and Python 3.9, 3.10, and 3.11.

## Features

Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ maintainers = [
{name = "Anna Zhydko", email = "anna.zhydko@krakentechnologies.ltd"}
]
classifiers = [
"Programming Language :: Python :: 3.09",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11"
]
license = {text = "GNU General Public License v3"}
dependencies = [
Expand Down
24 changes: 21 additions & 3 deletions src/dj_notebook/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
import django
import os
from django.core.management.color import no_style
from django.conf import settings as django_settings
from django_extensions.management import shells


from .shell_plus import Plus


def activate(settings: str) -> Plus:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings)
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
django.setup()
if settings == "test_harness":
# Used for testing
# NOTE: This is bad code smell, we'll improve on it
# when we have a better idea of what we're doing
django_settings.configure(
INSTALLED_APPS=[
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]
)
else:
# Used for standard operations
os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings)
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
django.setup()
return Plus(shells.import_objects({"quiet_load": True}, no_style()))
1 change: 1 addition & 0 deletions tests/django_test_project/example_short_form.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
],
"source": [
"from django.contrib.auth import get_user_model\n",
"\n",
"User = get_user_model()\n",
"User.objects.all()"
]
Expand Down
4 changes: 3 additions & 1 deletion tests/test_dj_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@


def test_thing():
assert activate() == "Hello, world!"
plus = activate("test_harness")
# TODO capture STDOUT and assert on it
assert plus.print() is None

0 comments on commit 22348fa

Please sign in to comment.