Ejemplo n.º 1
0
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, []))
Ejemplo n.º 2
0
  def testNonexistent(self):
    root = TestObject()
    cpe = api.CPE(handle.Handle(root))

    cpe.parameter_attrs.set_notification_parameters_cb = SetNotification
    cpe.parameter_attrs.new_value_change_session_cb = NewSession

    f = FakeAttrs()
    f.Name = 'AutoThingy.3'
    f.Notification = 2
    f.NotificationChange = 'true'
    cpe.SetParameterAttributes(f)
    self.assertEqual(len(cpe.parameter_attrs.params), 1)
    root.NumAutoThingies = 1

    # Check that this doesn't raise an exception
    cpe.parameter_attrs.CheckForTriggers()
    self.assertEqual(0, len(set_notification_arg[0]))

    root.NumAutoThingies = 5
    self.assertEqual(0, len(set_notification_arg[0]))

    root.AutoThingyList['3'].word = 'word1'
    cpe.parameter_attrs.CheckForTriggers()
    self.assertEqual(1, len(set_notification_arg[0]))
Ejemplo n.º 3
0
  def testSetAttr(self):
    root = TestSimpleRoot()
    cpe = api.CPE(handle.Handle(root))
    f = FakeAttrs()
    f.Name = 'SomeParam'
    f.Notification = 2
    cpe.SetParameterAttributes(f)
    self.assertEqual(len(cpe.parameter_attrs.params), 1)
    self.assertEqual(cpe.parameter_attrs.params['SomeParam'].notification, 0)

    f.Name = 'SomeParam'
    f.Notification = 2
    f.NotificationChange = 'true'
    cpe.SetParameterAttributes(f)
    self.assertEqual(len(cpe.parameter_attrs.params), 1)
    self.assertEqual(2, cpe.parameter_attrs.params['SomeParam'].notification)

    cpe.parameter_attrs.set_notification_parameters_cb = SetNotification
    cpe.parameter_attrs.new_value_change_session_cb = NewSession

    # The value hasn't changed, so this shouldn't do anything.
    cpe.parameter_attrs.CheckForTriggers()
    self.assertEqual(0, len(set_notification_arg[0]))
    self.assertEqual(0, new_session_called[0])

    # Change the value and make sure a new session is triggered.
    root.SomeParam = 'NewValue'
    cpe.parameter_attrs.CheckForTriggers()
    self.assertEqual(1, len(set_notification_arg[0]))
    self.assertEqual('SomeParam', set_notification_arg[0][0][0])
    self.assertEqual(root.SomeParam, set_notification_arg[0][0][1])
    self.assertEqual(1, new_session_called[0])
Ejemplo n.º 4
0
 def getCpe(self):
   root = TestDeviceModelRoot()
   cpe = api.CPE(root)
   cpe_machine = http.Listen(ip=None, port=0,
                             ping_path='/ping/acs_integration_test',
                             acs=None, cpe=cpe, cpe_listener=False,
                             platform_config=FakePlatformConfig())
   return cpe_machine
Ejemplo n.º 5
0
 def testDeleteParam(self):
   root = TestObject()
   cpe = api.CPE(handle.Handle(root))
   (unused_idx, unused_obj) = cpe.AddObject('Thingy.', '1')
   f = FakeAttrs()
   f.Name = 'Thingy.1'
   f.Notification = 2
   cpe.SetParameterAttributes(f)
   self.assertEqual(len(cpe.parameter_attrs.params), 1)
   cpe.DeleteObject('Thingy.1.', 'fake-key')
   self.assertEqual(len(cpe.parameter_attrs.params), 0)
Ejemplo n.º 6
0
 def getCpe(self):
   dm_root.PLATFORMDIR = '../platform'
   root = dm_root.DeviceModelRoot(self.io_loop, 'fakecpe')
   cpe = api.CPE(root)
   dldir = tempfile.mkdtemp()
   self.removedirs.append(dldir)
   cfdir = tempfile.mkdtemp()
   self.removedirs.append(cfdir)
   cpe.download_manager.SetDirectories(config_dir=cfdir, download_dir=dldir)
   cpe_machine = http.Listen(ip=None, port=0,
                             ping_path='/ping/http_test',
                             acs=None, cpe=cpe, cpe_listener=False,
                             platform_config=MockPlatformConfig(),
                             ioloop=self.io_loop)
   return cpe_machine
Ejemplo n.º 7
0
 def testSetAttrErrors(self):
   root = TestSimpleRoot()
   cpe = api.CPE(handle.Handle(root))
   error_list = []
   cpe._Apply(error_list, 'fullname', api.ParameterNotWritableError,
              RaiseAttributeError, [])
   cpe._Apply(error_list, 'fullname', None, RaiseTypeError, [])
   cpe._Apply(error_list, 'fullname', None, RaiseValueError, [])
   cpe._Apply(error_list, 'fullname', None, RaiseKeyError, [])
   cpe._Apply(error_list, 'fullname', None, RaiseIOError, [])
   self.assertEqual(5, len(error_list))
   self.assertEqual(api.ParameterNotWritableError, type(error_list[0]))
   self.assertEqual(api.ParameterTypeError, type(error_list[1]))
   self.assertEqual(api.ParameterValueError, type(error_list[2]))
   self.assertEqual(api.ParameterNameError, type(error_list[3]))
   self.assertEqual(api.ParameterInternalError, type(error_list[4]))
Ejemplo n.º 8
0
 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')])
Ejemplo n.º 9
0
 def testGetParameterValuesEmpty(self):
   cpe = api.CPE(handle.Handle(TestSimpleRoot()))
   result = cpe.GetParameterValues([''])
   self.assertTrue(result)
   self.assertEqual(result[0], ('SomeParam', 'SomeParamValue'))
Ejemplo n.º 10
0
  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)