예제 #1
0
    def testRobust(self):
        """Test the sendRobust function"""
        def fails(val, **kwargs):
            raise ValueError('this')
        a_signal.connect(fails)
        result = a_signal.send_robust(sender=self, val="test")
        err = result[0][1]
        self.assert_(isinstance(err, ValueError))
        self.assertEqual(err.args, ('this',))
        a_signal.disconnect(fails)
        self._testIsClean(a_signal)

    def testDisconnection(self):
        receiver_1 = Callable()
        receiver_2 = Callable()
        receiver_3 = Callable()
        a_signal.connect(receiver_1)
        a_signal.connect(receiver_2)
        a_signal.connect(receiver_3)
        a_signal.disconnect(receiver_1)
        del receiver_2
        garbage_collect()
        a_signal.disconnect(receiver_3)
        self._testIsClean(a_signal)

def getSuite():
    return unittest.makeSuite(DispatcherTests,'test')

if __name__ == "__main__":
    unittest.main()
예제 #2
0
        self.assertNotEqual(t1.render(Context({})), t2.render(Context({})))


class RenderToStringTest(unittest.TestCase):
    def setUp(self):
        self._old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
        settings.TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__),
                                               'templates'), )

    def tearDown(self):
        settings.TEMPLATE_DIRS = self._old_TEMPLATE_DIRS

    def test_basic(self):
        self.assertEqual(loader.render_to_string('test_context.html'), 'obj:')

    def test_basic_context(self):
        self.assertEqual(
            loader.render_to_string('test_context.html', {'obj': 'test'}),
            'obj:test')

    def test_existing_context_kept_clean(self):
        context = Context({'obj': 'before'})
        output = loader.render_to_string('test_context.html', {'obj': 'after'},
                                         context_instance=context)
        self.assertEqual(output, 'obj:after')
        self.assertEqual(context['obj'], 'before')


if __name__ == "__main__":
    unittest.main()
예제 #3
0
        self.assertAuthenticated('*****@*****.**', 'qwerty')
        self.assertAllowed('*****@*****.**')
        self.assertRejected('*****@*****.**')
        clean_whitelist()
    
    def testW2(self):
        self.assertAuthenticated('*****@*****.**', 'qwerty')
        for i in xrange(5):
            self.assertAllowed('*****@*****.**')
        self.assertRejected('*****@*****.**')
        clean_whitelist()

    def testW3(self):
        self.assertAuthenticated('*****@*****.**', 'qwerty')
        for i in xrange(4):
            self.assertAllowed('*****@*****.**')
        for i in xrange(7):
            self.assertAuthenticated('*****@*****.**', 'qwerty', ip='127.0.0.%d' % (2+i))
        self.assertAllowed('*****@*****.**')
        self.assertRejected('*****@*****.**')
        clean_whitelist()

if __name__ == '__main__':
    if getattr(settings, 'RS_TEST_WHITELIST_AS_WELL', False):
        unittest.main(verbosity=2)
    else:
        suite = unittest.TestLoader().loadTestsFromTestCase(Test)
        unittest.TextTestRunner(verbosity=2).run(suite)
        print '\nWarning: to speed things up whitelist testing was skipped (so that only test redis db is used). '\
              'Run \'./manage.py test redissentry\' to go through all tests (test main database will be used as well).'
예제 #4
0
def main():
    unittest.main()
예제 #5
0
def main():
    unittest.main()
예제 #6
0
        clean_whitelist()

    def testW2(self):
        self.assertAuthenticated('*****@*****.**', 'qwerty')
        for i in xrange(5):
            self.assertAllowed('*****@*****.**')
        self.assertRejected('*****@*****.**')
        clean_whitelist()

    def testW3(self):
        self.assertAuthenticated('*****@*****.**', 'qwerty')
        for i in xrange(4):
            self.assertAllowed('*****@*****.**')
        for i in xrange(7):
            self.assertAuthenticated('*****@*****.**',
                                     'qwerty',
                                     ip='127.0.0.%d' % (2 + i))
        self.assertAllowed('*****@*****.**')
        self.assertRejected('*****@*****.**')
        clean_whitelist()


if __name__ == '__main__':
    if getattr(settings, 'RS_TEST_WHITELIST_AS_WELL', False):
        unittest.main(verbosity=2)
    else:
        suite = unittest.TestLoader().loadTestsFromTestCase(Test)
        unittest.TextTestRunner(verbosity=2).run(suite)
        print '\nWarning: to speed things up whitelist testing was skipped (so that only test redis db is used). '\
              'Run \'./manage.py test redissentry\' to go through all tests (test main database will be used as well).'