Skip to content

Commit

Permalink
Test and packaging infrastructure.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasofthings authored Aug 14, 2024
1 parent 87ce6af commit 3c100dc
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 90 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,4 @@ cython_debug/
#.idea/

wheel
.ruff_cache
56 changes: 32 additions & 24 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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
"""
23 changes: 0 additions & 23 deletions setupcfg.old

This file was deleted.

8 changes: 0 additions & 8 deletions tests/remove_views.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
STATIC_URL = "/"
MEDIA_URL = "/media/"
INSTALLED_APPS = [
"webapp",
"django.contrib.contenttypes",
"django.contrib.sites",
"django.contrib.sessions",
Expand All @@ -33,6 +32,7 @@
"allauth.account",
"allauth.socialaccount",
"oauth2_provider",
"webapp",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
Expand Down
14 changes: 0 additions & 14 deletions tests/testsettings.py

This file was deleted.

3 changes: 0 additions & 3 deletions unused-setup.py

This file was deleted.

21 changes: 14 additions & 7 deletions webapp/models/activitypub/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.w3.org/TR/activitypub/#actor-objects>`_
Expand All @@ -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::
<QuerySet [<Actor: https://23.social/users/andreasofthings>, <Actor: https://23.social/users/christianrickert>]>
<QuerySet [<Actor: https://23.social/users/andreasofthings>]>
<QuerySet [<Actor: https://example.com/other>]>
"""

profile = models.ForeignKey(
Expand Down
8 changes: 4 additions & 4 deletions webapp/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion webapp/tests/activitypub/activityobject.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
4 changes: 2 additions & 2 deletions webapp/tests/activitypub/inbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions webapp/tests/signature.py → webapp/tests/test_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions webapp/views/web/likes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 3c100dc

Please sign in to comment.