def test_queues_retry(self):
        self.station.set_real_terminate(True)
        self.station.set_real_id(True)
        self.station.set_real_register(True)
        self.assertFalse(self.station.station.has_ready_deferreds())

        self.assertEqual(len(self.station.station.deferreds), 0)
        handle_listallobjects(self.station)
        req1 = self.station.stream.pop(0)
        handle_terminate(req1)
        self.assertEqual(len(self.station.station.deferreds), 1)
    def test_follows_up_on_channels(self):
        self.station.set_real_terminate(True)
        self.station.set_real_id(True)
        self.station.set_real_register(True)
        handle_listallobjects(self.station)
        req1 = self.station.stream.pop(0)
        self.assertEqual(req1.verb, "LISTALLOBJECTS")

        while self.station.stream:
            resp = self.station.stream.pop(0)
            if resp.verb == "TERMINATE":
                break
            self.assertEqual(resp.verb, "DESCRIBEOBJECTS")


        self.assertEqual(len(self.station.stream), 0)
        resp.stream = self.station.stream
        handle_terminate(req1)

        req2 = self.station.stream.pop(0)
        self.assertEqual(req2.verb, "LISTALLCHANNELS")
    def test_handle_terminate(self):
        # Write an object into the station
        self.station.set_real_id(True)
        oid = self.station.station.write("butts lol")
        self.station.payload = oid

        self.assertEqual(len(self.station.station.registry.contents), 0)

        self.station.station.register_request(self.station)
        self.assertEqual(len(self.station.station.registry.contents), 1)

        handle_fetchobject(self.station)
        ret = [0]

        def _teardown():
            ret[0] += 1
        self.station.teardown = _teardown

        term = self.station.stream.pop()
        handle_terminate(term)

        self.assertEqual(len(self.station.station.registry.contents), 0)
        self.assertEqual(ret[0], 1)
    def test_handle_terminate(self):
        # Write an object into the station
        self.station.set_real_id(True)
        oid = self.station.station.write("butts lol")
        self.station.payload = oid

        self.assertEqual(len(self.station.station.registry.contents), 0)

        self.station.station.register_request(self.station)
        self.assertEqual(len(self.station.station.registry.contents), 1)

        handle_fetchobject(self.station)
        ret = [0]

        def _teardown():
            ret[0] += 1

        self.station.teardown = _teardown

        term = self.station.stream.pop()
        handle_terminate(term)

        self.assertEqual(len(self.station.station.registry.contents), 0)
        self.assertEqual(ret[0], 1)