Skip to content

Commit

Permalink
Test Like Web UI
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasofthings authored Aug 11, 2024
1 parent ac8de21 commit 5f35ff6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
6 changes: 6 additions & 0 deletions webapp/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from webapp.tests.actor import ActorTestCase
# from webapp.tests.signature import SignatureTest

from webapp.tests.web import WebLikeTest

logger = logging.getLogger(__name__)

__all__ = [
Expand All @@ -30,6 +32,10 @@
"ActivityObjectTest",
]

__all__ = [
"WebLikeTest",
]

status_code = 404


Expand Down
40 changes: 40 additions & 0 deletions webapp/tests/web/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from django.test import TestCase
from django.contrib.auth import get_user_model

from webapp.models import Like

class WebLikeTest(TestCase):
def setUp(self):
User = get_user_model()
self.client = Client()
self.username = "andreas"
user = User.objects.create_user(username=self.username, password="password")

def test_like_create_anonymous(self):
self.client.get(reverse("like-create")
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, "/accounts/login/?next=/like/")
self.assertEqual(Like.objects.count(), 0)

def test_like_create_authenticated(self):
self.client.login(username=self.username, password="password")
response = self.client.get(reverse("like-create"))
self.assertEqual(response.status_code, 200)
self.client.post(reverse("like-create"), data={"object": "http://example.com"})
self.assertEqual(Like.objects.count(), 1)

def test_like_list(self):
response = self.client.get(reverse("like-list"))
self.assertEqual(response.status_code, 200)

def test_like_detail(self):
like = Like.objects.create(object="http://example.com")
response = self.client.get(reverse("like-detail", kwargs={"pk": like.pk}))
self.assertEqual(response.status_code, 200)

def test_like_delete(self):
like = Like.objects.create(object="http://example.com")
response = self.client.get(reverse("like-delete", kwargs={"pk": like.pk}))
self.assertEqual(response.status_code, 200)
self.client.post(reverse("like-delete", kwargs={"pk": like.pk}))
self.assertEqual(Like.objects.count(), 0)

0 comments on commit 5f35ff6

Please sign in to comment.