Skip to content

Commit

Permalink
chore: get rid of dead code (#751)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Jan 22, 2024
1 parent 2c0febb commit f67eac2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 126 deletions.
7 changes: 0 additions & 7 deletions src/dsp_tools/commands/project/models/ontology.py
Expand Up @@ -306,13 +306,6 @@ def read(self) -> "Ontology":
result = self._con.get(Ontology.ROUTE + "/allentities/" + quote_plus(self._iri) + Ontology.ALL_LANGUAGES)
return Ontology.fromJsonObj(self._con, result)

def delete(self) -> Optional[str]:
result = self._con.delete(
Ontology.ROUTE + "/" + quote_plus(self._iri),
params={"lastModificationDate": str(self._lastModificationDate)},
)
return result.get("knora-api:result")

@staticmethod
def getAllOntologies(con: Connection) -> list["Ontology"]:
result = con.get(Ontology.ROUTE + Ontology.METADATA)
Expand Down
2 changes: 0 additions & 2 deletions src/dsp_tools/utils/connection.py
Expand Up @@ -62,15 +62,13 @@ def post(
def delete(
self,
route: str,
params: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
) -> dict[str, Any]:
"""
Make a HTTP GET request to the server to which this connection has been established.
Args:
route: route that will be called on the server
params: additional parameters for the HTTP request
headers: headers for the HTTP request
"""

Expand Down
9 changes: 0 additions & 9 deletions src/dsp_tools/utils/connection_live.py
Expand Up @@ -125,7 +125,6 @@ def post(
url=url,
data=data,
uploaded_file=files["file"][0] if files else None,
params=None,
headers=headers,
timeout=timeout,
)
Expand Down Expand Up @@ -167,7 +166,6 @@ def get(
method="GET",
url=url,
data=None,
params=None,
headers=headers,
timeout=timeout,
)
Expand Down Expand Up @@ -213,7 +211,6 @@ def put(
method="PUT",
url=url,
data=data,
params=None,
headers=headers,
timeout=timeout,
)
Expand All @@ -230,15 +227,13 @@ def put(
def delete(
self,
route: str,
params: Optional[dict[str, Any]] = None,
headers: dict[str, str] | None = None,
) -> dict[str, Any]:
"""
Make a HTTP GET request to the server to which this connection has been established.
Args:
route: route that will be called on the server
params: additional parameters for the HTTP request
headers: headers for the HTTP request
Returns:
Expand All @@ -256,14 +251,12 @@ def delete(
method="DELETE",
url=url,
data=None,
params=params,
headers=headers,
timeout=timeout,
)
response = self.session.delete(
url=url,
headers=headers,
params=params,
timeout=timeout,
)
return cast(dict[str, Any], response.json())
Expand Down Expand Up @@ -366,7 +359,6 @@ def _log_request(
method: str,
url: str,
data: dict[str, Any] | None,
params: Optional[dict[str, Any]],
timeout: int,
headers: dict[str, str] | None = None,
uploaded_file: str | None = None,
Expand All @@ -379,7 +371,6 @@ def _log_request(
"HTTP request": method,
"url": url,
"headers": headers,
"params": params,
"timetout": timeout,
"payload": data,
"uploaded file": uploaded_file,
Expand Down
150 changes: 43 additions & 107 deletions test/e2e/commands/project/test_propertyclass.py
@@ -1,118 +1,54 @@
"""end to end tests for property class"""

import unittest

import pytest

from dsp_tools.commands.project.models.ontology import Ontology
from dsp_tools.commands.project.models.propertyclass import PropertyClass
from dsp_tools.models.helpers import DateTimeStamp
from dsp_tools.models.langstring import LangString, Languages
from dsp_tools.utils.connection import Connection
from dsp_tools.utils.connection_live import ConnectionLive

# ruff: noqa: PT009 (pytest-unittest-assertion) (remove this line when pytest is used instead of unittest)


class TestPropertyClass(unittest.TestCase):
project = "http://rdfh.ch/projects/0001"
onto_name = "propclass-test-a"
onto_label = "propclass_test_ontology"

onto: Ontology
last_modification_date: DateTimeStamp
con: Connection

name = "MyPropClassName"
rdf_object = "TextValue"
label = LangString({Languages.DE: "MyPropClassLabel"})
comment = LangString({Languages.DE: "This is a property class for testing"})

def setUp(self) -> None:
"""
Creates a connection and a new ontology.
For each test method, a new TestCase instance is created, so setUp() is executed before each test method.
"""
self.con = ConnectionLive(server="http://0.0.0.0:3333")
self.con.login(email="root@example.com", password="test")

# Create a test ontology
self.onto = Ontology(
con=self.con,
project=self.project,
name=self.onto_name,
label=self.onto_label,
).create()

self.assertIsNotNone(self.onto.iri)
self.last_modification_date = self.onto.lastModificationDate

def tearDown(self) -> None:
"""
Logs out from DSP-API and remove test ontology.
For each test method, a new TestCase instance is created, so tearDown() is executed after each test method.
"""
result = self.onto.delete()
self.assertIsNotNone(result)
self.con.logout()

def test_PropertyClass_create(self) -> None:
"""
create new property class
"""
self.last_modification_date, property_class = PropertyClass(
con=self.con,
context=self.onto.context,
name=self.name,
ontology_id=self.onto.iri,
rdf_object=self.rdf_object,
label=self.label,
comment=self.comment,
).create(self.last_modification_date)

self.onto.lastModificationDate = self.last_modification_date

self.assertIsNotNone(property_class.iri)
self.assertEqual(property_class.name, self.name)
self.assertEqual(property_class.label["de"], self.label["de"])
self.assertEqual(property_class.comment["de"], self.comment["de"])

# get ontology data
self.onto = self.onto.read()
self.last_modification_date = self.onto.lastModificationDate
self.last_modification_date = property_class.delete(self.last_modification_date)

# get ontology data
self.onto = self.onto.read()

def test_PropertyClass_update(self) -> None:
self.onto = self.onto.read()

# create test resource class
self.last_modification_date, property_class = PropertyClass(
con=self.con,
context=self.onto.context,
name=self.name,
ontology_id=self.onto.iri,
rdf_object=self.rdf_object,
label=self.label,
comment=self.comment,
).create(self.last_modification_date)
self.onto.lastModificationDate = self.last_modification_date
self.assertIsNotNone(property_class.iri)

# modify the property class
property_class.addLabel("en", "This is english comment")
property_class.rmLabel("de")
property_class.addComment("it", "Commentario italiano")
self.last_modification_date, property_class_updated = property_class.update(self.last_modification_date)
self.onto.lastModificationDate = self.last_modification_date
self.assertEqual(property_class_updated.label["en"], "This is english comment")
self.assertEqual(property_class_updated.comment["it"], "Commentario italiano")

# delete the resource class to clean up
self.last_modification_date = property_class_updated.delete(self.last_modification_date)
self.onto.lastModificationDate = self.last_modification_date
def test_PropertyClass_create() -> None:
con = ConnectionLive(server="http://0.0.0.0:3333")
con.login(email="root@example.com", password="test")

# Create a test ontology
onto = Ontology(
con=con,
project="http://rdfh.ch/projects/0001",
name="onto-1",
label="onto-label",
).create()
assert onto.iri is not None
last_modification_date = onto.lastModificationDate

# create new property class
prop_name = "MyPropClassName"
prop_label = LangString({Languages.DE: "MyPropClassLabel"})
prop_comment = LangString({Languages.DE: "This is a property class for testing"})
last_modification_date, property_class = PropertyClass(
con=con,
context=onto.context,
name=prop_name,
ontology_id=onto.iri,
rdf_object="TextValue",
label=prop_label,
comment=prop_comment,
).create(last_modification_date)

assert property_class.iri is not None
assert property_class.name == prop_name
assert property_class.label["de"] == prop_label["de"]
assert property_class.comment["de"] == prop_comment["de"]

# modify the property class
property_class.addLabel("en", "This is english comment")
property_class.rmLabel("de")
property_class.addComment("it", "Commentario italiano")
last_modification_date, property_class_updated = property_class.update(last_modification_date)
assert property_class_updated.label["en"] == "This is english comment"
property_class_updated.comment["it"] == "Commentario italiano"

# delete the property class to clean up
_ = property_class_updated.delete(last_modification_date)


if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion test/unittests/commands/xmlupload/connection_mock.py
Expand Up @@ -35,7 +35,6 @@ def post(
def delete(
self,
route: str,
params: dict[str, Any] | None = None,
headers: dict[str, str] | None = None,
) -> dict[str, Any]:
raise AssertionError("DELETE not implemented in mock")
Expand Down

0 comments on commit f67eac2

Please sign in to comment.