Exemplo n.º 1
0
 def test_send_event(self):
     # Note lack of filter!
     self.tr.clear()
     init_outstanding_ack = self.proto.outstanding_ack
     self.proto.send_event(DummyEvent())
     self.assertEqual(self.tr.value()[4:], DummyEvent().raw_bytes)
     self.assertEqual(self.proto.outstanding_ack - init_outstanding_ack, 1)
Exemplo n.º 2
0
 def test_send_xml(self):
     dummy_element = DummyEvent()
     self.proto.send_xml(dummy_element)
     self.assertEqual(
         self.tr.value(),
         struct.pack("!i", len(dummy_element.raw_bytes)) +
         dummy_element.raw_bytes)
Exemplo n.º 3
0
 def test_process_event_invalid_cant_nak(self):
     self.proto.factory.validators = [Fails()]
     self.proto.factory.handlers = [Succeeds()]
     d = self.proto.process_event(DummyEvent(), can_nak=False)
     d.addCallback(self._check_for_role, "ack")
     d.addCallback(self._check_for_handler_runs, False)
     return d
Exemplo n.º 4
0
 def test_process_event_valid_fails(self):
     self.proto.factory.validators = [Succeeds()]
     self.proto.factory.handlers = [Fails()]
     d = self.proto.process_event(DummyEvent())
     d.addCallback(self._check_for_role, "ack")
     d.addCallback(self._check_for_handler_runs, True)
     return d
Exemplo n.º 5
0
 def setUp(self):
     self.event = DummyEvent()
     self.factory = VOEventSenderFactory(self.event)
     self.proto = self.factory.buildProtocol(('127.0.0.1', 0))
     self.tr = proto_helpers.StringTransportWithDisconnection()
     self.proto.makeConnection(self.tr)
     self.tr.protocol = self.proto
Exemplo n.º 6
0
 def test_lengthLimitExceeded(self):
     self.assertEqual(self.tr.disconnecting, False)
     dummy_element = DummyEvent()
     self.proto.dataReceived(
         struct.pack("<i", len(dummy_element.raw_bytes)) +
         dummy_element.raw_bytes)
     self.assertEqual(self.tr.disconnecting, True)
Exemplo n.º 7
0
 def _check_logged_value(self, script_name, sentinel, should_fail=False):
     observer = DummyLogObserver()
     twisted_log.addObserver(observer)
     log.LEVEL = log.Levels.DEBUG
     spawn = SpawnCommand(SHELL, util.sibpath(__file__, script_name))
     def _check_log(_):
         self.assertTrue(sentinel in
                         " ".join(msg[0] for msg in observer.messages))
     d = spawn(DummyEvent())
     if should_fail:
         return self.assertFailure(d, Exception).addCallback(_check_log)
     else:
         d.addCallback(_check_log)
         return d
Exemplo n.º 8
0
 def test_write_data(self):
     """
     Demonstrate that an external command can save data.
     """
     output_file = tempfile.NamedTemporaryFile()
     dummy_event = DummyEvent()
     def read_data(result):
         try:
             # NamedTemporaryFile is opened in binary mode, so we compare
             # raw bytes.
             self.assertEqual(output_file.read(), dummy_event.raw_bytes)
         finally:
             output_file.close()
     spawn = SpawnCommand(SHELL, util.sibpath(__file__, "test_spawn_output.sh"), output_file.name)
     d = spawn(dummy_event)
     d.addCallback(read_data)
     return d
Exemplo n.º 9
0
    def test_prune_bad_event(self):
        bad_event = DummyEvent(ivoid=b"ivo://")
        self.assertNotIn("", self.event_db.databases)
        # This event doesn't validate and is rejected.
        self.assertFalse(self.event_db.check_event(bad_event))
        # The hostname shouldn't event be stored in our list of databases.
        self.assertNotIn("", self.event_db.databases)
        d = self.event_db.prune(0)

        def done_prune(result):
            # After pruning, everything in the database should be unlocked.
            for lock in self.event_db.databases.values():
                self.assertFalse(lock.locked())
            self.assertFalse(self.event_db.check_event(bad_event))
            self.assertTrue(self.event_db.check_event(self.event))
        d.addCallback(done_prune)
        return d
Exemplo n.º 10
0
    def test_send_event_with_filter_accept(self):
        def check_output(result):
            self.assertEqual(self.tr.value()[4:], DummyEvent().raw_bytes)

        init_outstanding_ack = self.proto.outstanding_ack

        def check_ack_increment(result):
            self.assertEqual(self.proto.outstanding_ack - init_outstanding_ack,
                             1)

        self.tr.clear()
        self.proto.filters.append(
            etree.XPath("/*[local-name()=\"VOEvent\" and @role=\"test\"]")
        )  # Will accept dummy event with role "test"
        d = self.proto.send_event(DummyEvent())
        d.addCallback(check_output)
        d.addCallback(check_ack_increment)
        return d
Exemplo n.º 11
0
 def test_good_parse(self):
     test_target = "test"
     self.config.parseOptions([test_target, self.event_filename])
     self.assertEqual(self.config['target'], test_target)
     self.assertEqual(self.config['event'].read(), DummyEvent().raw_bytes)
Exemplo n.º 12
0
 def setUp(self):
     self.config = Options()
     self.tempdir = TemporaryDirectory()
     self.event_filename = os.path.join(self.tempdir.name, "event.xml")
     with open(self.event_filename, "wb") as f:
         f.write(DummyEvent().raw_bytes)
Exemplo n.º 13
0
 def test_bad_ivoid(self):
     bad_event = DummyEvent(b"ivo://#")
     self.assertFalse(self.event_db.check_event(bad_event))
Exemplo n.º 14
0
 def setUp(self):
     self.event_db_dir = tempfile.mkdtemp()
     self.event_db = Event_DB(self.event_db_dir)
     self.event = DummyEvent()
Exemplo n.º 15
0
 def setUp(self):
     self.event = DummyEvent()
     self.factory = VOEventSenderFactory(self.event)
     self.proto = self.factory.buildProtocol(('127.0.0.1', 0))
Exemplo n.º 16
0
 def check_output(result):
     self.assertEqual(self.tr.value()[4:], DummyEvent().raw_bytes)
Exemplo n.º 17
0
 def test_no_exec(self):
     """
     Fail when the executable doesn't exist.
     """
     spawn = SpawnCommand("/not/a/real/executable")
     return self.assertFailure(spawn(DummyEvent()), Exception)
Exemplo n.º 18
0
 def test_good_process(self):
     spawn = SpawnCommand(EXECUTABLE)
     d = spawn(DummyEvent())
     d.addCallback(self.assertEqual, True)
     return d
Exemplo n.º 19
0
 def setUp(self):
     self.event_db_dir = tempfile.mkdtemp()
     self.checker = CheckPreviouslySeen(Event_DB(self.event_db_dir))
     self.event = DummyEvent()