Example #1
0
class TestAuthentication(TestCase):
    def setUp(self):
        self.message = message_from_string(MAIL)
        self.user = User.objects.create_user('Bob', '*****@*****.**', '123')
        self.client = Client()

    def test_anonymous(self):
        request = EmailRequest(message=self.message)
        try:
            response = self.client.request(request)
        except RecipientNotFound:
            pass
        user = response.context['user']
        self.assertEquals(True, user.is_anonymous())
        
    def test_registered(self):
        self.message.replace_header('From', '*****@*****.**')
        request = EmailRequest(message=self.message)
        response = self.client.request(request)
        user = response.context['user']
        self.assertEquals(False, user.is_anonymous())
        self.assertEquals(user, self.user)

    def test_loginrequired_anonymous(self):
        self.message.replace_header('Envelope-To', '*****@*****.**')
        request = EmailRequest(message=self.message)
        response = self.client.request(request)
        self.assertEquals('Access Denied to Recipient', response.subject)

    def test_loginrequired_registered(self):
        self.message.replace_header('From', '*****@*****.**')
        self.message.replace_header('Envelope-To', '*****@*****.**')
        request = EmailRequest(message=self.message)
        response = self.client.request(request)
        self.assertEquals('Echo Echo', response.subject)
Example #2
0
 def test_req_middleware(self):
     current_middleware = get_setting('MAIL_MIDDLEWARE')
     settings.MAIL_MIDDLEWARE = current_middleware + ('testapp.tests.TestMiddleware', )
     request = EmailRequest(message=self.message)
     client = Client()
     response = client.request(request)
     self.assertEquals(True, request.middlewares['request'])
     self.assertEquals(True, request.middlewares['view'])
     self.assertEquals(True, request.middlewares['response'])
     settings.MAIL_MIDDLEWARE = current_middleware
Example #3
0
class TestResolver(TestCase):
    def setUp(self):
        self.message = message_from_string(MAIL)
        self.client = Client()

    def test_404(self):
        self.message.replace_header('Envelope-To', '*****@*****.**')
        em = EmailRequest(message=self.message)
        response = self.client.request(em)
        self.assertEquals('recipient_notfound.txt', response.template.name)

    def test_ok(self):
        em = EmailRequest(message=self.message)
        response = self.client.request(em)
        self.assertEquals(
            response.context['request'].get_recipient_address(),
            '*****@*****.**')
        self.assertEquals(response.subject, 'Echo Echo')
Example #4
0
 def setUp(self):
     self.message = message_from_string(MAIL)
     self.client = Client()
Example #5
0
 def setUp(self):
     self.message = message_from_string(MAIL)
     self.user = User.objects.create_user('Bob', '*****@*****.**', '123')
     self.client = Client()