added landscape.io and some fixes it found

This commit is contained in:
Ken Cochrane 2015-01-03 11:09:30 -05:00
parent 7e32eacd97
commit a7bc8c0d55
7 changed files with 30 additions and 5 deletions

View file

@ -16,7 +16,7 @@ the goal is to do those things very well, and have full unit tests with docs.
Build status
------------
[![Build Status](https://travis-ci.org/kencochrane/django-defender.svg)](https://travis-ci.org/kencochrane/django-defender) [![Coverage Status](https://img.shields.io/coveralls/kencochrane/django-defender.svg)](https://coveralls.io/r/kencochrane/django-defender)
[![Build Status](https://travis-ci.org/kencochrane/django-defender.svg)](https://travis-ci.org/kencochrane/django-defender) [![Coverage Status](https://img.shields.io/coveralls/kencochrane/django-defender.svg)](https://coveralls.io/r/kencochrane/django-defender)[![Code Health](https://landscape.io/github/kencochrane/django-defender/master/landscape.svg)](https://landscape.io/github/kencochrane/django-defender/master)
Goals for 0.1
=============

7
defender/.landscape.yaml Normal file
View file

@ -0,0 +1,7 @@
doc-warnings: yes
test-warnings: no
strictness: veryhigh
max-line-length: 80
uses:
- django
autodetect: yes

View file

@ -30,3 +30,9 @@ class AccessAttempt(models.Model):
class Meta:
ordering = ['-attempt_time']
def __unicode__(self):
""" unicode value for this model """
return u"{0} @ {1} | {2}".format(self.username,
self.attempt_time,
self.login_valid)

View file

@ -1,3 +1,5 @@
import os
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
@ -28,7 +30,7 @@ INSTALLED_APPS = [
'defender',
]
SECRET_KEY = 'too-secret-for-test'
SECRET_KEY = os.environ.get('SECRET_KEY', 'too-secret-for-test')
LOGIN_REDIRECT_URL = '/admin'

View file

@ -17,6 +17,7 @@ from django.http import HttpRequest
from .connection import parse_redis_url
from . import utils
from . import config
from models import AccessAttempt
mocked_redis = mockredis.mock_strict_redis_client()
@ -287,6 +288,14 @@ class AccessAttemptTest(TestCase):
response = self.client.get(ADMIN_LOGIN_URL)
self.assertContains(response, self.PERMANENT_LOCKED_MESSAGE)
def test_login_attempt_model(self):
""" test the login model"""
response = self._login()
self.assertContains(response, LOGIN_FORM_KEY)
self.assertEquals(AccessAttempt.objects.count(), 1)
self.assertIsNotNone(AccessAttempt.objects.all()[0])
def test_is_valid_ip(self):
""" Test the is_valid_ip() method
"""

View file

@ -1,3 +1,4 @@
import os
DATABASES = {
'default': {
@ -29,7 +30,7 @@ INSTALLED_APPS = [
'defender',
]
SECRET_KEY = 'too-secret-for-test'
SECRET_KEY = os.environ.get('SECRET_KEY', 'too-secret-for-test')
LOGIN_REDIRECT_URL = '/admin'

View file

@ -20,7 +20,7 @@ def is_valid_ip(ip_address):
valid = True
try:
socket.inet_aton(ip_address.strip())
except:
except (socket.error, AttributeError):
valid = False
return valid
@ -61,7 +61,7 @@ def get_ip_address_from_request(request):
remote_addr):
ip_address = remote_addr.strip()
if not ip_address:
ip_address = '127.0.0.1'
ip_address = '127.0.0.1'
return ip_address