2022-06-05 22:48:31 +00:00
|
|
|
# Copyright © 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2022-06-05 19:45:42 +00:00
|
|
|
|
2022-06-05 22:48:31 +00:00
|
|
|
|
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from django.urls import reverse
|
|
|
|
from django.test import TestCase, Client
|
|
|
|
|
|
|
|
from .views import CREATE_APP_CTX, new_app
|
|
|
|
|
|
|
|
|
|
|
|
class CreateNewAppTests(TestCase):
|
|
|
|
"""
|
|
|
|
Tests create new app view
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.password = "password121231"
|
|
|
|
self.user = get_user_model().objects.create_user(
|
|
|
|
username="create_new_app_tests",
|
|
|
|
email="create_new_app_tests@example.org",
|
|
|
|
password=self.password,
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_create_new_app_unauthenticated_user(self):
|
|
|
|
"""
|
|
|
|
Tests if new_app is accessible only when user is authenticated
|
|
|
|
"""
|
|
|
|
resp = self.client.get(reverse("oauth.integrations.new_app"))
|
|
|
|
self.assertEqual(resp.status_code, 302)
|
|
|
|
|
|
|
|
def test_create_new_app_renders(self):
|
|
|
|
"""
|
|
|
|
Tests new_app template render
|
|
|
|
"""
|
|
|
|
|
|
|
|
c = Client()
|
|
|
|
c.login(username=self.user.username, password=self.password)
|
|
|
|
c.session.save()
|
|
|
|
|
|
|
|
resp = c.get(reverse("oauth.integrations.new_app"))
|
|
|
|
self.assertEqual(resp.status_code, 200)
|
|
|
|
for (_, value) in CREATE_APP_CTX.items():
|
|
|
|
self.assertContains(resp, value)
|
|
|
|
|
|
|
|
def test_new_app_submission(self):
|
|
|
|
"""
|
|
|
|
Tests new_app template render
|
|
|
|
"""
|
|
|
|
payload = {
|
|
|
|
"name": "test_new_app_submission",
|
|
|
|
"redirect_uri": "https://test_new_app_submission.example.org",
|
|
|
|
}
|
|
|
|
c = Client()
|
|
|
|
c.login(username=self.user.username, password=self.password)
|
|
|
|
c.session.save()
|
|
|
|
resp = c.post(reverse("oauth.integrations.new_app"), payload)
|
|
|
|
self.assertEqual(resp.status_code, 200)
|