Add simple integration tests
This commit is contained in:
parent
5743dd7096
commit
72f78f89ae
2 changed files with 49 additions and 1 deletions
|
|
@ -6,6 +6,8 @@ from django.core.cache import cache
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
from newsreader.accounts.tests.factories import UserFactory
|
from newsreader.accounts.tests.factories import UserFactory
|
||||||
from newsreader.news.collection.exceptions import (
|
from newsreader.news.collection.exceptions import (
|
||||||
StreamException,
|
StreamException,
|
||||||
|
|
@ -13,6 +15,53 @@ from newsreader.news.collection.exceptions import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class IntegrationsViewTestCase(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.user = UserFactory(email="test@test.nl", password="test")
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
|
||||||
|
self.url = reverse("accounts:integrations")
|
||||||
|
|
||||||
|
|
||||||
|
class RedditIntegrationsTestCase(IntegrationsViewTestCase):
|
||||||
|
def test_reddit_authorization(self):
|
||||||
|
self.user.reddit_refresh_token = None
|
||||||
|
self.user.save()
|
||||||
|
|
||||||
|
response = self.client.get(self.url)
|
||||||
|
|
||||||
|
soup = BeautifulSoup(response.content, features="lxml")
|
||||||
|
button = soup.find("a", class_="link button button--reddit")
|
||||||
|
|
||||||
|
self.assertEquals(button.text.strip(), "Authorize account")
|
||||||
|
|
||||||
|
def test_reddit_refresh_token(self):
|
||||||
|
self.user.reddit_refresh_token = "jadajadajada"
|
||||||
|
self.user.reddit_access_token = None
|
||||||
|
self.user.save()
|
||||||
|
|
||||||
|
response = self.client.get(self.url)
|
||||||
|
|
||||||
|
soup = BeautifulSoup(response.content, features="lxml")
|
||||||
|
button = soup.find("a", class_="link button button--reddit")
|
||||||
|
|
||||||
|
self.assertEquals(button.text.strip(), "Refresh token")
|
||||||
|
|
||||||
|
def test_reddit_revoke(self):
|
||||||
|
self.user.reddit_refresh_token = "jadajadajada"
|
||||||
|
self.user.reddit_access_token = None
|
||||||
|
self.user.save()
|
||||||
|
|
||||||
|
response = self.client.get(self.url)
|
||||||
|
|
||||||
|
soup = BeautifulSoup(response.content, features="lxml")
|
||||||
|
buttons = soup.find_all("a", class_="link button button--reddit")
|
||||||
|
|
||||||
|
self.assertIn(
|
||||||
|
"Deauthorize account", [button.text.strip() for button in buttons]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RedditTemplateViewTestCase(TestCase):
|
class RedditTemplateViewTestCase(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.user = UserFactory(email="test@test.nl", password="test")
|
self.user = UserFactory(email="test@test.nl", password="test")
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ from newsreader.news.collection.tasks import RedditTokenTask
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
# TODO add tests
|
|
||||||
class IntegrationsView(TemplateView):
|
class IntegrationsView(TemplateView):
|
||||||
template_name = "accounts/views/integrations.html"
|
template_name = "accounts/views/integrations.html"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue