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
5195f8b3
authored
Jun 09, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: more tests
parent
89325b9c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
12 deletions
+38
-12
circle/dashboard/tests/test_periodic_task.py
+38
-12
No files found.
circle/dashboard/tests/test_periodic_task.py
View file @
5195f8b3
import
unittest
import
unittest
from
mock
import
patch
,
MagicMock
from
mock
import
patch
,
MagicMock
from
django.contrib.auth.models
import
User
from
..models
import
Notification
from
..models
import
Notification
from
..tasks
import
local_periodic_tasks
from
..tasks
import
local_periodic_tasks
...
@@ -9,22 +10,47 @@ from ..tasks import local_periodic_tasks
...
@@ -9,22 +10,47 @@ from ..tasks import local_periodic_tasks
@patch.object
(
local_periodic_tasks
,
'send_mail'
)
@patch.object
(
local_periodic_tasks
,
'send_mail'
)
@patch.object
(
Notification
,
'objects'
)
@patch.object
(
Notification
,
'objects'
)
class
EmailNotificationTestCase
(
unittest
.
TestCase
):
class
EmailNotificationTestCase
(
unittest
.
TestCase
):
def
get_fake_notification
(
self
,
user
=
None
,
**
kwargs
):
if
user
is
None
:
user
=
MagicMock
(
spec
=
User
)
user
.
profile
.
__unicode__
.
return_value
=
"user"
user
.
email
=
"mail"
user
.
profile
.
email_notifications
=
True
user
.
profile
.
preferred_language
=
"en"
params
=
{
"to"
:
user
,
"subject"
:
"subj"
,
"message"
:
"msg"
,
"status"
:
Notification
.
STATUS
.
new
}
params
.
update
(
kwargs
)
return
MagicMock
(
spec
=
Notification
,
**
params
)
def
test_not_sending
(
self
,
no
,
sm
):
def
test_not_sending
(
self
,
no
,
sm
):
fake
=
MagicMock
(
spec
=
Notification
)
fake
=
[
self
.
get_fake_notification
()]
fake
.
to
.
profile
.
email_notifications
=
False
fake
[
0
]
.
to
.
profile
.
email_notifications
=
False
no
.
filter
.
return_value
=
[
fake
]
no
.
filter
.
return_value
=
fake
local_periodic_tasks
.
send_email_notifications
()
local_periodic_tasks
.
send_email_notifications
()
assert
not
sm
.
called
assert
not
sm
.
called
def
test_sending
(
self
,
no
,
sm
):
def
test_sending
(
self
,
no
,
sm
):
fake
=
MagicMock
(
spec
=
Notification
)
fake
=
[
self
.
get_fake_notification
()]
fake
.
to
.
profile
.
__unicode__
.
return_value
=
"user"
no
.
filter
.
return_value
=
fake
fake
.
to
.
email
=
"mail"
fake
.
to
.
profile
.
email_notifications
=
True
fake
.
to
.
profile
.
preferred_language
=
"en"
fake
.
subject
=
"subj"
fake
.
message
=
"msg"
no
.
filter
.
return_value
=
[
fake
]
local_periodic_tasks
.
send_email_notifications
()
local_periodic_tasks
.
send_email_notifications
()
assert
sm
.
called
assert
sm
.
called
assert
fake
.
status
==
fake
.
STATUS
.
delivered
assert
all
(
i
.
status
==
i
.
STATUS
.
delivered
for
i
in
fake
)
def
test_sending_more
(
self
,
no
,
sm
):
fake
=
[
self
.
get_fake_notification
(),
self
.
get_fake_notification
()]
fake
.
append
(
self
.
get_fake_notification
(
fake
[
0
]
.
to
))
no
.
filter
.
return_value
=
fake
local_periodic_tasks
.
send_email_notifications
()
self
.
assertEquals
(
sm
.
call_count
,
2
)
assert
all
(
i
.
status
==
i
.
STATUS
.
delivered
for
i
in
fake
)
def
test_sending_some
(
self
,
no
,
sm
):
fake
=
[
self
.
get_fake_notification
(),
self
.
get_fake_notification
()]
fake
.
append
(
self
.
get_fake_notification
(
fake
[
0
]
.
to
))
fake
[
1
]
.
to
.
profile
.
email_notifications
=
False
no
.
filter
.
return_value
=
fake
local_periodic_tasks
.
send_email_notifications
()
self
.
assertEquals
(
[
i
.
status
==
i
.
STATUS
.
delivered
for
i
in
fake
],
[
True
,
False
,
True
])
self
.
assertEquals
(
sm
.
call_count
,
1
)
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