fix some codacy errors
This commit is contained in:
parent
3063cf116b
commit
570676f5b0
6 changed files with 28 additions and 11 deletions
|
@ -1,6 +1,6 @@
|
|||
function alert_version(last_version){
|
||||
jQuery(function( $ ){
|
||||
$('#alert-version').click(function( e ){
|
||||
$("#alert-version").click(function( e ){
|
||||
e.preventDefault();
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime()+(10*365*24*60*60*1000));
|
||||
|
@ -8,18 +8,20 @@ function alert_version(last_version){
|
|||
document.cookie = "cas-alert-version=" + last_version + expires + "; path=/";
|
||||
});
|
||||
|
||||
var nameEQ="cas-alert-version="
|
||||
var ca = document.cookie.split(';');
|
||||
var nameEQ="cas-alert-version=";
|
||||
var ca = document.cookie.split(";");
|
||||
var value;
|
||||
for(var i=0;i < ca.length;i++) {
|
||||
var c = ca[i];
|
||||
while (c.charAt(0)==' ')
|
||||
while(c.charAt(0) === " "){
|
||||
c = c.substring(1,c.length);
|
||||
if (c.indexOf(nameEQ) == 0)
|
||||
}
|
||||
if(c.indexOf(nameEQ) === 0){
|
||||
value = c.substring(nameEQ.length,c.length);
|
||||
}
|
||||
}
|
||||
if(value === last_version){
|
||||
$('#alert-version').parent().hide();
|
||||
$("#alert-version").parent().hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -284,6 +284,7 @@ class NewVersionWarningTestCase(TestCase):
|
|||
|
||||
@mock.patch("cas_server.models.VERSION", "0.1.2")
|
||||
def test_send_mails(self):
|
||||
"""test the send_mails method with ADMINS and a new version available"""
|
||||
models.NewVersionWarning.send_mails()
|
||||
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
|
@ -297,16 +298,19 @@ class NewVersionWarningTestCase(TestCase):
|
|||
|
||||
@mock.patch("cas_server.models.VERSION", "1.2.3")
|
||||
def test_send_mails_same_version(self):
|
||||
"""test the send_mails method with with current version being the last"""
|
||||
models.NewVersionWarning.objects.create(version="0.1.2")
|
||||
models.NewVersionWarning.send_mails()
|
||||
self.assertEqual(len(mail.outbox), 0)
|
||||
|
||||
@override_settings(ADMINS=[])
|
||||
def test_send_mails_no_admins(self):
|
||||
"""test the send_mails method without ADMINS"""
|
||||
models.NewVersionWarning.send_mails()
|
||||
self.assertEqual(len(mail.outbox), 0)
|
||||
|
||||
@override_settings(CAS_NEW_VERSION_EMAIL_WARNING=False)
|
||||
def test_send_mails_disabled(self):
|
||||
"""test the send_mails method if disabled"""
|
||||
models.NewVersionWarning.send_mails()
|
||||
self.assertEqual(len(mail.outbox), 0)
|
||||
|
|
|
@ -136,9 +136,12 @@ class CheckPasswordCase(TestCase):
|
|||
"""test all the hex_HASH method: the hashed password is a simple hash of the password"""
|
||||
hashes = ["md5", "sha1", "sha224", "sha256", "sha384", "sha512"]
|
||||
hashed_password1 = []
|
||||
for hash in hashes:
|
||||
for hash_scheme in hashes:
|
||||
hashed_password1.append(
|
||||
("hex_%s" % hash, getattr(utils.hashlib, hash)(self.password1).hexdigest())
|
||||
(
|
||||
"hex_%s" % hash_scheme,
|
||||
getattr(utils.hashlib, hash_scheme)(self.password1).hexdigest()
|
||||
)
|
||||
)
|
||||
for (method, hp1) in hashed_password1:
|
||||
self.assertTrue(utils.check_password(method, self.password1, hp1, "utf8"))
|
||||
|
|
|
@ -52,6 +52,7 @@ class LoginTestCase(TestCase, BaseServicePattern, CanLogin):
|
|||
@mock.patch("cas_server.utils.last_version", lambda: "1.2.3")
|
||||
@mock.patch("cas_server.utils.VERSION", "0.1.2")
|
||||
def test_new_version_available_ok(self):
|
||||
"""test the new version info box"""
|
||||
client = Client()
|
||||
response = client.get("/login")
|
||||
self.assertIn(b"A new version of the application is available", response.content)
|
||||
|
@ -60,12 +61,16 @@ class LoginTestCase(TestCase, BaseServicePattern, CanLogin):
|
|||
@mock.patch("cas_server.utils.last_version", lambda: None)
|
||||
@mock.patch("cas_server.utils.VERSION", "0.1.2")
|
||||
def test_new_version_available_badpypi(self):
|
||||
"""
|
||||
test the new version info box if pypi is not available (unable to retreive last version)
|
||||
"""
|
||||
client = Client()
|
||||
response = client.get("/login")
|
||||
self.assertNotIn(b"A new version of the application is available", response.content)
|
||||
|
||||
@override_settings(CAS_NEW_VERSION_HTML_WARNING=False)
|
||||
def test_new_version_available_disabled(self):
|
||||
"""test the new version info box is disabled"""
|
||||
client = Client()
|
||||
response = client.get("/login")
|
||||
self.assertNotIn(b"A new version of the application is available", response.content)
|
||||
|
|
|
@ -33,6 +33,11 @@ if django.VERSION < (1, 8):
|
|||
from django.template import Context
|
||||
else:
|
||||
def Context(arg):
|
||||
"""
|
||||
Starting from django 1.8 render take a dict and deprecated the use of a Context.
|
||||
So this is the identity function, only use for compatibility with django 1.7 where
|
||||
render MUST take a Context as argument.
|
||||
"""
|
||||
return arg
|
||||
|
||||
|
||||
|
|
|
@ -64,9 +64,7 @@ def context(params):
|
|||
params["VERSION"] = VERSION
|
||||
params["LAST_VERSION"] = LAST_VERSION
|
||||
if LAST_VERSION is not None:
|
||||
t_version = decode_version(VERSION)
|
||||
t_last_version = decode_version(LAST_VERSION)
|
||||
params["upgrade_available"] = t_version < t_last_version
|
||||
params["upgrade_available"] = decode_version(VERSION) < decode_version(LAST_VERSION)
|
||||
else:
|
||||
params["upgrade_available"] = False
|
||||
return params
|
||||
|
|
Loading…
Reference in a new issue