def test_load_config_with_invalid_values(self):
        """ Tests if None is returned when config is not set properly """

        client = FusekiTriplestoreClient()
        fuseki_base_url, ds_name_default, ds_name_shacl, ds_name_harvest = client._get_fuseki_config(
        )

        self.assertIsNone(ds_name_harvest)
        self.assertIsNone(ds_name_shacl)
        self.assertIsNone(ds_name_default)
        self.assertIsNone(fuseki_base_url)
    def test_is_available_triplestore_request_exception(
            self, mock_requests_get):
        """ Tests if is_available() returns False if raises an exception while connecting triplestore. """

        mock_requests_get.return_value.status_code = requests.exceptions.ConnectionError(
            'test_error')

        client = FusekiTriplestoreClient()

        is_available_return = client.is_available()

        self.assertEquals(is_available_return, False)
    def test_create_dataset_successful_mqa(self, mock_requests_post,
                                           mock_fuseki_is_available):
        """ Tests create MQA is called with correct parameters """

        uri = "http://example.org/datasets/1"
        g = Graph()
        g.add((URIRef(uri), RDF.type, self.DCAT.Dataset))

        mock_requests_post.return_value.status_code = 200
        mock_fuseki_is_available.return_value = True

        client = FusekiTriplestoreClient()
        client.create_dataset_in_triplestore_mqa(g, uri)

        mock_requests_post.assert_called_once_with(
            '{}/data'.format(FUSEKI_SHACL_ENDPOINT_URL),
            data=g,
            headers=HEADERS)
    def test_get_endpoint_urls(self, mock_fuseki_available):
        """ Tests if endpoint URLs are built properly """

        mock_fuseki_available.return_value = False

        client = FusekiTriplestoreClient()

        self.assertEquals(client._get_update_endpoint(FUSEKI_BASE_DS_NAME),
                          '{}/update'.format(FUSEKI_ENDPOINT_URL))
        self.assertEquals(client._get_data_endpoint(FUSEKI_BASE_DS_NAME),
                          '{}/data'.format(FUSEKI_ENDPOINT_URL))
        self.assertEquals(client._get_query_endpoint(FUSEKI_BASE_DS_NAME),
                          '{}/query'.format(FUSEKI_ENDPOINT_URL))
        self.assertEquals(client._get_update_endpoint(FUSEKI_SHACL_DS_NAME),
                          '{}/update'.format(FUSEKI_SHACL_ENDPOINT_URL))
        self.assertEquals(client._get_data_endpoint(FUSEKI_SHACL_DS_NAME),
                          '{}/data'.format(FUSEKI_SHACL_ENDPOINT_URL))
        self.assertEquals(client._get_query_endpoint(FUSEKI_SHACL_DS_NAME),
                          '{}/query'.format(FUSEKI_SHACL_ENDPOINT_URL))
        self.assertEquals(client._get_ping_endpoint(),
                          '{}/$/ping'.format(FUSEKI_BASE_URL))