def test_get_base_url(): assert get_base_url("http://localhost:8094/wps") == "http://localhost:8094/wps" assert get_base_url("http://localhost:8094/wps?service=wps&request=getcapabilities") == \ "http://localhost:8094/wps" assert get_base_url("https://localhost:8094/wps?service=wps&request=getcapabilities") == \ "https://localhost:8094/wps" with pytest.raises(ValueError): get_base_url("ftp://localhost:8094/wps")
def save_service(self, service, overwrite=True): # type: (Service, bool) -> Service """ Stores an OWS service in mongodb. """ service_url = get_base_url(service.url) # check if service is already registered if self.collection.count_documents({"url": service_url}) > 0: if overwrite: self.collection.delete_one({"url": service_url}) else: raise ServiceRegistrationError("service url already registered.") service_name = get_sane_name(service.name, **self.sane_name_config) if self.collection.count_documents({"name": service_name}) > 0: if overwrite: self.collection.delete_one({"name": service_name}) else: raise ServiceRegistrationError("service name already registered.") self.collection.insert_one(Service( url=service_url, name=service_name, type=service.type, public=service.public, auth=service.auth).params()) return self.fetch_by_url(url=service_url)
def fetch_by_url(self, url): # type: (str) -> Service """ Gets service for given ``url`` from `MongoDB` storage. """ service = self.collection.find_one({"url": get_base_url(url)}) if not service: raise ServiceNotFound return Service(service)