示例#1
0
    def register_service(self, url, name=None, service_type='wps', public=False, c4i=False, overwrite=True):
        """
        Adds OWS service with given name to registry database.
        """

        service_url = baseurl(url)
        # check if service is already registered
        if self.collection.count({'url': service_url}) > 0:
            if overwrite:
                self.collection.delete_one({'url': service_url})
            else:
                raise RegistrationException("service url already registered.")

        name = namesgenerator.get_sane_name(name)
        if not name:
            name = namesgenerator.get_random_name()
            if self.collection.count({'name': name}) > 0:
                name = namesgenerator.get_random_name(retry=True)
        if self.collection.count({'name': name}) > 0:
            if overwrite:
                self.collection.delete_one({'name': name})
            else:
                raise Exception("service name already registered.")
        service = dict(url=service_url, name=name, type=service_type, public=public, c4i=c4i)
        self.collection.insert_one(service)
        return service
def test_get_sane_name():
    assert get_sane_name("Hummingbird") == "hummingbird"
    assert get_sane_name("MapMint Demo Instance") == "mapmint_demo_instance"
    assert get_sane_name(None) == None
    assert get_sane_name("12") == None
    assert get_sane_name(" ab c ") == "ab_c"
    assert get_sane_name("a_much_to_long_name_for_this_test") == "a_much_to_long_name_for_t"