class UpdatableGustosClientTest(SeecrTestCase):
    def setUp(self):
        SeecrTestCase.setUp(self)
        self.client = UpdatableGustosClient(identifier='identifier')
        self.port = PortNumberGenerator.next()
        self.listen = UdpListenAndLog(self.port)

    def tearDown(self):
        self.listen.stop()
        SeecrTestCase.tearDown(self)

    def testNothing(self):
        self.client.report(values=DATA)
        self.assertEqual([], self.listen.log())

    def testUpdateOnce(self):
        consume(
            self.client.updateConfig(
                config={'gustos': {
                    'host': 'localhost',
                    'port': self.port
                }},
                services='ignored'))
        self.client.report(values=DATA)
        sleep(0.1)
        log = self.listen.log()
        self.assertEqual(1, len(log))
        self.assertEqual(DATA, loads(log[0])['data'])
Exemplo n.º 2
0
    def testListenAndLog(self):
        port = PortNumberGenerator.next()
        ulal = UdpListenAndLog(port)
        
        s = socket(AF_INET, SOCK_DGRAM)
        s.sendto("THIS IS THE PAYLOAD", ('127.0.0.1', port))
        sleep(.5)

        self.assertEquals(['THIS IS THE PAYLOAD'], ulal.log())
Exemplo n.º 3
0
    def testListenAndLog(self):
        port = PortNumberGenerator.next()
        ulal = UdpListenAndLog(port)

        with socket(AF_INET, SOCK_DGRAM) as s:
            s.sendto(b"THIS IS THE PAYLOAD", ('127.0.0.1', port))
            sleep(.5)

        self.assertEqual([b'THIS IS THE PAYLOAD'], ulal.log())
        ulal.stop()
Exemplo n.º 4
0
    def testResetLog(self):
        port = PortNumberGenerator.next()
        ulal = UdpListenAndLog(port)
        
        socket(AF_INET, SOCK_DGRAM).sendto("THIS IS THE PAYLOAD", ('127.0.0.1', port))
        sleep(.5)

        self.assertEquals(1, len(ulal.log()))
        ulal.reset()
        self.assertEquals(0, len(ulal.log()))
        socket(AF_INET, SOCK_DGRAM).sendto("THIS IS THE PAYLOAD", ('127.0.0.1', port))
        sleep(.5)
        self.assertEquals(1, len(ulal.log()))
 def setUp(self):
     SeecrTestCase.setUp(self)
     self.client = UpdatableGustosClient(identifier='identifier')
     self.port = PortNumberGenerator.next()
     self.listen = UdpListenAndLog(self.port)
 def startGustosUdpListener(self):
     self.gustosUdpListener = UdpListenAndLog(self.gustosPort)