Esempio n. 1
0
 def testGetExistingValue(self):
     """Test getting an existing value."""
     mock_namespace = SubscriptableMock()
     mock_namespace.expects(pmock.at_least_once()).acquire_read_lock()
     mock_namespace.expects(pmock.at_least_once()).release_read_lock()
     mock_namespace.expects(pmock.once()).has_key(
         pmock.eq(self.test_key)).will(pmock.return_value(True))
     mock_namespace.expects(pmock.once()).mock__getitem__(
         pmock.eq(self.test_key)).will(pmock.return_value(
         (time.time() - 60*5, time.time() + 60*5, 42)))
     def mock_create_func():
         self.fail('Attempted to create a new value.')
     value = out_of_band_cache.Value(self.test_key, mock_namespace,
                                     createfunc=mock_create_func).get_value()
     mock_namespace.verify()
 def test__refit_multichoice_len(self):
     """
     Test length of multi_choices
     """
     self.mock_listener.expects(at_least_once()).question_changed()
     assert len(self.quiz.multi_choices) == self.quiz.DEFAULT_MULTICHOICE_LEN
     self.quiz.remove_quizzes(self.quiz.quiz_pool[self.quiz.DEFAULT_MULTICHOICE_LEN :])
     assert len(self.quiz.multi_choices) == self.quiz.DEFAULT_MULTICHOICE_LEN, (
         "self.quiz.multi_choices has wrong length: %s instead of %s."
         % (len(self.quiz.multi_choices), self.quiz.DEFAULT_MULTICHOICE_LEN)
     )
     self.quiz.remove_quizzes(self.quiz.quiz_pool[3 : self.quiz.DEFAULT_MULTICHOICE_LEN])
     assert len(self.quiz.multi_choices) == 3, "self.quiz.multi_choices has wrong length: %s instead of 3." % len(
         self.quiz.multi_choices
     )
     self.quiz.remove_quizzes(self.quiz.quiz_pool[:3])
     assert len(self.quiz.multi_choices) == 1
     self.mock_listener.verify()
Esempio n. 3
0
 def test__refit_multichoice_len(self):
     """
     Test length of multi_choices
     """
     self.mock_listener.expects(at_least_once()).question_changed()
     assert len(
         self.quiz.multi_choices) == self.quiz.DEFAULT_MULTICHOICE_LEN
     self.quiz.remove_quizzes(
         self.quiz.quiz_pool[self.quiz.DEFAULT_MULTICHOICE_LEN:])
     assert len(self.quiz.multi_choices) == \
             self.quiz.DEFAULT_MULTICHOICE_LEN, \
             "self.quiz.multi_choices has wrong length: %s instead of %s." \
             % (len(self.quiz.multi_choices), \
             self.quiz.DEFAULT_MULTICHOICE_LEN)
     self.quiz.remove_quizzes(
         self.quiz.quiz_pool[3:self.quiz.DEFAULT_MULTICHOICE_LEN])
     assert len(self.quiz.multi_choices) == 3, \
         "self.quiz.multi_choices has wrong length: %s instead of 3." % \
         len(self.quiz.multi_choices)
     self.quiz.remove_quizzes(self.quiz.quiz_pool[:3])
     assert len(self.quiz.multi_choices) == 1
     self.mock_listener.verify()
Esempio n. 4
0
 def setUp(self):
     self.mock = pmock.Mock()
     self.mock.expects(pmock.at_least_once()).method("rabbit")