File: test_abook.py

package info (click to toggle)
alot 0.11-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,716 kB
  • sloc: python: 11,261; makefile: 125; sh: 8
file content (41 lines) | stat: -rw-r--r-- 1,265 bytes parent folder | download
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
# Copyright (C) 2017  Lucas Hoffmann
# This file is released under the GNU GPL, version 3 or a later revision.
# For further details see the COPYING file
import os
import tempfile
import unittest

from alot.addressbook import abook
from alot.settings.errors import ConfigError

from .. import utilities
utilities.fix_default_paths()


class TestAbookAddressBook(unittest.TestCase):

    def test_abook_file_can_not_be_empty(self):
        with self.assertRaises(ConfigError):
            abook.AbookAddressBook("/dev/null")

    def test_get_contacts_lists_all_emails(self):
        data = """
        [format]
        version = unknown
        program = alot-test-suite
        [1]
        name = me
        email = me@example.com
        [2]
        name = you
        email = you@other.domain, you@example.com
        """
        with tempfile.NamedTemporaryFile(mode='w+', delete=False) as tmp:
            tmp.write(data)
            path = tmp.name
            self.addCleanup(os.unlink, path)
        addressbook = abook.AbookAddressBook(path)
        actual = addressbook.get_contacts()
        expected = [('me', 'me@example.com'), ('you', 'you@other.domain'),
                    ('you', 'you@example.com')]
        self.assertListEqual(actual, expected)