Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d6d50973
authored
Mar 10, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: fix and test search_profile
parent
d1d0ff36
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
+28
-2
circle/dashboard/tests/test_models.py
+25
-0
circle/dashboard/views.py
+3
-2
No files found.
circle/dashboard/tests/test_models.py
View file @
d6d50973
...
@@ -3,6 +3,7 @@ from django.contrib.auth.models import User
...
@@ -3,6 +3,7 @@ from django.contrib.auth.models import User
from
django.test
import
TestCase
from
django.test
import
TestCase
from
..models
import
Profile
from
..models
import
Profile
from
..views
import
search_user
class
NotificationTestCase
(
TestCase
):
class
NotificationTestCase
(
TestCase
):
...
@@ -25,3 +26,27 @@ class NotificationTestCase(TestCase):
...
@@ -25,3 +26,27 @@ class NotificationTestCase(TestCase):
assert
'user1'
in
msg
.
message
assert
'user1'
in
msg
.
message
assert
'testme'
in
msg
.
message
assert
'testme'
in
msg
.
message
assert
msg
in
self
.
u1
.
notification_set
.
all
()
assert
msg
in
self
.
u1
.
notification_set
.
all
()
class
ProfileTestCase
(
TestCase
):
def
setUp
(
self
):
self
.
u1
=
User
.
objects
.
create
(
username
=
'user1'
)
Profile
.
objects
.
get_or_create
(
user
=
self
.
u1
)
self
.
u2
=
User
.
objects
.
create
(
username
=
'user2'
,
email
=
'john@example.org'
)
Profile
.
objects
.
get_or_create
(
user
=
self
.
u2
,
org_id
=
'apple'
)
def
test_search_user_by_name
(
self
):
self
.
assertEqual
(
search_user
(
'user1'
),
self
.
u1
)
self
.
assertEqual
(
search_user
(
'user2'
),
self
.
u2
)
def
test_search_user_by_mail
(
self
):
self
.
assertEqual
(
search_user
(
'john@example.org'
),
self
.
u2
)
def
test_search_user_by_orgid
(
self
):
self
.
assertEqual
(
search_user
(
'apple'
),
self
.
u2
)
def
test_search_user_nonexist
(
self
):
with
self
.
assertRaises
(
User
.
DoesNotExist
):
search_user
(
'no-such-user'
)
circle/dashboard/views.py
View file @
d6d50973
...
@@ -50,9 +50,10 @@ def search_user(keyword):
...
@@ -50,9 +50,10 @@ def search_user(keyword):
try
:
try
:
return
User
.
objects
.
get
(
username
=
keyword
)
return
User
.
objects
.
get
(
username
=
keyword
)
except
User
.
DoesNotExist
:
except
User
.
DoesNotExist
:
return
User
.
objects
.
get
(
email
=
keyword
)
try
:
except
User
.
DoesNotExist
:
return
User
.
objects
.
get
(
profile__org_id
=
keyword
)
return
User
.
objects
.
get
(
profile__org_id
=
keyword
)
except
User
.
DoesNotExist
:
return
User
.
objects
.
get
(
email
=
keyword
)
# github.com/django/django/blob/stable/1.6.x/django/contrib/messages/views.py
# github.com/django/django/blob/stable/1.6.x/django/contrib/messages/views.py
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment