resolve conflicts
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
from django.test import TestCase
|
||||
from util.testing import UrlResetMixin
|
||||
from django.test.client import Client
|
||||
from django.contrib.auth.models import User
|
||||
from util.testing import UrlResetMixin
|
||||
from mock import patch
|
||||
|
||||
|
||||
class TestAutoAuthEnabled(UrlResetMixin, TestCase):
|
||||
class AutoAuthEnabledTestCase(UrlResetMixin, TestCase):
|
||||
"""
|
||||
Tests for the Auto auth view that we have for load testing.
|
||||
"""
|
||||
@@ -15,15 +16,16 @@ class TestAutoAuthEnabled(UrlResetMixin, TestCase):
|
||||
# value affects the contents of urls.py,
|
||||
# so we need to call super.setUp() which reloads urls.py (because
|
||||
# of the UrlResetMixin)
|
||||
super(TestAutoAuthEnabled, self).setUp()
|
||||
super(AutoAuthEnabledTestCase, self).setUp()
|
||||
self.url = '/auto_auth'
|
||||
self.client = Client()
|
||||
|
||||
def test_create_user(self):
|
||||
"""
|
||||
tests that user gets created when visiting the page
|
||||
Test that user gets created when visiting the page.
|
||||
"""
|
||||
|
||||
url = '/auto_auth'
|
||||
self.client.get(url)
|
||||
self.client.get(self.url)
|
||||
|
||||
qset = User.objects.all()
|
||||
|
||||
@@ -32,40 +34,29 @@ class TestAutoAuthEnabled(UrlResetMixin, TestCase):
|
||||
user = qset[0]
|
||||
assert user.is_active
|
||||
|
||||
@patch.dict("django.conf.settings.MITX_FEATURES", {"MAX_AUTO_AUTH_USERS": 10000000})
|
||||
def test_create_multiple_users(self):
|
||||
@patch('student.views.random.randint')
|
||||
def test_create_multiple_users(self, randint):
|
||||
"""
|
||||
speculative test to make sure multiple users are created.
|
||||
Technically, this test is probabalistic.
|
||||
|
||||
However, my judgement is that if the chance of failing due
|
||||
only to bad luck is less than 1:10^1000, we are OK (it is more
|
||||
likely that the test failed because the jenkins server was hit
|
||||
by an asteroid, or the person running the tests was a freind
|
||||
of Hamlet's).
|
||||
Test to make sure multiple users are created.
|
||||
"""
|
||||
randint.return_value = 1
|
||||
self.client.get(self.url)
|
||||
|
||||
url = '/auto_auth'
|
||||
|
||||
# hit the url a few times. Mathematically, is much more efficient
|
||||
# to hit the site many many times, and have a smaller MAX user
|
||||
# count, but it is the GET request that actually takes a lot of time.
|
||||
for i in range(200):
|
||||
self.client.get(url)
|
||||
randint.return_value = 2
|
||||
self.client.get(self.url)
|
||||
|
||||
qset = User.objects.all()
|
||||
|
||||
# make sure it is the smae user
|
||||
self.assertGreater(qset.count(), 1)
|
||||
# make sure that USER_1 and USER_2 were created
|
||||
self.assertEqual(qset.count(), 2)
|
||||
|
||||
@patch.dict("django.conf.settings.MITX_FEATURES", {"MAX_AUTO_AUTH_USERS": 1})
|
||||
def test_login(self):
|
||||
def test_login_already_created_user(self):
|
||||
"""
|
||||
test that when we have reached the limit for automatic users
|
||||
Test that when we have reached the limit for automatic users
|
||||
a subsequent request results in an already existant one being
|
||||
logged in.
|
||||
"""
|
||||
|
||||
# auto-generate 1 user (the max)
|
||||
url = '/auto_auth'
|
||||
self.client.get(url)
|
||||
@@ -74,11 +65,11 @@ class TestAutoAuthEnabled(UrlResetMixin, TestCase):
|
||||
self.client.get(url)
|
||||
qset = User.objects.all()
|
||||
|
||||
# make sure it is the smae user
|
||||
# make sure it is the same user
|
||||
self.assertEqual(qset.count(), 1)
|
||||
|
||||
|
||||
class TestAutoAuthDisabled(UrlResetMixin, TestCase):
|
||||
class AutoAuthDisabledTestCase(UrlResetMixin):
|
||||
"""
|
||||
Test that the page is inaccessible with default settings
|
||||
"""
|
||||
@@ -89,14 +80,13 @@ class TestAutoAuthDisabled(UrlResetMixin, TestCase):
|
||||
# value affects the contents of urls.py,
|
||||
# so we need to call super.setUp() which reloads urls.py (because
|
||||
# of the UrlResetMixin)
|
||||
super(TestAutoAuthDisabled, self).setUp()
|
||||
super(AutoAuthDisabledTestCase, self).setUp()
|
||||
self.url = '/auto_auth'
|
||||
self.client = Client()
|
||||
|
||||
def test_404(self):
|
||||
def test_auto_auth_disabled(self):
|
||||
"""
|
||||
make sure automatic authentication is invisible
|
||||
Make sure automatic authentication is disabled.
|
||||
"""
|
||||
|
||||
url = '/auto_auth'
|
||||
response = self.client.get(url)
|
||||
|
||||
response = self.client.get(self.url)
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
Reference in New Issue
Block a user