commit 12311fff64dba06b24c66dd0523e52f3cd8927b9 Author: Matthew Finkel Matthew.Finkel@gmail.com Date: Sun Aug 3 18:18:22 2014 +0000
Add a test for Buckets
The others will require mocking a DB connection. --- lib/bridgedb/test/test_Bucket.py | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+)
diff --git a/lib/bridgedb/test/test_Bucket.py b/lib/bridgedb/test/test_Bucket.py new file mode 100644 index 0000000..7cadd7b --- /dev/null +++ b/lib/bridgedb/test/test_Bucket.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +# +# This file is part of BridgeDB, a Tor bridge distribution system. +# +# :copyright: (c) 2007-2014, The Tor Project, Inc. +# (c) 2007-2014, all entities within the AUTHORS file +# :license: 3-Clause BSD, see LICENSE for licensing information + +"""Unittests for the :mod:`bridgedb.Bucket` module. + +These tests are meant to ensure that the :mod:`bridgedb.Bucket` module is +functioning as expected. +""" + +from __future__ import print_function + +import sure +from sure import this +from sure import the +from sure import expect + +from bridgedb import Bucket + + +class BucketDataTest(unittest.TestCase): + """Tests for :class:`bridgedb.Bucket.BucketData`.""" + + def test_alloc_some_of_the_bridges(self): + """Set the needed number of bridges""" + alloc = 10 + distname = "test-distributor" + bucket = Bucket.BucketData(distname, alloc) + this(distname).should.be.equal(bucket.name) + this(alloc).should.be.equal(bucket.needed) + + def test_alloc_all_the_bridges(self): + """Set the needed number of bridges to the default""" + alloc = '*' + distname = "test-distributor" + bucket = Bucket.BucketData(distname, alloc) + this(distname).should.be.equal(bucket.name) + this(alloc).should.be.equal(1000000) + + +class BucketManagerTest(unittest.TestCase): + """Tests for :class:`bridgedb.Bucket.BucketManager`.""" + TEST_CONFIG_FILE = StringIO(unicode("""\ + FILE_BUCKETS = { 'test1': 7, 'test2': 11 } + COLLECT_TIMESTAMPS = False + COUNTRY_BLOCK_FILE = []""")) + + def setUp(self): + configuration = {} + TEST_CONFIG_FILE.seek(0) + compiled = compile(TEST_CONFIG_FILE.read(), '<string>', 'exec') + exec compiled in configuration + self.config = persistent.Conf(**configuration) + self.state = persistent.State(**config.__dict__) + self.bucket = Bucket.BucketManager(self.config)