tests: add test around delegation, first with the *_by_document improvement for multiple delegates

refs #3886
This commit is contained in:
Benjamin Dauvergne 2013-10-29 11:44:09 +01:00
parent 33539b7e4e
commit 96d482f48c
1 changed files with 23 additions and 0 deletions

View File

@ -155,3 +155,26 @@ class UtilsTestCase(BaseTestCase):
def test_is_guest(self):
from . import models
self.assertTrue(models.is_guest(self.user2))
class DelegatesTestCase(BaseTestCase):
def setUp(self):
super(DelegatesTestCase, self).setUp()
from django.contrib.auth.models import User
from .models import (DocbowProfile, all_emails, Document, FileType, Delegation)
delegate = User(username='delegate')
delegate.set_password('delegate')
delegate.save()
Delegation.objects.create(by=self.users[0], to=delegate)
Delegation.objects.create(by=self.users[1], to=delegate)
def test_inbox_by_document(self):
from django.test import Client
c = Client()
c.login(username='delegate', password='delegate')
response = c.get('/inbox_by_document/%s/' % self.documents[0].id)
self.assertEqual(response.status_code, 302)
from .models import Mailbox
# Mailbox default ordering is -date so the last recipient mailbox
# is the first mailbox to be returned
mbox = Mailbox.objects.get(owner=self.users[1], document=self.documents[0])
self.assertTrue(response['Location'].endswith('/inbox/%s/' % mbox.id))