vbv/server/vbv_lernwelt/sso/tests/test_sso_authorize.py

38 lines
1.0 KiB
Python

import uuid
from unittest.mock import patch
from django.test import TestCase
from django.urls import reverse
from vbv_lernwelt.core.models import User
class TestSSO(TestCase):
def test_walking_skeleton(self):
self.assertTrue(True)
@patch("vbv_lernwelt.sso.views.oauth")
@patch("vbv_lernwelt.sso.views.decode_jwt")
def test_authorize_redirects_on_success(self, mock_decode_jwt, mock_oauth_service):
# GIVEN
email = "bobby@drop.table"
mock_oauth_service.authorize_access_token.return_value = {
"id_token": "test_token"
}
mock_decode_jwt.return_value = {
"emails": [email],
"oid": uuid.uuid4(),
"given_name": "Bobby",
"family_name": "Drop-Table",
}
# WHEN
response = self.client.get(reverse("sso:authorize"))
# THEN
self.assertTrue(User.objects.filter(email=email).exists())
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, "/")