Example #1
0
 def setup (self):
     TestComponent.setup(self)
     self.slp = ServiceLocator()
Example #2
0
class TestServiceLocator (TestComponent):
    
    def setup (self):
        TestComponent.setup(self)
        self.slp = ServiceLocator()
    
    def test_register (self):
        for each in range(2):
            try:
                self.slp.register("foo_service", "http://localhost:5900")
            except:
                raise
                assert not "Wasn't able to register a service."
    
    def test_unregister (self):
        try:
            self.slp.unregister("foo_service")
        except:
            assert not "Wasn't able to unregister an unregistered service."
        self.slp.register("foo_service", "http://localhost:5900")
        try:
            self.slp.unregister("foo_service")
        except:
            assert not "Wasn't able to unregister."
        try:
            self.slp.unregister("foo_service")
        except:
            assert not "Wasn't able to unregister multiple times."
    
    def test_locate (self):
        location = self.slp.locate("foo_service")
        assert location == ""
        self.slp.register("foo_service", "http://localhost:5900")
        location = self.slp.locate("foo_service")
        assert location == "http://localhost:5900"
        self.slp.unregister("foo_service")
        location = self.slp.locate("foo_service")
        assert location == ""
    
    def test_get_services (self):
        services = self.slp.get_services([{'name':"foo_service"}])
        assert len(services) == 0
        self.slp.register("foo_service", "http://localhost:5900")
        services = self.slp.get_services([{'name':"foo_service"}])
        assert len(services) == 1
        assert services[0].name == "foo_service"
        services = self.slp.get_services([{'name':"*", 'location':"*"}])
        assert len(services) == 1
        assert services[0].name == "foo_service"
        assert services[0].location == "http://localhost:5900"