Fixing tests

remotes/origin/enhancement/email-actions
Alejandro Alonso 2014-10-28 18:03:33 +01:00
parent 6e313abfbd
commit 38fc63425a
1 changed files with 44 additions and 36 deletions

View File

@ -22,15 +22,17 @@ from unittest.mock import MagicMock, patch
from django.core.urlresolvers import reverse
from django.apps import apps
from .. import factories as f
from .. utils import set_settings
from taiga.projects.notifications import services
from taiga.projects.notifications import models
from taiga.projects.notifications.choices import NotifyLevel
from taiga.projects.history.choices import HistoryType
from taiga.projects.history.services import take_snapshot
from taiga.projects.issues.serializers import IssueSerializer
from taiga.projects.userstories.serializers import UserStorySerializer
from taiga.projects.tasks.serializers import TaskSerializer
pytestmark = pytest.mark.django_db
@ -118,7 +120,7 @@ def test_users_to_notify():
# Test basic description modifications
issue.description = "test1"
issue.save()
users = services.get_users_to_notify(issue, history=history)
users = services.get_users_to_notify(issue)
assert len(users) == 1
assert tuple(users)[0] == issue.get_owner()
@ -126,13 +128,13 @@ def test_users_to_notify():
policy1.notify_level = NotifyLevel.watch
policy1.save()
users = services.get_users_to_notify(issue, history=history)
users = services.get_users_to_notify(issue)
assert len(users) == 2
assert users == {member1.user, issue.get_owner()}
# Test with watchers
issue.watchers.add(member3.user)
users = services.get_users_to_notify(issue, history=history)
users = services.get_users_to_notify(issue)
assert len(users) == 3
assert users == {member1.user, member3.user, issue.get_owner()}
@ -141,90 +143,87 @@ def test_users_to_notify():
policy3.save()
issue.watchers.add(member3.user)
users = services.get_users_to_notify(issue, history=history)
users = services.get_users_to_notify(issue)
assert len(users) == 2
assert users == {member1.user, issue.get_owner()}
@set_settings(CHANGE_NOTIFICATIONS_MIN_INTERVAL=0)
def test_send_notifications_using_services_method(mail):
project = f.ProjectFactory.create()
member1 = f.MembershipFactory.create(project=project)
member2 = f.MembershipFactory.create(project=project)
history_change = MagicMock()
history_change.owner = member1.user
history_change.user = {"pk": member1.user.pk}
history_change.comment = ""
history_change.type = HistoryType.change
history_create = MagicMock()
history_create.owner = member1.user
history_create.user = {"pk": member1.user.pk}
history_create.comment = ""
history_create.type = HistoryType.create
history_delete = MagicMock()
history_delete.owner = member1.user
history_delete.user = {"pk": member1.user.pk}
history_delete.comment = ""
history_delete.type = HistoryType.delete
# Issues
issue = f.IssueFactory.create(project=project)
take_snapshot(issue)
services.send_notifications(issue,
history=history_create,
users={member1.user, member2.user})
history=history_create)
services.send_notifications(issue,
history=history_change,
users={member1.user, member2.user})
history=history_change)
services.send_notifications(issue,
history=history_delete,
users={member1.user, member2.user})
history=history_delete)
# Userstories
us = f.UserStoryFactory.create()
take_snapshot(us)
services.send_notifications(us,
history=history_create,
users={member1.user, member2.user})
history=history_create)
services.send_notifications(us,
history=history_change,
users={member1.user, member2.user})
history=history_change)
services.send_notifications(us,
history=history_delete,
users={member1.user, member2.user})
history=history_delete)
# Tasks
task = f.TaskFactory.create()
take_snapshot(task)
services.send_notifications(task,
history=history_create,
users={member1.user, member2.user})
history=history_create)
services.send_notifications(task,
history=history_change,
users={member1.user, member2.user})
history=history_change)
services.send_notifications(task,
history=history_delete,
users={member1.user, member2.user})
history=history_delete)
# Wiki pages
wiki = f.WikiPageFactory.create()
take_snapshot(wiki)
services.send_notifications(wiki,
history=history_create,
users={member1.user, member2.user})
history=history_create)
services.send_notifications(wiki,
history=history_change,
users={member1.user, member2.user})
history=history_change)
services.send_notifications(wiki,
history=history_delete,
users={member1.user, member2.user})
assert len(mail.outbox) == 24
history=history_delete)
assert models.HistoryChangeNotification.objects.count() == 12
assert len(mail.outbox) == 0
services.process_sync_notifications()
assert len(mail.outbox) == 12
@set_settings(CHANGE_NOTIFICATIONS_MIN_INTERVAL=0)
def test_resource_notification_test(client, mail):
user1 = f.UserFactory.create()
user2 = f.UserFactory.create()
@ -242,13 +241,22 @@ def test_resource_notification_test(client, mail):
with patch(mock_path) as m:
data = {"subject": "Fooooo", "version": issue.version}
response = client.patch(url, json.dumps(data), content_type="application/json")
assert len(mail.outbox) == 1
assert response.status_code == 200
assert len(mail.outbox) == 0
assert models.HistoryChangeNotification.objects.count() == 1
services.process_sync_notifications()
assert len(mail.outbox) == 1
assert models.HistoryChangeNotification.objects.count() == 0
with patch(mock_path) as m:
response = client.delete(url)
assert response.status_code == 204
assert len(mail.outbox) == 1
assert models.HistoryChangeNotification.objects.count() == 1
services.process_sync_notifications()
assert len(mail.outbox) == 2
assert models.HistoryChangeNotification.objects.count() == 0
def test_watchers_assignation_for_issue(client):