Skip to content

Commit c06d3d0

Browse files
committed
Tests added, Cleanup
1 parent ab2c7a0 commit c06d3d0

File tree

11 files changed

+159
-18
lines changed

11 files changed

+159
-18
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
- id: blacken-docs
1818
additional_dependencies:
1919
- black==24.10.0
20-
files: '(?:README\.md|docs\/.*\.(?:md|rst))'
20+
files: '(?:README\.md|\.ambient-package-update\/templates\/snippets\/.*\.tpl|docs\/.*\.(?:md|rst))'
2121

2222
- repo: https://github.com/asottile/pyupgrade
2323
rev: v3.19.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ write me
6464

6565
- Check coverage
6666
````
67-
coverage run -m pytest --ds settingstests
67+
coverage run -m pytest --ds settings tests
6868
coverage report -m
6969
````
7070

manage.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
4+
import os
5+
import sys
6+
7+
8+
def main():
9+
"""Run administrative tasks."""
10+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
11+
try:
12+
from django.core.management import execute_from_command_line
13+
except ImportError as exc:
14+
raise ImportError( # noqa: TRY003
15+
"Couldn't import Django. Are you sure it's installed and "
16+
"available on your PYTHONPATH environment variable? Did you "
17+
"forget to activate a virtual environment?"
18+
) from exc
19+
execute_from_command_line(sys.argv)
20+
21+
22+
if __name__ == "__main__":
23+
main()

queuebie/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# TODO: is this thread-safe? does it matter? -> prove with unit-tests
99
message_registry = MessageRegistry()
1010

11-
# todo:
11+
# TODO: tasks for v1.0
1212
# -> docs with examples
1313
# -> tests
1414
# -> fix all code todos

queuebie/messages.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
import inspect
1+
import abc
22
import uuid
33
from dataclasses import dataclass
44

55
from queuebie.exceptions import MessageContextWrongTypeError
66

77

8-
# TODO: do we want to make it inherit from ABC?
9-
class Message:
8+
class Message(abc.ABC):
9+
"""
10+
Base class for all commands and events.
11+
"""
12+
1013
uuid = str
1114
Context: dataclass
1215

@@ -15,17 +18,11 @@ class Context:
1518
def __init__(self, **kwargs):
1619
raise NotImplementedError
1720

18-
@classmethod
19-
def _from_dict_to_dataclass(cls, *, context_data: dict) -> "Message.Context":
20-
return cls.Context(
21-
**{
22-
key: (context_data[key] if val.default == val.empty else context_data.get(key, val.default))
23-
for key, val in inspect.signature(cls.Context).parameters.items()
24-
}
25-
)
21+
def __init__(self, context: "Message.Context") -> None:
22+
super().__init__()
2623

27-
def __init__(self, context: "Message.Context"):
2824
self.uuid = str(uuid.uuid4())
25+
2926
if type(context) is not self.Context:
3027
raise MessageContextWrongTypeError(class_name=self.__class__.__name__)
3128
self.Context = context
@@ -35,8 +32,14 @@ def __str__(self) -> str:
3532

3633

3734
class Command(Message):
38-
pass
35+
"""
36+
Commands are messages which prompt the system to do something.
37+
Are always written in present tense: "CreateInvoice".
38+
"""
3939

4040

4141
class Event(Message):
42-
pass
42+
"""
43+
Events are the results of a command.
44+
Are always written in past tense: "InvoiceCreated".
45+
"""

queuebie/registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def autodiscover(self) -> None:
7070
return
7171

7272
# Import all messages in all installed apps to trigger notification class registration via decorator
73-
# todo: can we not do this on every request?
73+
# TODO: can we not do this on every request?
7474
for app in settings.INSTALLED_APPS:
7575
if app[:5] != "apps.":
7676
continue

settings.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from pathlib import Path
2+
3+
BASE_PATH = Path(__file__).resolve(strict=True).parent
4+
5+
INSTALLED_APPS = (
6+
"django.contrib.admin",
7+
"django.contrib.auth",
8+
"django.contrib.contenttypes",
9+
"django.contrib.sessions",
10+
"django.contrib.messages",
11+
"django.contrib.staticfiles",
12+
"queuebie",
13+
"testapp",
14+
)
15+
16+
DEBUG = False
17+
18+
ALLOWED_HOSTS = ["localhost:8000"]
19+
20+
SECRET_KEY = "ASDFjklö123456890"
21+
22+
# Routing
23+
ROOT_URLCONF = "testapp.urls"
24+
25+
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
26+
27+
DATABASES = {
28+
"default": {
29+
"ENGINE": "django.db.backends.sqlite3",
30+
"NAME": "db.sqlite",
31+
}
32+
}
33+
34+
TEMPLATES = [
35+
{
36+
"BACKEND": "django.template.backends.django.DjangoTemplates",
37+
"DIRS": ["templates"],
38+
"APP_DIRS": True,
39+
"OPTIONS": {
40+
"context_processors": [
41+
"django.template.context_processors.debug",
42+
"django.template.context_processors.request",
43+
"django.contrib.auth.context_processors.auth",
44+
"django.contrib.messages.context_processors.messages",
45+
],
46+
"debug": True,
47+
},
48+
},
49+
]
50+
51+
MIDDLEWARE = (
52+
"django.middleware.security.SecurityMiddleware",
53+
"django.contrib.sessions.middleware.SessionMiddleware",
54+
"django.middleware.common.CommonMiddleware",
55+
"django.middleware.csrf.CsrfViewMiddleware",
56+
"django.contrib.auth.middleware.AuthenticationMiddleware",
57+
"django.contrib.messages.middleware.MessageMiddleware",
58+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
59+
)
60+
61+
USE_TZ = True
62+
TIME_ZONE = "UTC"

testapp/__init__.py

Whitespace-only changes.

testapp/urls.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.contrib import admin
2+
from django.urls import path
3+
4+
urlpatterns = [
5+
# django Admin
6+
path("admin/", admin.site.urls),
7+
]

tests/test_apps.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django.apps import AppConfig, apps
2+
3+
4+
def test_app_config():
5+
app_config = apps.get_app_config("queuebie")
6+
7+
assert isinstance(app_config, AppConfig)
8+
assert app_config.default_auto_field == "django.db.models.BigAutoField"
9+
assert app_config.name == "queuebie"

0 commit comments

Comments
 (0)