-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from Cadasta/feature/org-roles-ui
Organization UI
- Loading branch information
Showing
51 changed files
with
1,201 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django.db.models import Q | ||
from django.contrib.auth.models import UserManager as DjangoUserManager | ||
from django.utils.translation import ugettext as _ | ||
|
||
|
||
class UserManager(DjangoUserManager): | ||
def get_from_username_or_email(self, identifier=None): | ||
users = self.filter(Q(username=identifier) | Q(email=identifier)) | ||
users_count = len(users) | ||
|
||
if users_count == 1: | ||
return users[0] | ||
|
||
if users_count == 0: | ||
error = _( | ||
"User with username or email {} does not exist" | ||
).format(identifier) | ||
raise self.model.DoesNotExist(error) | ||
elif users_count > 1: | ||
error = _( | ||
"More than one user found for username or email {}" | ||
).format(identifier) | ||
raise self.model.MultipleObjectsReturned(error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9.2 on 2016-03-30 17:30 | ||
from __future__ import unicode_literals | ||
|
||
import accounts.manager | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('accounts', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelManagers( | ||
name='user', | ||
managers=[ | ||
('objects', accounts.manager.UserManager()), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% include "accounts/snippets/registration_form.html" %} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django.test import TestCase | ||
|
||
from pytest import raises | ||
|
||
from ..models import User | ||
from .factories import UserFactory | ||
|
||
|
||
class UserManagerTest(TestCase): | ||
def test_get_from_usernamel(self): | ||
user = UserFactory.create() | ||
found = User.objects.get_from_username_or_email(identifier=user.username) | ||
|
||
assert found == user | ||
|
||
def test_get_from_email(self): | ||
user = UserFactory.create() | ||
found = User.objects.get_from_username_or_email(identifier=user.email) | ||
|
||
assert found == user | ||
|
||
def test_user_not_found(self): | ||
with raises(User.DoesNotExist): | ||
User.objects.get_from_username_or_email(identifier='username') | ||
|
||
def test_mulitple_users_found(self): | ||
UserFactory.create(username='[email protected]') | ||
UserFactory.create(email='[email protected]') | ||
|
||
with raises(User.MultipleObjectsReturned): | ||
User.objects.get_from_username_or_email(identifier='[email protected]') |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% extends "core/base.html" %} | ||
|
||
{% block title %}Dashboard{% endblock %} | ||
|
||
{% block content %} | ||
|
||
<h1>Dashboard</h1> | ||
|
||
<ul> | ||
<li><a href="{% url 'organization:list' %}">Organization index</a></li> | ||
<li><a href="{% url 'project:list' %}">Project index</a></li> | ||
<li><a href="{% url 'user:list' %}">User index</a></li> | ||
</ul> | ||
|
||
{% endblock %} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
from django.test import TestCase | ||
from django.core.urlresolvers import reverse, resolve | ||
|
||
from .. import views | ||
from ..views import default | ||
|
||
|
||
class CoreUrlTest(TestCase): | ||
def test_index_page(self): | ||
assert reverse('core:index') == '/' | ||
|
||
resolved = resolve('/') | ||
assert resolved.func.__name__ == views.IndexPage.__name__ | ||
assert resolved.func.__name__ == default.IndexPage.__name__ | ||
|
||
def test_dashboard(self): | ||
assert reverse('core:dashboard') == '/dashboard/' | ||
|
||
resolved = resolve('/dashboard/') | ||
assert resolved.func.__name__ == views.Dashboard.__name__ | ||
assert resolved.func.__name__ == default.Dashboard.__name__ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from django.test import TestCase | ||
from django.http import Http404 | ||
|
||
from rest_framework.exceptions import NotFound | ||
|
||
from ..views.api import set_exception, eval_json | ||
|
||
|
||
class ExceptionHandleTest(TestCase): | ||
def test_set_exception_with_404(self): | ||
exception = Http404("No Organization matches the given query.") | ||
|
||
e = set_exception(exception) | ||
assert type(e) == NotFound | ||
assert str(e) == "Organization not found." | ||
|
||
def test_set_exception_with_404_and_different_error(self): | ||
exception = Http404("Error Message") | ||
|
||
e = set_exception(exception) | ||
assert type(e) == Http404 | ||
assert str(e) == "Error Message" | ||
|
||
def test_set_exception_with_NotFound(self): | ||
exception = NotFound("Error Message") | ||
|
||
e = set_exception(exception) | ||
assert type(e) == NotFound | ||
assert str(e) == "Error Message" | ||
|
||
def test_evaluate_json(self): | ||
response_data = { | ||
'contacts': [ | ||
'{"name": "This field is required.", "url": "\'blah\' is not a \'uri\'"}', | ||
'{"name": "This field is required."}', | ||
], | ||
'field': "Something went wrong" | ||
} | ||
|
||
actual = eval_json(response_data) | ||
|
||
expected = { | ||
'contacts': [ | ||
{'name': "This field is required.", 'url': "\'blah\' is not a \'uri\'"}, | ||
{'name': "This field is required."}, | ||
], | ||
'field': "Something went wrong" | ||
} | ||
|
||
assert actual == expected |
Oops, something went wrong.