コード例 #1
0
            }]
        )
        records = self.wait_for_stream_data()
        self.assert_record_data_contains(records, b'foobar', b'barfoo')

    def wait_for_stream_data(self, num_attempts=6, poll_time=10):
        # Poll until we get records returned from get_records().
        for i in range(num_attempts):
            time.sleep(poll_time)
            stream = self.client.describe_stream(StreamName=self.stream_name)
            shard = stream['StreamDescription']['Shards'][0]
            shard_iterator = self.client.get_shard_iterator(
                StreamName=self.stream_name, ShardId=shard['ShardId'],
                ShardIteratorType='TRIM_HORIZON')
            records = self.client.get_records(
                ShardIterator=shard_iterator['ShardIterator'])
            if records['Records']:
                return records
        raise RuntimeError("Unable to retrieve data from kinesis stream after "
                           "%s attempts with delay of %s seconds."
                           % (num_attempts, poll_time))

    def assert_record_data_contains(self, records, *expected):
        record_data = [r['Data'] for r in records['Records']]
        for item in expected:
            self.assertIn(item, record_data)


if __name__ == '__main__':
    unittest.main()
コード例 #2
0
        c = pymongo.MongoClient(self.server.host, self.server.port)
        self.assertRaises(pymongo.errors.OperationFailure,
                          c.admin.collection_names)

    def test_auth_admin(self):
        c = pymongo.MongoClient(self.server.host, self.server.port)
        self.assertRaises(pymongo.errors.OperationFailure,
                          c.admin.collection_names)
        self.assertTrue(c.admin.authenticate('admin', 'admin'))
        self.assertTrue(isinstance(c.admin.collection_names(), list))
        self.assertTrue(c.admin.logout() is None)
        self.assertRaises(pymongo.errors.OperationFailure,
                          c.admin.collection_names)

    def test_auth_collection(self):
        c = pymongo.MongoClient(self.server.host, self.server.port)
        self.assertTrue(c.admin.authenticate('admin', 'admin'))
        db = c.test_server_auth
        db.add_user('user', 'userpass', roles=['readWrite'])
        c.admin.logout()

        self.assertTrue(db.authenticate('user', 'userpass'))
        self.assertTrue(db.foo.insert({'foo': 'bar'}, wtimeout=1000))
        self.assertTrue(isinstance(db.foo.find_one(), dict))
        db.logout()
        self.assertRaises(pymongo.errors.OperationFailure, db.foo.find_one)


if __name__ == '__main__':
    unittest.main(verbosity=3)
コード例 #3
0
        # If we unregister the first event from the copied emitter,
        # We should be able to register the second handler.
        copied_emitter.unregister('foo', first_handler, 'bar')
        copied_emitter.register('foo', second_handler, 'bar')
        copied_emitter.emit('foo', id_name='third-time')
        self.assertEqual(first, ['first-time', 'second-time'])
        self.assertEqual(second, ['third-time'])

        # The original event emitter should have the unique id event still
        # registered though.
        self.emitter.emit('foo', id_name='fourth-time')
        self.assertEqual(first, ['first-time', 'second-time', 'fourth-time'])
        self.assertEqual(second, ['third-time'])

    def test_copy_events_with_partials(self):
        # There's a bug in python2.6 where you can't deepcopy
        # a partial object.  We want to ensure that doesn't
        # break when a partial is hooked up as an event handler.
        def handler(a, b, **kwargs):
            return b

        f = functools.partial(handler, 1)
        self.emitter.register('a.b', f)
        copied = copy.copy(self.emitter)
        self.assertEqual(copied.emit_until_response(
            'a.b', b='return-val')[1], 'return-val')


if __name__ == '__main__':
    unittest.main()
コード例 #4
0
ファイル: ticket.py プロジェクト: tsanov/bloodhound
    suite.addTest(RegressionTestTicket6912a())
    suite.addTest(RegressionTestTicket6912b())
    suite.addTest(RegressionTestTicket7821group())
    suite.addTest(RegressionTestTicket7821var())
    suite.addTest(RegressionTestTicket8247())
    suite.addTest(RegressionTestTicket8861())
    suite.addTest(RegressionTestTicket9084())
    suite.addTest(RegressionTestTicket9981())

    return suite


#--------------
# Multiproduct test cases
#--------------


def functionalSuite(suite=None):
    if not suite:
        from tests import functional
        suite = functional.functionalSuite()

    trac_functionalSuite(suite)

    return suite


if __name__ == '__main__':
    import unittest
    unittest.main(defaultTest='functionalSuite')
コード例 #5
0
ファイル: upgrade.py プロジェクト: thimalk/bloodhound
    def construct_dummy_table(self, n_custom_fields=1):
        fields = [Column('id')] + [
            Column('v%d' % (i+1)) for i in range(n_custom_fields)
        ]
        return Table('dummy_table')[fields]

    def get_version(self, db):
        rows = db("SELECT value FROM system WHERE name = %s",
                  (self.__class__.__name__,))
        return int(rows[0][0]) if rows else 0

    def update_version(self, db, version):
        old_version = self.get_version(db)
        if old_version:
            db("UPDATE system SET value=%s WHERE name=%s",
               (version, self.__class__.__name__,))
        else:
            db("INSERT INTO system (name, value) VALUES ('%s','%s')"
               % (self.__class__.__name__, version))
        return version


def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(EnvironmentUpgradeTestCase, 'test'))
    return suite

if __name__ == '__main__':
    unittest.main(defaultTest='test_suite')
コード例 #6
0
        process.cleanup_mprocess(config_path, cfg)

    def test_write_config_with_specify_config_path(self):
        cfg = {'port': 27017, 'objcheck': 'true'}
        fd_key, file_path = tempfile.mkstemp()
        os.close(fd_key)
        config_path = process.write_config(cfg, file_path)
        self.assertEqual(file_path, config_path)
        process.cleanup_mprocess(config_path, cfg)

    def test_proc_alive(self):
        p = subprocess.Popen([self.executable])
        self.assertTrue(process.proc_alive(p))
        p.terminate()
        p.wait()
        self.assertFalse(process.proc_alive(p))
        self.assertFalse(process.proc_alive(None))

    def test_read_config(self):
        cfg = {"noprealloc": True, "smallfiles": False, "oplogSize": 10, "other": "some string"}
        config_path = process.write_config(cfg)
        self.tmp_files.append(config_path)
        self.assertEqual(process.read_config(config_path), cfg)


if __name__ == '__main__':
    unittest.main(verbosity=3)
    # suite = unittest.TestSuite()
    # suite.addTest(ProcessTestCase('test_repair'))
    # unittest.TextTestRunner(verbosity=2).run(suite)
コード例 #7
0
ファイル: core.py プロジェクト: tsanov/bloodhound
            self.assertIsInstance(c, ComponentA)

    def test_with_product_component_manager(self):
        self.compmgr.parent = self
        self.compmgr.all_product_envs = lambda: [self.compmgr, self.compmgr]

        class ComponentA(Component):
            implements(ITest)

        class ComponentB(Component):
            mp_extension_point = MultiProductExtensionPoint(ITest)

        components = ComponentB(self.compmgr).mp_extension_point
        self.assertEqual(len(components), 1)
        for c in components:
            self.assertIsInstance(c, ComponentA)


class ITest(Interface):
    def test():
        """Dummy function."""


def test_suite():
    return unittest.TestSuite([
        unittest.makeSuite(MultiProductExtensionPointTestCase, 'test'),
    ])

if __name__ == '__main__':
    unittest.main(defaultTest='test_suite')
コード例 #8
0
ファイル: ticket.py プロジェクト: mohsadki/dargest
    suite.addTest(RegressionTestTicket6912b())
    suite.addTest(RegressionTestTicket7821group())
    suite.addTest(RegressionTestTicket7821var())
    suite.addTest(RegressionTestTicket8247())
    suite.addTest(RegressionTestTicket8861())
    suite.addTest(RegressionTestTicket9084())
    suite.addTest(RegressionTestTicket9981())

    return suite


#--------------
# Multiproduct test cases
#--------------



def functionalSuite(suite=None):
    if not suite:
        from tests import functional
        suite = functional.functionalSuite()

    trac_functionalSuite(suite)

    return suite


if __name__ == '__main__':
    import unittest
    unittest.main(defaultTest='functionalSuite')