def main(): class FakeDeviceInfo(object): Manufacturer = 'manufacturer' ManufacturerOUI = 'oui' ProductClass = 'productclass' SerialNumber = 'serialnumber' root = core.Exporter() root.Export(params=['Test', 'Test2'], lists=['Sub']) root.Test = '5' root.Test2 = 6 root.SubList = {} root.Sub = core.Exporter root.DeviceInfo = FakeDeviceInfo() real_acs = api.ACS() real_cpe = api.CPE(real_acs, root, None) cpe = CPE(real_cpe) acs = ACS(real_acs) encode = Encode() print cpe.Handle(encode.GetRPCMethods()) print cpe.Handle(encode.GetParameterNames('', False)) print cpe.Handle(encode.GetParameterValues(['Test'])) print cpe.Handle(encode.SetParameterValues([('Test', 6), ('Test2', 7)], 77)) print cpe.Handle(encode.GetParameterValues(['Test', 'Test2'])) print cpe.Handle(encode.AddObject('Sub.', 5)) print cpe.Handle(encode.DeleteObject('Sub.0', 5)) print acs.Handle(encode.Inform(root, [], 1, None, 1, []))
def testObject(self): root = core.Exporter() root.Export(objects=['Test']) root.Test = TestObject() root.ValidateExports() cpe = api.CPE(root) #pylint: disable-msg=W0612 (idx, status) = cpe.AddObject('Test.Thingy.', 0) name = 'Test.Thingy.%d' % int(idx) #pylint: disable-msg=E1103 cpe.SetParameterValues([('%s.word' % name, 'word1')], 0) self.assertEqual(root.GetExport(name).word, 'word1') self.assertRaises(KeyError, cpe._SetParameterValue, '%s.not_exist' % name, 'word1') result = cpe.GetParameterValues(['%s.word' % name]) self.assertEqual(result, [('%s.word' % name, 'word1')])
def main(): loop = mainloop.MainLoop() class Sub(core.Exporter): def __init__(self): core.Exporter.__init__(self) self.Export(params=['Value']) self.Value = 0 root = core.Exporter() root.Sub = Sub root.SubList = {} root.Test = 'this is a test string' root.Export(params=['Test'], lists=['Sub']) loop.ListenInet(('', 12999), MakeRemoteCommandStreamer(root)) loop.ListenUnix('/tmp/cwmpd.sock', MakeRemoteCommandStreamer(root)) loop.Start()
def testObject(self): root = core.Exporter() root.Export(objects=['Test']) root.Test = TestObject() h = handle.Handle(root) h.ValidateExports() cpe = api.CPE(h) (idx, unused_status) = cpe.AddObject('Test.Thingy.', 0) name = 'Test.Thingy.%d' % int(idx) cpe.SetParameterValues([('%s.word' % name, 'word1')], 0) self.assertEqual(h.GetExport(name).word, 'word1') self.assertRaises(KeyError, cpe._SetParameterValue, '%s.not_exist' % name, 'word1') result = cpe.GetParameterValues(['%s.word' % name]) self.assertEqual(result, [('%s.word' % name, 'word1')]) self.assertEqual(changes, 1) self.assertRaises(api.SetParameterErrors, cpe.SetParameterValues, [('%s.word' % name, 'snorkleberry'), ('nonexist', 'broken')], 0) # word was not changed because nonexist didn't exist and we check for # existence first. self.assertEqual(result, [('%s.word' % name, 'word1')]) self.assertEqual(changes, 1) # word changed, but then changed back, because readonlyword has no # validator and it failed in the set phase. self.assertRaises(api.SetParameterErrors, cpe.SetParameterValues, [('%s.word' % name, 'snorkleberry'), ('%s.readonlyword' % name, 'broken')], 0) self.assertEqual(result, [('%s.word' % name, 'word1')]) self.assertEqual(changes, 3) # word changed, but then changed back. Strictly speaking we could have # aborted the set as soon as reasonlyword failed, but then the set of # error messages wouldn't be as thorough as possible, so we deliberately # choose to try all the sets if we get to the setting phase. self.assertRaises(api.SetParameterErrors, cpe.SetParameterValues, [('%s.readonlyword' % name, 'broken'), ('%s.word' % name, 'snorkleberry')], 0) self.assertEqual(result, [('%s.word' % name, 'word1')]) self.assertEqual(changes, 5) self.assertRaises(api.SetParameterErrors, cpe.SetParameterValues, [('%s.word' % name, 'snorkleberry'), ('%s.validatedword' % name, 'broken')], 0) self.assertEqual(result, [('%s.word' % name, 'word1')]) self.assertEqual(changes, 5) (objidx_list, status) = cpe.X_CATAWAMPUS_ORG_AddObjects( [('Test.Thingy.', 5), ('Test.Thingy.', 2)], 0) self.assertEqual(status, 0) self.assertEqual(len(objidx_list), 2) idxlist = objidx_list[0][1] + objidx_list[1][1] self.assertEqual(len(set(idxlist)), 7) result = cpe.GetParameterValues([('Test.Thingy.%d' % int(idx)) for idx in idxlist]) self.assertEqual([i.word for idx, i in result], [None] * 7)