def testFormatter(self): [msg] = juice.parseString( benchmark.formatResults( "frunk", 4096, benchmark.ResourceSnapshot( 3, benchmark.diskstat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), benchmark.partitionstat(1, 2, 3, 4), 12), benchmark.ResourceSnapshot( 7, benchmark.diskstat(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21), benchmark.partitionstat(5, 7, 9, 11), 56), False, False)) self.assertEquals(msg['_command'], 'Result') self.assertEquals(msg['version'], '0') self.assertEquals(msg['error'], 'False') self.assertEquals(msg['timeout'], 'False') self.assertEquals(msg['name'], 'frunk') self.failIfEqual(msg['host'], 'localhost') self.assertIn('sector_size', msg) self.assertIn('python_version', msg) self.assertIn('twisted_version', msg) self.assertIn('divmod_version', msg) self.assertEquals(msg['elapsed'], '4') self.assertEquals(msg['filesystem_growth'], '44') self.assertEquals(msg['read_count'], '4') self.assertEquals(msg['read_sectors'], '5') self.assertEquals(msg['write_count'], '6') self.assertEquals(msg['write_sectors'], '7') self.assertEquals(msg['read_ms'], '10') self.assertEquals(msg['write_ms'], '10')
def testCreateRTPSocket(self): lcp = useragent.LocalControlProtocol(False) lcp.makeConnection(StringTransport()) lcp.createRTPSocket("A Dialog", u"server.com") box = juice.parseString(lcp.transport.value()) self.assertEquals(box[0]['host'], "server.com") lcp.dataReceived('-Answer: %s\r\nCookie: 123\r\n\r\n' % (box[0]['_ask'])) self.assertEquals(lcp.dialogs['123'], "A Dialog") self.assertEquals(lcp.cookies["A Dialog"], '123')
def testFormatterWithoutPartitionStats(self): """ Sometimes it is not possible to find partitionstats. In these cases, None should be reported as the value for all fields which are derived from the partitionstats object. """ [msg] = juice.parseString(benchmark.formatResults( "frunk", 4096, benchmark.ResourceSnapshot( 3, benchmark.diskstat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), None, 12), benchmark.ResourceSnapshot( 7, benchmark.diskstat(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21), None, 56), False, False)) self.assertEqual(msg['_command'], 'Result') self.assertEqual(msg['version'], '0') self.assertEqual(msg['error'], 'False') self.assertEqual(msg['timeout'], 'False') self.assertEqual(msg['name'], 'frunk') self.assertNotEqual(msg['host'], 'localhost') self.assertIn('sector_size', msg) self.assertIn('python_version', msg) self.assertIn('twisted_version', msg) self.assertIn('divmod_version', msg) self.assertEqual(msg['elapsed'], '4') self.assertEqual(msg['filesystem_growth'], '44') self.failIfIn('read_count', msg) self.failIfIn('read_sectors', msg) self.failIfIn('write_count', msg) self.failIfIn('write_sectors', msg) self.assertEqual(msg['read_ms'], '10') self.assertEqual(msg['write_ms'], '10')
def testFormatter(self): [msg] = juice.parseString(benchmark.formatResults( "frunk", 4096, benchmark.ResourceSnapshot( 3, benchmark.diskstat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), benchmark.partitionstat(1, 2, 3, 4), 12), benchmark.ResourceSnapshot( 7, benchmark.diskstat(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21), benchmark.partitionstat(5, 7, 9, 11), 56), False, False)) self.assertEqual(msg['_command'], 'Result') self.assertEqual(msg['version'], '0') self.assertEqual(msg['error'], 'False') self.assertEqual(msg['timeout'], 'False') self.assertEqual(msg['name'], 'frunk') self.assertNotEqual(msg['host'], 'localhost') self.assertIn('sector_size', msg) self.assertIn('python_version', msg) self.assertIn('twisted_version', msg) self.assertIn('divmod_version', msg) self.assertEqual(msg['elapsed'], '4') self.assertEqual(msg['filesystem_growth'], '44') self.assertEqual(msg['read_count'], '4') self.assertEqual(msg['read_sectors'], '5') self.assertEqual(msg['write_count'], '6') self.assertEqual(msg['write_sectors'], '7') self.assertEqual(msg['read_ms'], '10') self.assertEqual(msg['write_ms'], '10')
if not os.path.exists(domainpath): os.makedirs(domainpath) userpath = os.path.join(domainpath, username+".info") if os.path.exists(userpath): raise NotAllowed() f = open(userpath, 'w') f.write(juice.Box(username=username, password=password.encode('hex')).serialize()) f.close() def get(self, (domain, username)): domainpath = os.path.join(self.path, domain) if os.path.exists(domainpath): filepath = os.path.join(domainpath, username+".info") if os.path.exists(filepath): data = juice.parseString(open(filepath).read())[0] return data['password'].decode('hex') class DirectoryCertificateAndUserStore(q2q.DirectoryCertificateStore): def __init__(self, filepath): q2q.DirectoryCertificateStore.__init__(self, filepath) self.users = _usermap(os.path.join(filepath, "users")) def getPrivateCertificate(self, domain): try: return q2q.DirectoryCertificateStore.getPrivateCertificate(self, domain) except KeyError: if len(self.localStore.keys()) > 10: # avoid DoS; nobody is going to need autocreated certs for more # than 10 domains raise