This repository has been archived on 2021-04-21. You can view files and clone it, but cannot push or open issues or pull requests.
djangoldp-webpushnotification/djangoldp_webpushnotification/tests/tests_accept_subscription.py

34 lines
953 B
Python
Raw Normal View History

import json
from django.contrib.auth import get_user_model
from django.urls import reverse
from django.test import Client, TestCase
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.client.force_login(self.user)
def tearDown(self):
self.user.delete()
def test_accept_sub(self):
payload = {
"status_type": "subscribe",
"subscription": {
"endpoint": "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')
self.assertEqual(response.status_code, 201)