From aaf365dba27b6ed63384d054dce9f10e20a90ad3 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Thu, 15 Apr 2021 09:40:32 +0200 Subject: [PATCH] Add webpush model checks into sub test Let the formatter have its way also. --- .../tests/tests_accept_subscription.py | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/djangoldp_webpushnotification/tests/tests_accept_subscription.py b/djangoldp_webpushnotification/tests/tests_accept_subscription.py index 2e10fd6..eaa1117 100644 --- a/djangoldp_webpushnotification/tests/tests_accept_subscription.py +++ b/djangoldp_webpushnotification/tests/tests_accept_subscription.py @@ -1,14 +1,17 @@ import json from django.contrib.auth import get_user_model -from django.urls import reverse from django.test import Client, TestCase +from django.urls import reverse +from webpush.models import PushInformation, SubscriptionInfo class TestAcceptSubscription(TestCase): def setUp(self): self.client = Client() - self.user = get_user_model().objects.create(username='john', email='jlennon@beatles.com', password='glass onion') + self.user = get_user_model().objects.create( + username="john", email="jlennon@beatles.com", password="glass onion" + ) self.client.force_login(self.user) def tearDown(self): @@ -16,18 +19,27 @@ class TestAcceptSubscription(TestCase): def test_accept_sub(self): payload = { - "status_type": "subscribe", - "subscription": { - "endpoint": "example.com", - "keys": { - "auth": "barfoo", - "p256dh": "foobar" - } - }, - "browser": "firefox" + "status_type": "subscribe", + "subscription": { + "endpoint": "https://example.com", + "keys": {"auth": "barfoo", "p256dh": "foobar"}, + }, + "browser": "firefox", } url = reverse("save_webpush_info") - response = self.client.post(url, data=json.dumps(payload), content_type='application/json') + response = self.client.post( + url, data=json.dumps(payload), content_type="application/json" + ) self.assertEqual(response.status_code, 201) + + sub_info = SubscriptionInfo.objects.get() + self.assertEqual(sub_info.browser, "firefox") + self.assertEqual(sub_info.endpoint, "https://example.com") + self.assertEqual(sub_info.auth, "barfoo") + self.assertEqual(sub_info.p256dh, "foobar") + + push_info = PushInformation.objects.get() + self.assertEqual(push_info.user, self.user) + self.assertEqual(push_info.subscription, sub_info)