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){
|
function alert_version(last_version){
|
||||||
jQuery(function( $ ){
|
jQuery(function( $ ){
|
||||||
$('#alert-version').click(function( e ){
|
$("#alert-version").click(function( e ){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
date.setTime(date.getTime()+(10*365*24*60*60*1000));
|
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=/";
|
document.cookie = "cas-alert-version=" + last_version + expires + "; path=/";
|
||||||
});
|
});
|
||||||
|
|
||||||
var nameEQ="cas-alert-version="
|
var nameEQ="cas-alert-version=";
|
||||||
var ca = document.cookie.split(';');
|
var ca = document.cookie.split(";");
|
||||||
var value;
|
var value;
|
||||||
for(var i=0;i < ca.length;i++) {
|
for(var i=0;i < ca.length;i++) {
|
||||||
var c = ca[i];
|
var c = ca[i];
|
||||||
while (c.charAt(0)==' ')
|
while(c.charAt(0) === " "){
|
||||||
c = c.substring(1,c.length);
|
c = c.substring(1,c.length);
|
||||||
if (c.indexOf(nameEQ) == 0)
|
}
|
||||||
|
if(c.indexOf(nameEQ) === 0){
|
||||||
value = c.substring(nameEQ.length,c.length);
|
value = c.substring(nameEQ.length,c.length);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(value === last_version){
|
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")
|
@mock.patch("cas_server.models.VERSION", "0.1.2")
|
||||||
def test_send_mails(self):
|
def test_send_mails(self):
|
||||||
|
"""test the send_mails method with ADMINS and a new version available"""
|
||||||
models.NewVersionWarning.send_mails()
|
models.NewVersionWarning.send_mails()
|
||||||
|
|
||||||
self.assertEqual(len(mail.outbox), 1)
|
self.assertEqual(len(mail.outbox), 1)
|
||||||
|
@ -297,16 +298,19 @@ class NewVersionWarningTestCase(TestCase):
|
||||||
|
|
||||||
@mock.patch("cas_server.models.VERSION", "1.2.3")
|
@mock.patch("cas_server.models.VERSION", "1.2.3")
|
||||||
def test_send_mails_same_version(self):
|
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.objects.create(version="0.1.2")
|
||||||
models.NewVersionWarning.send_mails()
|
models.NewVersionWarning.send_mails()
|
||||||
self.assertEqual(len(mail.outbox), 0)
|
self.assertEqual(len(mail.outbox), 0)
|
||||||
|
|
||||||
@override_settings(ADMINS=[])
|
@override_settings(ADMINS=[])
|
||||||
def test_send_mails_no_admins(self):
|
def test_send_mails_no_admins(self):
|
||||||
|
"""test the send_mails method without ADMINS"""
|
||||||
models.NewVersionWarning.send_mails()
|
models.NewVersionWarning.send_mails()
|
||||||
self.assertEqual(len(mail.outbox), 0)
|
self.assertEqual(len(mail.outbox), 0)
|
||||||
|
|
||||||
@override_settings(CAS_NEW_VERSION_EMAIL_WARNING=False)
|
@override_settings(CAS_NEW_VERSION_EMAIL_WARNING=False)
|
||||||
def test_send_mails_disabled(self):
|
def test_send_mails_disabled(self):
|
||||||
|
"""test the send_mails method if disabled"""
|
||||||
models.NewVersionWarning.send_mails()
|
models.NewVersionWarning.send_mails()
|
||||||
self.assertEqual(len(mail.outbox), 0)
|
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"""
|
"""test all the hex_HASH method: the hashed password is a simple hash of the password"""
|
||||||
hashes = ["md5", "sha1", "sha224", "sha256", "sha384", "sha512"]
|
hashes = ["md5", "sha1", "sha224", "sha256", "sha384", "sha512"]
|
||||||
hashed_password1 = []
|
hashed_password1 = []
|
||||||
for hash in hashes:
|
for hash_scheme in hashes:
|
||||||
hashed_password1.append(
|
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:
|
for (method, hp1) in hashed_password1:
|
||||||
self.assertTrue(utils.check_password(method, self.password1, hp1, "utf8"))
|
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.last_version", lambda: "1.2.3")
|
||||||
@mock.patch("cas_server.utils.VERSION", "0.1.2")
|
@mock.patch("cas_server.utils.VERSION", "0.1.2")
|
||||||
def test_new_version_available_ok(self):
|
def test_new_version_available_ok(self):
|
||||||
|
"""test the new version info box"""
|
||||||
client = Client()
|
client = Client()
|
||||||
response = client.get("/login")
|
response = client.get("/login")
|
||||||
self.assertIn(b"A new version of the application is available", response.content)
|
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.last_version", lambda: None)
|
||||||
@mock.patch("cas_server.utils.VERSION", "0.1.2")
|
@mock.patch("cas_server.utils.VERSION", "0.1.2")
|
||||||
def test_new_version_available_badpypi(self):
|
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()
|
client = Client()
|
||||||
response = client.get("/login")
|
response = client.get("/login")
|
||||||
self.assertNotIn(b"A new version of the application is available", response.content)
|
self.assertNotIn(b"A new version of the application is available", response.content)
|
||||||
|
|
||||||
@override_settings(CAS_NEW_VERSION_HTML_WARNING=False)
|
@override_settings(CAS_NEW_VERSION_HTML_WARNING=False)
|
||||||
def test_new_version_available_disabled(self):
|
def test_new_version_available_disabled(self):
|
||||||
|
"""test the new version info box is disabled"""
|
||||||
client = Client()
|
client = Client()
|
||||||
response = client.get("/login")
|
response = client.get("/login")
|
||||||
self.assertNotIn(b"A new version of the application is available", response.content)
|
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
|
from django.template import Context
|
||||||
else:
|
else:
|
||||||
def Context(arg):
|
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
|
return arg
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -64,9 +64,7 @@ def context(params):
|
||||||
params["VERSION"] = VERSION
|
params["VERSION"] = VERSION
|
||||||
params["LAST_VERSION"] = LAST_VERSION
|
params["LAST_VERSION"] = LAST_VERSION
|
||||||
if LAST_VERSION is not None:
|
if LAST_VERSION is not None:
|
||||||
t_version = decode_version(VERSION)
|
params["upgrade_available"] = decode_version(VERSION) < decode_version(LAST_VERSION)
|
||||||
t_last_version = decode_version(LAST_VERSION)
|
|
||||||
params["upgrade_available"] = t_version < t_last_version
|
|
||||||
else:
|
else:
|
||||||
params["upgrade_available"] = False
|
params["upgrade_available"] = False
|
||||||
return params
|
return params
|
||||||
|
|
Loading…
Reference in a new issue