def test_device_group_and_device(self): foreach = Input(_from= [{"device-group":"test"}, {"device":"test2"}], select=["name"]).build_foreach() correct_foreach = "/devices/device[name=/devices/device-group[name='test']/member or name='test2']" self.assertEqual(foreach, correct_foreach)
def test_Input_Builder_device_group_no_where(self): """Test to validate the input builder expressions are built properly for many selects.""" foreach = Input(_from= [{"device-group":"test"}], select=["name"]).build_foreach() #"devices/device[name=/devices/device-group[name='acc1-pl']/member] self.assertEqual(foreach, "/devices/device[name=/devices/device-group[name='test']/member]")
def test_Input_Builder_many_expressions(self): """Test to validate the input builder expressions are built properly for many selects.""" expressions = Input(_from= ["*"], select=["name", "address"], where=["name='test'", "port='22'"]).expressions self.assertEqual(expressions, [{'result-type': ['string'], 'expression': 'name', 'label': 'name'}, {'result-type': ['string'], 'expression': 'address', 'label': 'address'}])
def test_Input_Builder_many_filters(self): """Test to validate the input builder works wih many filters.""" foreach = Input(_from= ["*"], select=["name"], where=["name='test'", "port='22'"]).build_foreach() self.assertEqual(foreach, "/devices/device[name='test' and port='22' ]")
def test_Input_Builder_single_filter(self): """Test to validate the input builder works wih one filter.""" foreach = Input(_from= ["*"], select=["name"], where=["name='test'"]).build_foreach() self.assertEqual(foreach, "/devices/device[name='test' ]")
def test_Input_Builder_from_all(self): """Test to validate the _from = ['*'] functionality works.""" foreach = Input(_from= ["*"], select=["name"]).build_foreach() self.assertEqual(foreach, "/devices/device")