1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
# -*- coding: utf-8 -*-
#
# Copyright (C) 2006 Edgewall Software
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at http://trac.edgewall.com/license.html.
#
# This software consists of voluntary contributions made by many
# individuals. For the exact contribution history, see the revision
# history and logs, available at http://projects.edgewall.com/trac/.
from StringIO import StringIO
import unittest
from trac.test import EnvironmentStub, Mock
from tracspamfilter.filters.session import SessionFilterStrategy
class SessionFilterStrategyTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub(enable=[SessionFilterStrategy])
self.strategy = SessionFilterStrategy(self.env)
def test_new_session(self):
data = {}
session = Mock(last_visit=42, get=data.get)
retval = self.strategy.test(Mock(session=session), None, None)
self.assertEqual((3, 'Existing session found'), retval)
def test_session_name_set(self):
data = {'name': 'joe'}
session = Mock(last_visit=42, get=data.get)
retval = self.strategy.test(Mock(session=session), None, None)
self.assertEqual((6, 'Existing session found'), retval)
def test_session_email_set(self):
data = {'email': 'joe@example.org'}
session = Mock(last_visit=42, get=data.get)
retval = self.strategy.test(Mock(session=session), None, None)
self.assertEqual((6, 'Existing session found'), retval)
def test_session_email_set_but_invalid(self):
data = {'email': 'joey'}
session = Mock(last_visit=42, get=data.get)
retval = self.strategy.test(Mock(session=session), None, None)
self.assertEqual((3, 'Existing session found'), retval)
def test_session_name_and_email_set(self):
data = {'name': 'joe', 'email': 'joe@example.org'}
session = Mock(last_visit=42, get=data.get)
retval = self.strategy.test(Mock(session=session), None, None)
self.assertEqual((9, 'Existing session found'), retval)
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(SessionFilterStrategyTestCase, 'test'))
return suite
if __name__ == '__main__':
unittest.main(defaultTest='suite')
|