示例#1
0
 def setUp(self):
     self._mlist = create_list('*****@*****.**')
     self.command = Members()
     self.command.parser = FakeParser()
     self.args = FakeArgs()
示例#2
0
 def setUp(self):
     self._mlist = create_list('*****@*****.**')
     self.command = Members()
     self.command.parser = FakeParser()
     self.args = FakeArgs()
示例#3
0
class TestCLIMembers(unittest.TestCase):
    layer = ConfigLayer

    def setUp(self):
        self._mlist = create_list('*****@*****.**')
        self.command = Members()
        self.command.parser = FakeParser()
        self.args = FakeArgs()

    def test_no_such_list(self):
        self.args.list = ['bee.example.com']
        with self.assertRaises(SystemExit):
            self.command.process(self.args)
        self.assertEqual(self.command.parser.message,
                         'No such list: bee.example.com')

    def test_bad_delivery_status(self):
        self.args.list = ['ant.example.com']
        self.args.nomail = 'bogus'
        with self.assertRaises(SystemExit):
            self.command.process(self.args)
        self.assertEqual(self.command.parser.message,
                         'Unknown delivery status: bogus')

    def test_role_administrator(self):
        subscribe(self._mlist, 'Anne', role=MemberRole.owner)
        subscribe(self._mlist, 'Bart', role=MemberRole.moderator)
        subscribe(self._mlist, 'Cate', role=MemberRole.nonmember)
        subscribe(self._mlist, 'Dave', role=MemberRole.member)
        self.args.list = ['ant.example.com']
        self.args.role = 'administrator'
        with NamedTemporaryFile('w', encoding='utf-8') as outfp:
            self.args.output_filename = outfp.name
            self.command.process(self.args)
            with open(outfp.name, 'r', encoding='utf-8') as infp:
                lines = infp.readlines()
        self.assertEqual(len(lines), 2)
        self.assertEqual(lines[0], 'Anne Person <*****@*****.**>\n')
        self.assertEqual(lines[1], 'Bart Person <*****@*****.**>\n')

    def test_role_any(self):
        subscribe(self._mlist, 'Anne', role=MemberRole.owner)
        subscribe(self._mlist, 'Bart', role=MemberRole.moderator)
        subscribe(self._mlist, 'Cate', role=MemberRole.nonmember)
        subscribe(self._mlist, 'Dave', role=MemberRole.member)
        self.args.list = ['ant.example.com']
        self.args.role = 'any'
        with NamedTemporaryFile('w', encoding='utf-8') as outfp:
            self.args.output_filename = outfp.name
            self.command.process(self.args)
            with open(outfp.name, 'r', encoding='utf-8') as infp:
                lines = infp.readlines()
        self.assertEqual(len(lines), 4)
        self.assertEqual(lines[0], 'Anne Person <*****@*****.**>\n')
        self.assertEqual(lines[1], 'Bart Person <*****@*****.**>\n')
        self.assertEqual(lines[2], 'Cate Person <*****@*****.**>\n')
        self.assertEqual(lines[3], 'Dave Person <*****@*****.**>\n')

    def test_role_moderator(self):
        subscribe(self._mlist, 'Anne', role=MemberRole.owner)
        subscribe(self._mlist, 'Bart', role=MemberRole.moderator)
        subscribe(self._mlist, 'Cate', role=MemberRole.nonmember)
        subscribe(self._mlist, 'Dave', role=MemberRole.member)
        self.args.list = ['ant.example.com']
        self.args.role = 'moderator'
        with NamedTemporaryFile('w', encoding='utf-8') as outfp:
            self.args.output_filename = outfp.name
            self.command.process(self.args)
            with open(outfp.name, 'r', encoding='utf-8') as infp:
                lines = infp.readlines()
        self.assertEqual(len(lines), 1)
        self.assertEqual(lines[0], 'Bart Person <*****@*****.**>\n')

    def test_bad_role(self):
        self.args.list = ['ant.example.com']
        self.args.role = 'bogus'
        with self.assertRaises(SystemExit):
            self.command.process(self.args)
        self.assertEqual(self.command.parser.message,
                         'Unknown member role: bogus')

    def test_already_subscribed_with_display_name(self):
        subscribe(self._mlist, 'Anne')
        outfp = StringIO()
        with NamedTemporaryFile('w', buffering=1, encoding='utf-8') as infp:
            print('Anne Person <*****@*****.**>', file=infp)
            self.args.list = ['ant.example.com']
            self.args.input_filename = infp.name
            with patch('builtins.print', partial(print, file=outfp)):
                self.command.process(self.args)
        self.assertEqual(
            outfp.getvalue(),
            'Already subscribed (skipping): Anne Person <*****@*****.**>\n'
        )
示例#4
0
class TestCLIMembers(unittest.TestCase):
    layer = ConfigLayer

    def setUp(self):
        self._mlist = create_list('*****@*****.**')
        self.command = Members()
        self.command.parser = FakeParser()
        self.args = FakeArgs()

    def test_no_such_list(self):
        self.args.list = ['bee.example.com']
        with self.assertRaises(SystemExit):
            self.command.process(self.args)
        self.assertEqual(self.command.parser.message,
                         'No such list: bee.example.com')

    def test_bad_delivery_status(self):
        self.args.list = ['ant.example.com']
        self.args.nomail = 'bogus'
        with self.assertRaises(SystemExit):
            self.command.process(self.args)
        self.assertEqual(self.command.parser.message,
                         'Unknown delivery status: bogus')

    def test_role_administrator(self):
        subscribe(self._mlist, 'Anne', role=MemberRole.owner)
        subscribe(self._mlist, 'Bart', role=MemberRole.moderator)
        subscribe(self._mlist, 'Cate', role=MemberRole.nonmember)
        subscribe(self._mlist, 'Dave', role=MemberRole.member)
        self.args.list = ['ant.example.com']
        self.args.role = 'administrator'
        with NamedTemporaryFile('w', encoding='utf-8') as outfp:
            self.args.output_filename = outfp.name
            self.command.process(self.args)
            with open(outfp.name, 'r', encoding='utf-8') as infp:
                lines = infp.readlines()
        self.assertEqual(len(lines), 2)
        self.assertEqual(lines[0], 'Anne Person <*****@*****.**>\n')
        self.assertEqual(lines[1], 'Bart Person <*****@*****.**>\n')

    def test_role_any(self):
        subscribe(self._mlist, 'Anne', role=MemberRole.owner)
        subscribe(self._mlist, 'Bart', role=MemberRole.moderator)
        subscribe(self._mlist, 'Cate', role=MemberRole.nonmember)
        subscribe(self._mlist, 'Dave', role=MemberRole.member)
        self.args.list = ['ant.example.com']
        self.args.role = 'any'
        with NamedTemporaryFile('w', encoding='utf-8') as outfp:
            self.args.output_filename = outfp.name
            self.command.process(self.args)
            with open(outfp.name, 'r', encoding='utf-8') as infp:
                lines = infp.readlines()
        self.assertEqual(len(lines), 4)
        self.assertEqual(lines[0], 'Anne Person <*****@*****.**>\n')
        self.assertEqual(lines[1], 'Bart Person <*****@*****.**>\n')
        self.assertEqual(lines[2], 'Cate Person <*****@*****.**>\n')
        self.assertEqual(lines[3], 'Dave Person <*****@*****.**>\n')

    def test_role_moderator(self):
        subscribe(self._mlist, 'Anne', role=MemberRole.owner)
        subscribe(self._mlist, 'Bart', role=MemberRole.moderator)
        subscribe(self._mlist, 'Cate', role=MemberRole.nonmember)
        subscribe(self._mlist, 'Dave', role=MemberRole.member)
        self.args.list = ['ant.example.com']
        self.args.role = 'moderator'
        with NamedTemporaryFile('w', encoding='utf-8') as outfp:
            self.args.output_filename = outfp.name
            self.command.process(self.args)
            with open(outfp.name, 'r', encoding='utf-8') as infp:
                lines = infp.readlines()
        self.assertEqual(len(lines), 1)
        self.assertEqual(lines[0], 'Bart Person <*****@*****.**>\n')

    def test_bad_role(self):
        self.args.list = ['ant.example.com']
        self.args.role = 'bogus'
        with self.assertRaises(SystemExit):
            self.command.process(self.args)
        self.assertEqual(self.command.parser.message,
                         'Unknown member role: bogus')

    def test_already_subscribed_with_display_name(self):
        subscribe(self._mlist, 'Anne')
        outfp = StringIO()
        with NamedTemporaryFile('w', buffering=1, encoding='utf-8') as infp:
            print('Anne Person <*****@*****.**>', file=infp)
            self.args.list = ['ant.example.com']
            self.args.input_filename = infp.name
            with patch('builtins.print', partial(print, file=outfp)):
                self.command.process(self.args)
        self.assertEqual(
           outfp.getvalue(),
           'Already subscribed (skipping): Anne Person <*****@*****.**>\n'
           )