Skip to content

Commit

Permalink
Tests for Google and Github login
Browse files Browse the repository at this point in the history
  • Loading branch information
ATHARVA-GAWAS committed Feb 27, 2024
1 parent 7482fd3 commit 31f7682
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion website/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os

import unittest
import chromedriver_autoinstaller
from django.core.files.storage import default_storage
from django.core.files.uploadedfile import SimpleUploadedFile
Expand All @@ -13,6 +13,11 @@

from .models import Issue, IssueScreenshot

from unittest.mock import patch
from django.urls import reverse
from django.test import RequestFactory, TestCase
from .views import GoogleLogin, GithubLogin

os.environ["DJANGO_LIVE_TEST_SERVER_ADDRESS"] = "localhost:8082"


Expand Down Expand Up @@ -145,3 +150,53 @@ def test_on_hide(self):

if "hidden" not in filename:
self.assertFalse(True, "files rename failed")

class TestGoogleLogin(TestCase):
def setUp(self):
self.factory = RequestFactory()

def test_callback_url(self):
view = GoogleLogin()
request = self.factory.get("/auth/google/")
request.session = {}
view.request = request

def mock_reverse(url_name):
if url_name == "google_callback":
return "http://example.com/accounts/google/login/callback/"
else:
raise ValueError("Unexpected URL name")

def mock_build_absolute_uri(uri):
return "http://example.com" + uri

with patch("django.urls.reverse", side_effect=mock_reverse):
with patch("django.http.HttpRequest.build_absolute_uri", side_effect=mock_build_absolute_uri):
callback_url = view.callback_url

self.assertEqual(callback_url, "http://example.com/accounts/google/login/callback/")

class TestGithubLogin(TestCase):
def setUp(self):
self.factory = RequestFactory()

def test_callback_url(self):
view = GithubLogin()
request = self.factory.get("auth/github/")
request.session = {}
view.request = request

def mock_reverse(url_name):
if url_name == "github_callback":
return "http://example.com/accounts/github/login/callback/"
else:
raise ValueError("Unexpected URL name")

def mock_build_absolute_uri(uri):
return "http://example.com" + uri

with patch("django.urls.reverse", side_effect=mock_reverse):
with patch("django.http.HttpRequest.build_absolute_uri", side_effect=mock_build_absolute_uri):
callback_url = view.callback_url

self.assertEqual(callback_url, "http://example.com/accounts/github/login/callback/")

0 comments on commit 31f7682

Please sign in to comment.