diff --git a/.gitignore b/.gitignore index b9e9837..d81c81b 100644 --- a/.gitignore +++ b/.gitignore @@ -160,3 +160,4 @@ cython_debug/ #.idea/ wheel +.ruff_cache \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 80fd0f3..2469129 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,34 +44,15 @@ classifiers = [ "Homepage" = "https://www.pramari.de" "Bug Tracker" = "https://github.com/pramari/npc/issues" -[tool.tox] -min_version = 4.0 -legacy_tox_ini = """ - [tox] - isolated_build = True - env_list = - py312 - type - - [testenv] - setenv = - DJANGO_SETTINGS_MODULE=tests.settings - PYTHONPATH = ".";{toxinidir}:{toxinidir} - - deps = - pytest - coverage - ruff - commands = - ruff check webapp - coverage run --source webapp tests/manage.py test --settings=tests.settings - coverage xml -""" +[tool.pytest] +DJANGO_SETTINGS_MODULE = "tests.settings" [tool.pytest.ini_options] +python_files = "tests.py test_*.py" +# python_files = ["test_*.py", "tests.py"] DJANGO_SETTINGS_MODULE = "tests.settings" -python_files = ["test_*.py"] + [tool.coverage.run] source = ["webapp"] @@ -133,3 +114,30 @@ line-ending = "auto" docstring-code-format = false docstring-code-line-length = "dynamic" +[tool.tox] +min_version = 4.0 +legacy_tox_ini = """ + [tox] + isolated_build = True + env_list = + py312 + type + + [testenv] + setenv = + DJANGO_SETTINGS_MODULE=tests.settings + PYTHONPATH = ".";{toxinidir}:{toxinidir} + + deps = + coverage + pytest + pytest-django + pytest-cov + ruff + + commands = + ruff check webapp + pytest webapp + # coverage run --source webapp tests/manage.py test --settings=tests.settings + # coverage xml +""" \ No newline at end of file diff --git a/setupcfg.old b/setupcfg.old deleted file mode 100644 index 6c8c066..0000000 --- a/setupcfg.old +++ /dev/null @@ -1,23 +0,0 @@ -[metadata] -name = pramari-webapp -version = 0.1 -description = A Django app to manage identities and user-flows. -long_description = file: README.md -url = https://pramari.de -author = Andreas Neumeier -author_email = andreas@neumeier.org -license = BSD-3-Clause # Example license -classifiers = - Environment :: Web Environment - Framework :: Django - Framework :: Django :: 4.2 - Intended Audience :: Developers - License :: OSI Approved :: BSD License - Operating System :: OS Independent - Programming Language :: Python - Programming Language :: Python :: 3 - Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.11 - Programming Language :: Python :: 3.12 - Topic :: Internet :: WWW/HTTP - Topic :: Internet :: WWW/HTTP :: Dynamic Content diff --git a/tests/remove_views.py b/tests/remove_views.py deleted file mode 100644 index 7ed1999..0000000 --- a/tests/remove_views.py +++ /dev/null @@ -1,8 +0,0 @@ -from django.test import TestCase - -class CICDTests(TestCase): - def test_isExecuted(self): - """ - will pass. - """ - self.assertIs(True, True) diff --git a/tests/settings.py b/tests/settings.py index 182661f..03e5775 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -23,7 +23,6 @@ STATIC_URL = "/" MEDIA_URL = "/media/" INSTALLED_APPS = [ - "webapp", "django.contrib.contenttypes", "django.contrib.sites", "django.contrib.sessions", @@ -33,6 +32,7 @@ "allauth.account", "allauth.socialaccount", "oauth2_provider", + "webapp", ] MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", diff --git a/tests/testsettings.py b/tests/testsettings.py deleted file mode 100644 index 25f2e34..0000000 --- a/tests/testsettings.py +++ /dev/null @@ -1,14 +0,0 @@ -SECRET_KEY = "fake-key" -MIDDLEWARE = [ - "allauth.account.middleware.AccountMiddleware" -] -INSTALLED_APPS = [ - "django.contrib.auth", - "django.contrib.contenttypes", - "django.contrib.sessions", - "allauth", - "allauth.account", - "allauth.socialaccount", - "webapp", - "django_task", -] diff --git a/unused-setup.py b/unused-setup.py deleted file mode 100644 index 6068493..0000000 --- a/unused-setup.py +++ /dev/null @@ -1,3 +0,0 @@ -from setuptools import setup - -setup() diff --git a/webapp/models/activitypub/actor.py b/webapp/models/activitypub/actor.py index 1169173..413605e 100644 --- a/webapp/models/activitypub/actor.py +++ b/webapp/models/activitypub/actor.py @@ -68,6 +68,12 @@ class Actor(models.Model): `actor` has `liked`. The `liked` property is *OPTIONAL* for `Actor` objects. + - `follows` - a django `ManyToManyField` relationshio to `self` that + stores any `actors` that this `actor` is `follows`. + + - `followed_by` - a django `ManyToManyField` relationshio to `self` that + stores any `actors` that are `following` this `actor`. + .. seealso:: The definition of W3C ActivityPub `Actor Objects `_ @@ -84,32 +90,33 @@ class Actor(models.Model): .. doctest:: Actor.objects.create(id='https://example.com/actor') + Actor.objects.create(id='https://example.com/other') actor = Actor.objects.get(id='https://example.com/actor') + other = Actor.objects.get(id='https://example.com/other') The `Actor` object will provide required and some optional properties: .. testcode:: - actor.inbox + actor.id This will produce the full url for the `inbox` of the actor: .. testoutput:: - 'https://example.com/actor/inbox' + 'https://example.com/actor' The `Actor` object will provide required and some optional properties: .. testcode:: + actor.follows.add(other) actor.follows.all() - actor.followed_by.all() - Will return the `actors` that are `followed` by this `actor` and the - `actors` that are `following` this `actor`: + This will add the `other` actor to the `follows` of the `actor`: .. testoutput:: - , ]> - ]> + + ]> """ profile = models.ForeignKey( diff --git a/webapp/tests/__init__.py b/webapp/tests/__init__.py index 8ee1a20..9b0c38c 100644 --- a/webapp/tests/__init__.py +++ b/webapp/tests/__init__.py @@ -9,10 +9,10 @@ from webapp.tests.activitypub.action import ActionTest from webapp.tests.activitypub.remote import ActivityPubTest from webapp.tests.activitypub.activityobject import ActivityObjectTest -from webapp.tests.following import FollowingTest -from webapp.tests.outbox import OutboxTest -from webapp.tests.webfinger import WebfingerTests -from webapp.tests.actor import ActorTestCase +from webapp.tests.test_following import FollowingTest +from webapp.tests.test_outbox import OutboxTest +from webapp.tests.test_webfinger import WebfingerTests +from webapp.tests.test_actor import ActorTestCase # from webapp.tests.signature import SignatureTest from webapp.tests.web import WebLikeTest diff --git a/webapp/tests/activitypub/activityobject.py b/webapp/tests/activitypub/activityobject.py index 5814d78..9338009 100644 --- a/webapp/tests/activitypub/activityobject.py +++ b/webapp/tests/activitypub/activityobject.py @@ -1,7 +1,7 @@ # Description: This file contains the test cases for the ActivityObject class. from django.test import TestCase from webapp.activity import ActivityObject -from webapp.tests.messages import w3c_activity +from webapp.tests.rename_messages import w3c_activity class ActivityObjectTest(TestCase): diff --git a/webapp/tests/activitypub/inbox.py b/webapp/tests/activitypub/inbox.py index 60bf900..0014855 100644 --- a/webapp/tests/activitypub/inbox.py +++ b/webapp/tests/activitypub/inbox.py @@ -63,7 +63,7 @@ def test_follow_1(self): It's unclear where the error is. """ - from webapp.tests.messages import w3c_activity + from webapp.tests.rename_messages import w3c_activity for message in w3c_activity['follow']: result = self.client.post( @@ -100,7 +100,7 @@ def test_random(self): from ActivityPub and others. """ from webapp.exceptions import ParseActivityError - from webapp.tests.messages import follow + from webapp.tests.rename_messages import follow data = json.dumps(follow) self.client.post( diff --git a/webapp/tests/messages.py b/webapp/tests/rename_messages.py similarity index 100% rename from webapp/tests/messages.py rename to webapp/tests/rename_messages.py diff --git a/webapp/tests/actor.py b/webapp/tests/test_actor.py similarity index 100% rename from webapp/tests/actor.py rename to webapp/tests/test_actor.py diff --git a/webapp/tests/following.py b/webapp/tests/test_following.py similarity index 100% rename from webapp/tests/following.py rename to webapp/tests/test_following.py diff --git a/webapp/tests/outbox.py b/webapp/tests/test_outbox.py similarity index 100% rename from webapp/tests/outbox.py rename to webapp/tests/test_outbox.py diff --git a/webapp/tests/signature.py b/webapp/tests/test_signature.py similarity index 97% rename from webapp/tests/signature.py rename to webapp/tests/test_signature.py index c06122c..9d64d43 100644 --- a/webapp/tests/signature.py +++ b/webapp/tests/test_signature.py @@ -5,7 +5,7 @@ from webapp.models import Profile from webapp.signature import Signature, SignatureChecker, signedRequest -from webapp.tests.messages import follow +from webapp.tests.rename_messages import follow testsignature = { "signature": 'keyId="https://23.social/users/andreasofthings#main-key",algorithm="rsa-sha256",headers="(request-target) host date digest content-type",signature="e5Vj4XBt9B/TJSI4iJPDW3NtAXtOM8Z6y0j72uglfSi/R1xVwUvGcgu/r0h5yaf8e5weBZcuQ7t4ztMJfQGhol2weRWqFiC5vN1SkJTnen669sX0z6JPR/9FV9piEeSLCGHdW1wscR0c1XIQNciciPB8RrgouEQxmOxPCvlXFxqQeAVRH82d5UObSU9XQOx9/j8et/lCPegQuDM00l6qmhAAwqX7UnVDrNUJgN3eYcJpOMGfGNeymdZwf3j8/CAdQGgQPfzuNmDHvy4Wo79BZV4ud9mkVquEAh7RagfwIQRUtM/mI2i2qGrXwnpjwhOgxJkjoG7Fc18qvzuT3nQfQg=="', # noqa: E501 @@ -65,8 +65,8 @@ def test_request_signed(self): Test whether a request can be signed. """ - user = Profile.objects.get(user=self.user) - key_id = user.get_key_id + profile = Profile.objects.get(user=self.user) + key_id = profile.actor.keyID ses, request = signedRequest( "GET", "https://pramari.de/signature", follow, key_id diff --git a/webapp/tests/webfinger.py b/webapp/tests/test_webfinger.py similarity index 100% rename from webapp/tests/webfinger.py rename to webapp/tests/test_webfinger.py diff --git a/webapp/views/web/likes.py b/webapp/views/web/likes.py index 1abc1b1..b145ff9 100644 --- a/webapp/views/web/likes.py +++ b/webapp/views/web/likes.py @@ -58,6 +58,7 @@ def form_valid(self, form): action_object=self.object, ) actor = self.request.user.profile_set.get().actor + print("DEBUG: ", settings.DEBUG) if settings.DEBUG: sendLike(actor.id, form.cleaned_data["object"]) else: