Example #1
0
    def test_constructor_args(self):
        ref = 'foo'
        _type = 'host'
        name = 'bar'
        properties = {'red': 1, 'blue': 'foo', 'green': 1.0}
        sender = Sender(ref=ref, _type=_type, name=name, properties=properties)

        self.assertEqual(sender.ref, ref)
        self.assertEqual(sender.type, _type)
        self.assertEqual(sender.name, name)
        self.assertEqual(sender.properties, properties)
Example #2
0
    def test_to_json(self):
        ref = 'device'
        _type = 'blah'
        name = 'hello'
        properties = {'red': 1, 'blue': 'foo', 'green': 1.0}
        sender = Sender(ref=ref, _type=_type, name=name, properties=properties)

        output = json.dumps(sender,
                            sort_keys=True,
                            default=tspapi.source.serialize_instance)
        expected = '{"name": "hello", "properties": {"blue": "foo", "green": 1.0, "red": 1}, ' + \
                   '"ref": "device", "type": "blah"}'
        self.assertEqual(expected, output)
Example #3
0
 def test_default_constructor(self):
     sender = Sender()
     self.assertIsNone(sender.ref)
     self.assertIsNone(sender.type)
     self.assertIsNone(sender.name)
     self.assertIsNone(sender.properties)
Example #4
0
 def test_properties(self):
     properties = {'red': 1, 'blue': 'foo', 'green': 1.0}
     sender = Sender(properties=properties)
     self.assertEqual(1, properties['red'])
     self.assertEqual('foo', properties['blue'])
     self.assertEqual(1.0, properties['green'])
Example #5
0
 def test_name(self):
     name = 'hello'
     sender = Sender(name=name)
     self.assertEqual(sender.name, name)
Example #6
0
 def test_type(self):
     _type = 'blah'
     sender = Sender(_type=_type)
     self.assertEqual(sender.type, _type)
Example #7
0
 def test_ref(self):
     ref = 'bar'
     sender = Sender(ref=ref)
     self.assertEqual(sender.ref, ref)
Example #8
0
 def test_create_event_with_sender(self):
     source = Source(ref='localhost', _type='host', name='bubba')
     sender = Sender(ref='localhost', _type='host', name='bubba')
     self.api.event_create(title='Hello World', fingerprint_fields=['@title'], source=source, sender=sender)