Show
Ignore:
Timestamp:
11/07/07 09:23:09 (1 year ago)
Author:
alberto
Message:

Applied reindent.py an all .py files to switch from tabs to 4 spaces. Closes #66

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/tests/basic_tests.py

    r47 r67  
    66# This code is placed under the MIT license: 
    77# 
    8 # Permission is hereby granted, free of charge, to any person obtaining a copy  
    9 # of this software and associated documentation files (the "Software"), to deal  
    10 # in the Software without restriction, including without limitation the rights  
    11 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
    12 # copies of the Software, and to permit persons to whom the Software is  
     8# Permission is hereby granted, free of charge, to any person obtaining a copy 
     9# of this software and associated documentation files (the "Software"), to deal 
     10# in the Software without restriction, including without limitation the rights 
     11# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
     12# copies of the Software, and to permit persons to whom the Software is 
    1313# furnished to do so, subject to the following conditions: 
    1414# 
    15 # The above copyright notice and this permission notice shall be included in  
     15# The above copyright notice and this permission notice shall be included in 
    1616# all copies or substantial portions of the Software. 
    1717# 
    18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
    19 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
    20 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  
    21 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
    22 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  
    23 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  
     18# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
     19# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
     20# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
     21# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
     22# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
     23# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
    2424# SOFTWARE. 
    2525 
     
    3838 
    3939class TestBasicTests(unittest.TestCase): 
    40         "Basic test cases for TurboMail." 
     40    "Basic test cases for TurboMail." 
    4141 
    42         def setUp(self): 
    43                 server_port = 42042 
    44                  
    45                 test_config = {'mail.on': True, 'mail.timeout': 1, 
    46                                            'mail.server': 'localhost:%d' % server_port} 
    47                 self._original_config = save_config(test_config.keys()) 
    48                 turbogears.config.update(test_config) 
    49                  
    50                 self.sink = SMTPMailsink(host='localhost', port=server_port) 
    51                 self.sink.start() 
    52                  
    53                 turbomail.start_extension() 
     42    def setUp(self): 
     43        server_port = 42042 
     44 
     45        test_config = {'mail.on': True, 'mail.timeout': 1, 
     46                                   'mail.server': 'localhost:%d' % server_port} 
     47        self._original_config = save_config(test_config.keys()) 
     48        turbogears.config.update(test_config) 
     49 
     50        self.sink = SMTPMailsink(host='localhost', port=server_port) 
     51        self.sink.start() 
     52 
     53        turbomail.start_extension() 
    5454 
    5555 
    56         def tearDown(self): 
    57                 turbomail.shutdown_extension() 
    58                 turbogears.config.update(self._original_config) 
    59                 self.sink.stop() 
     56    def tearDown(self): 
     57        turbomail.shutdown_extension() 
     58        turbogears.config.update(self._original_config) 
     59        self.sink.stop() 
    6060 
    6161 
    62         def test_simple(self): 
    63                 "Test that sending a simple mail with turbomail.Message works." 
    64                 sender = 'sender@foo.example' 
    65                 recipient = 'recipient@foo.example' 
    66                 subject = 'foo bar' 
    67                 message = turbomail.Message(sender, recipient, subject) 
    68                 message.plain = 'Hello World!'             
    69                 turbomail.enqueue(message) 
     62    def test_simple(self): 
     63        "Test that sending a simple mail with turbomail.Message works." 
     64        sender = 'sender@foo.example' 
     65        recipient = 'recipient@foo.example' 
     66        subject = 'foo bar' 
     67        message = turbomail.Message(sender, recipient, subject) 
     68        message.plain = 'Hello World!' 
     69        turbomail.enqueue(message) 
    7070 
    71                 msginfo = get_received_mail(self.sink) 
    72                 self.assertEqual(sender, msginfo['from']) 
    73                 self.assertEqual([recipient], msginfo['recipients']) 
    74                 msg = email.message_from_string(msginfo['mail'])  
    75                 self.failIf(msg.has_key('Old-Return-Path')) 
    76                 self.failIf(msg.has_key('Return-Path')) 
    77                 assert 'Hello World' in msg.get_payload()  
     71        msginfo = get_received_mail(self.sink) 
     72        self.assertEqual(sender, msginfo['from']) 
     73        self.assertEqual([recipient], msginfo['recipients']) 
     74        msg = email.message_from_string(msginfo['mail']) 
     75        self.failIf(msg.has_key('Old-Return-Path')) 
     76        self.failIf(msg.has_key('Return-Path')) 
     77        assert 'Hello World' in msg.get_payload() 
    7878 
    79         def test_smtpfrom(self): 
    80                 "Test that smtpfrom is being honored and used as envelope sender." 
    81                 sender = 'sender@foo.example' 
    82                 recipient = 'recipient@foo.example' 
    83                 subject = 'foo bar' 
    84                 smtpfrom = 'devnull@foo.example' 
    85                 message = turbomail.Message(sender, recipient, subject,  
    86                                                                         smtpfrom=smtpfrom) 
    87                 message.plain = 'Hello World!'             
    88                 turbomail.enqueue(message) 
    89                 msginfo = get_received_mail(self.sink) 
    90                 self.assertEqual(smtpfrom, msginfo['from']) 
    91                 self.assertEqual([recipient], msginfo['recipients']) 
     79    def test_smtpfrom(self): 
     80        "Test that smtpfrom is being honored and used as envelope sender." 
     81        sender = 'sender@foo.example' 
     82        recipient = 'recipient@foo.example' 
     83        subject = 'foo bar' 
     84        smtpfrom = 'devnull@foo.example' 
     85        message = turbomail.Message(sender, recipient, subject, 
     86                                                                smtpfrom=smtpfrom) 
     87        message.plain = 'Hello World!' 
     88        turbomail.enqueue(message) 
     89        msginfo = get_received_mail(self.sink) 
     90        self.assertEqual(smtpfrom, msginfo['from']) 
     91        self.assertEqual([recipient], msginfo['recipients']) 
    9292 
    93         def test_add_custom_headers_dict(self): 
    94                 "Test that custom headers (dict type) can be attached." 
    95                 extra_headers = {'Precendence': 'bulk', 'X-User': 'Alice'} 
    96                 message = turbomail.Message('sender@foo.example',  
    97                                                                         'recipient@foo.example', 'foo bar') 
    98                 message.plain = 'Hello World!' 
    99                 message.headers = extra_headers 
    100                 turbomail.enqueue(message) 
    101                 msginfo = get_received_mail(self.sink) 
    102                 msg = email.message_from_string(msginfo['mail'])  
    103                 for header_name in extra_headers.keys(): 
    104                         self.failUnless(msg.has_key(header_name)) 
    105                         self.assertEquals(extra_headers[header_name], msg[header_name]) 
     93    def test_add_custom_headers_dict(self): 
     94        "Test that custom headers (dict type) can be attached." 
     95        extra_headers = {'Precendence': 'bulk', 'X-User': 'Alice'} 
     96        message = turbomail.Message('sender@foo.example', 
     97                                                                'recipient@foo.example', 'foo bar') 
     98        message.plain = 'Hello World!' 
     99        message.headers = extra_headers 
     100        turbomail.enqueue(message) 
     101        msginfo = get_received_mail(self.sink) 
     102        msg = email.message_from_string(msginfo['mail']) 
     103        for header_name in extra_headers.keys(): 
     104            self.failUnless(msg.has_key(header_name)) 
     105            self.assertEquals(extra_headers[header_name], msg[header_name]) 
    106106 
    107         def test_add_custom_headers_tuple(self): 
    108                 "Test that a custom header (tuple type) can be attached." 
    109                 extra_headers = (('Precendence', 'bulk'), ('X-User', 'Alice')) 
    110                 message = turbomail.Message('sender@foo.example',  
    111                                                                         'recipient@foo.example', 'foo bar') 
    112                 message.plain = 'Hello World!' 
    113                 message.headers = extra_headers 
    114                 turbomail.enqueue(message) 
    115                 msginfo = get_received_mail(self.sink) 
    116                 msg = email.message_from_string(msginfo['mail'])  
    117                 for name, value in extra_headers: 
    118                         self.failUnless(msg.has_key(name)) 
    119                         self.assertEquals(value, msg[name]) 
     107    def test_add_custom_headers_tuple(self): 
     108        "Test that a custom header (tuple type) can be attached." 
     109        extra_headers = (('Precendence', 'bulk'), ('X-User', 'Alice')) 
     110        message = turbomail.Message('sender@foo.example', 
     111                                                                'recipient@foo.example', 'foo bar') 
     112        message.plain = 'Hello World!' 
     113        message.headers = extra_headers 
     114        turbomail.enqueue(message) 
     115        msginfo = get_received_mail(self.sink) 
     116        msg = email.message_from_string(msginfo['mail']) 
     117        for name, value in extra_headers: 
     118            self.failUnless(msg.has_key(name)) 
     119            self.assertEquals(value, msg[name]) 
    120120 
    121         def test_add_custom_headers_list(self): 
    122                 "Test that a custom header (list type) can be attached." 
    123                 extra_headers = [('Precendence', 'bulk'), ('X-User', 'Alice')] 
    124                 message = turbomail.Message('sender@foo.example',  
    125                                                                         'recipient@foo.example', 'foo bar') 
    126                 message.plain = 'Hello World!' 
    127                 message.headers = extra_headers 
    128                 turbomail.enqueue(message) 
    129                 msginfo = get_received_mail(self.sink) 
    130                 msg = email.message_from_string(msginfo['mail'])  
    131                 for name, value in extra_headers: 
    132                         self.failUnless(msg.has_key(name)) 
    133                         self.assertEquals(value, msg[name]) 
    134  
     121    def test_add_custom_headers_list(self): 
     122        "Test that a custom header (list type) can be attached." 
     123        extra_headers = [('Precendence', 'bulk'), ('X-User', 'Alice')] 
     124        message = turbomail.Message('sender@foo.example', 
     125                                                                'recipient@foo.example', 'foo bar') 
     126        message.plain = 'Hello World!' 
     127        message.headers = extra_headers 
     128        turbomail.enqueue(message) 
     129        msginfo = get_received_mail(self.sink) 
     130        msg = email.message_from_string(msginfo['mail']) 
     131        for name, value in extra_headers: 
     132            self.failUnless(msg.has_key(name)) 
     133            self.assertEquals(value, msg[name])