Skip to content

Commit

Permalink
Merge pull request #20 from andela/ch-customize-admin-site-160887220
Browse files Browse the repository at this point in the history
#160887220 customize authors haven admin site
  • Loading branch information
Walukagga Patrick committed Oct 8, 2018
2 parents 896455f + e0fd1d8 commit 854d87d
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
__pycache__/
*.py[cod]
*$py.class

.DS_Store
# C extensions
*.so

# Distribution / packaging
migrations/
.Python
Expand Down Expand Up @@ -95,3 +94,4 @@ ENV/

# SQLite3
db.sqlite3
migrations
4 changes: 2 additions & 2 deletions authors/apps/authentication/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.contrib import admin
from authors.apps.default_admin import *
from authors.apps.authentication.models import User

class UserAdmin(admin.ModelAdmin):
fields = ('username', 'email','is_active','is_verified','is_staff')
list_display = ('username', 'email','is_active','is_verified','is_staff')

admin.site.register(User,UserAdmin)
admin.site.register(User,UserAdmin)
7 changes: 4 additions & 3 deletions authors/apps/authentication/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class RegistrationSerializer(serializers.ModelSerializer):
# characters, and can not be read by the client.
password = serializers.CharField(
max_length=128,
min_length=8,
write_only=True
)

Expand Down Expand Up @@ -45,9 +44,11 @@ def validate(self, data):
)

# Raise an exception if the password is not alphanumeric
if not re.match("(.*[a-zA-Z])(.*[0-9])", password):
if not re.match("(?=.*[a-z])(?=.*[A-Z])"
"(?=.*[0-9])(?=.*[^a-zA-Z0-9])", password) or len(password)<8:
raise serializers.ValidationError(
{"password": "The password should have have a number and a letter"}
{"password": "The password should have atleast 8 characters a"
"lowwercase,uppercase,number and a special character"}
)

return {
Expand Down
1 change: 0 additions & 1 deletion authors/apps/authentication/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ def build_profile_on_user_creation(sender, instance, created, **kwargs):
profile = Profile(user=instance)
profile.save()


3 changes: 3 additions & 0 deletions authors/apps/default_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

admin.site.site_header = 'Authors Haven Administration Site'
1 change: 0 additions & 1 deletion authors/apps/profiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def update(self, request, *args, **kwargs):

username=self.kwargs["username"]
if username == request.user.username:

user_data = request.data.get('profile', {})

serializer_data = {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_authentication/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class BaseTest:
def __init__(self):
self.username = "simon"
self.email = "simon@andela.com"
self.password = "simon123"
self.password = "Simon123@"
self.bio = "I am left handed"
self.image_url = "https://i.stack.imgur.com/xHWG8.jpg"
self.reg_data = {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_authentication/test_password_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PasswordRestTestCase(APITestCase, BaseTest):
def setUp(self):
BaseTest.__init__(self)
self.client = APIClient()
self.email = 'kimbsimon2@gmail.com'
self.email = 'kimbsimon@gmail.com'
# Create a user
self.user = User.objects.create_user(
self.username, self.email, self.password)
Expand Down
9 changes: 1 addition & 8 deletions tests/test_authentication/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_invalid_password(self):
response = self.client.post(
'/api/users/', self.reg_data, format="json")
self.assertEqual(response.status_code, 400)
self.assertIn("8 characters", str(response.data))
self.assertIn("lowwercase,uppercase,number and a special character", str(response.data))

def test_missing_email_field(self):
del self.reg_data['user']['email']
Expand All @@ -57,13 +57,6 @@ def test_register_super_user_without_password(self):
with self.assertRaises(TypeError):
self.user = User.objects.create_superuser(None, None, None)

def test_password_not_alphanumeric(self):
self.reg_data['user']['password'] = "23456890"
response = self.client.post(
'/api/users/', self.reg_data, format="json")
self.assertEqual(response.status_code, 400)
self.assertIn("a number and a letter", str(response.data))

def test_invalid_username(self):
self.reg_data['user']['username'] = "234568#"
response = self.client.post(
Expand Down
22 changes: 9 additions & 13 deletions tests/test_profiles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ def setUp(self):
self.user_data = {"user": {
"username": "admin",
"email": "admin@gmail.com",
"password": "admin12345"}
"password": "Admin12345@"

}

}

self.profile_data = {"profile": {
Expand Down Expand Up @@ -38,19 +41,12 @@ def setUp(self):
"first_name": "spiderman",
"email": "xyz@gmail.com",
"bio": "",
}
}
}

self.sign_up = self.client.post(
"/api/users/", self.user_data, format="json")








self.sign_up = self.client.post("/api/users/", self.user_data, format="json")

self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.sign_up.data["token"])

self.client.credentials(
HTTP_AUTHORIZATION='Token ' + self.sign_up.data["token"])

0 comments on commit 854d87d

Please sign in to comment.