def test_adaptors_sorted(self, mock_get_gsm):
     'Ensure the adaptors are sorted by the ``weight`` attribute'
     mock_gsm = mock_get_gsm()
     mock_gsm.getAdapters.return_value = [('Ethel', SimpleRule(weight=8)),
                                          ('the', SimpleRule(weight=10)),
                                          ('frog', SimpleRule(weight=7))]
     canPost = CanPostToGroup(self.group, self.userInfo)
     r = canPost.adaptors
     self.assertEqual([7, 8, 10], [a.weight for a in [b[1] for b in r]])
 def test_rules(self, mock_adaptors):
     'Test the ``rules`` attribute returns just the rules'
     r0 = SimpleRule()
     r1 = SimpleRule()
     r2 = SimpleRule()
     mock_adaptors.return_value = [('Ethel', r0), ('the', r1), ('frog', r2)]
     canPost = CanPostToGroup(self.group, self.userInfo)
     r = canPost.rules
     self.assertEqual([r0, r1, r2], r)
 def test_status(self, mock_rules):
     'Test we get the right status-message if there are rules'
     mock_rules.return_value = [
         SimpleRule(True, 0, 'Ethel'),
         SimpleRule(False, 9, 'the'),
         SimpleRule(False, 7, 'frog')
     ]
     canPost = CanPostToGroup(self.group, self.userInfo)
     r = canPost.status
     self.assertEqual('frog', r)
 def test_status_num_min(self, mock_rules):
     'Test we get the minumum status if there are rules'
     mock_rules.return_value = [
         SimpleRule(True),
         SimpleRule(False, 9),
         SimpleRule(False, 7)
     ]
     canPost = CanPostToGroup(self.group, self.userInfo)
     r = canPost.statusNum
     self.assertEqual(7, r)
 def test_can_post_one_of_many_false(self, mock_rules):
     'Test we are blocked from posting if a rule of many is False'
     mock_rules.return_value = [
         SimpleRule(True),
         SimpleRule(False),
         SimpleRule(True)
     ]
     canPost = CanPostToGroup(self.group, self.userInfo)
     r = canPost.canPost
     self.assertFalse(r)
 def test_status_num_0(self, mock_rules):
     'Test we get status of 0 (ok) if there are no rules'
     mock_rules.return_value = []
     canPost = CanPostToGroup(self.group, self.userInfo)
     r = canPost.statusNum
     self.assertEqual(0, r)
 def test_can_post_all_true(self, mock_rules):
     'Test we can post if the rules are all True'
     mock_rules.return_value = [SimpleRule(True), SimpleRule(True)]
     canPost = CanPostToGroup(self.group, self.userInfo)
     r = canPost.canPost
     self.assertTrue(r)
 def test_can_post_no_rules(self, mock_rules):
     'Test we can post if there are no rules'
     mock_rules.return_value = []
     canPost = CanPostToGroup(self.group, self.userInfo)
     r = canPost.canPost
     self.assertTrue(r)