Repository: HTTP-APIs/hydrus
Pull request #253 (2018-07-26 07:41:30)

Update requirements.txt
<!-- Please create/claim an issue before sending a PR -->
<!-- Add issue number (Eg: fixes #123) -->

Fixes #

### Checklist
- [ ] My branch is up-to-date with upstream/develop branch.
- [ ] Everything works and tested for Python 3.5.2 and above.

### Description
<!-- Describe about what this PR does, previous state and new state of the output -->

### Test Logs
<!-- Please submit test logs to confirm everything is working. -->

### Changes log

#### Added
<!-- Edit these points below to describe the new features added with this PR -->
- Feature 1
- Feature 2

#### Changed
<!-- Edit these points below to describe the changes made in existing functionality with this PR -->
- Change 1
- Change 2

#### Fixed
<!-- Edit these points below to describe the bug fixes made with this PR -->
- Bug 1

#### Removed
<!-- Edit these points below to describe the removed features with this PR -->
- Deprecated feature 1


Patch:
diff --git a/hydrus/app.py b/hydrus/app.py
index f22f2d6..55dce86 100644
--- a/hydrus/app.py
+++ b/hydrus/app.py
@@ -236,7 +236,7 @@ class Entrypoint(Resource):
 class Item(Resource):
     """Handles all operations(GET, POST, PATCH, DELETE) on Items (item can be anything depending upon the vocabulary)."""
 
-    def get(self, id_: str, path: str) -> Response:
+    def get(self, id_: int, path: str) -> Response:
         """
         GET object with id = id_ from the database.
 
@@ -268,7 +268,7 @@ class Item(Resource):
                     jsonify(message), status_code=status_code)
         abort(405)
 
-    def post(self, id_: str, path: str) -> Response:
+    def post(self, id_: int, path: str) -> Response:
         """Update object of type<path> at ID<id_> with new object_ using HTTP POST.
 
         :param id_ - ID of Item to be updated
@@ -314,7 +314,7 @@ class Item(Resource):
 
         abort(405)
 
-    def put(self, id_: str, path: str) -> Response:
+    def put(self, id_: int, path: str) -> Response:
         """Add new object_ optional <id_> parameter using HTTP PUT.
 
         :param id_ - ID of Item to be updated
@@ -353,7 +353,7 @@ class Item(Resource):
 
         abort(405)
 
-    def delete(self, id_: str, path: str) -> Response:
+    def delete(self, id_: int, path: str) -> Response:
         """Delete object with id=id_ from database."""
         auth_response = check_authentication_response()
         if isinstance(auth_response, Response):
@@ -678,8 +678,6 @@ class Contexts(Resource):
 
 def app_factory(API_NAME: str="api") -> Flask:
     """Create an app object."""
-
-
     app = Flask(__name__)
     app.config['SECRET_KEY'] = 'secret key'
     CORS(app)
@@ -695,7 +693,7 @@ def app_factory(API_NAME: str="api") -> Flask:
     api.add_resource(ItemCollection, "/" + API_NAME +
                      "/<string:path>", endpoint="item_collection")
     api.add_resource(Item, "/" + API_NAME +
-                     "/<string:path>/<uuid:id_>", endpoint="item")
+                     "/<string:path>/<int:id_>", endpoint="item")
     api.add_resource(Items, "/" + API_NAME +
                      "/<string:path>/add/<int_list>", "/" + API_NAME +
                      "/<string:path>/add", "/" + API_NAME +
diff --git a/hydrus/data/crud.py b/hydrus/data/crud.py
index fbe3654..f71f425 100644
--- a/hydrus/data/crud.py
+++ b/hydrus/data/crud.py
@@ -52,7 +52,7 @@ triples = with_polymorphic(Graph, '*')
 properties = with_polymorphic(BaseProperty, "*")
 
 
-def get(id_: str, type_: str, api_name: str, session: scoped_session,
+def get(id_: int, type_: str, api_name: str, session: scoped_session,
         recursive: bool = False, path: str=None) -> Dict[str, str]:
     """Retrieve an Instance with given ID from the database [GET].
     :param id_: id of object to be fetched
@@ -130,7 +130,7 @@ def get(id_: str, type_: str, api_name: str, session: scoped_session,
 
 
 def insert(object_: Dict[str, Any], session: scoped_session,
-           id_: Optional[str] =None) -> str:
+           id_: Optional[int] =None) -> int:
     """Insert an object to database [POST] and returns the inserted object.
     :param object_: object to be inserted
     :param session: sqlalchemy scoped session
@@ -344,7 +344,7 @@ def insert_multiple(objects_: List[Dict[str,
 
 
 
-def delete(id_: str, type_: str, session: scoped_session) -> None:
+def delete(id_: int, type_: str, session: scoped_session) -> None:
     """Delete an Instance and all its relations from DB given id [DELETE].
     :param id_: id of object to be deleted
     :param type_: type of object to be deleted
@@ -446,13 +446,13 @@ def delete_multiple(
     session.commit()
 
 
-def update(id_: str,
+def update(id_: int,
            type_: str,
            object_: Dict[str,
                          str],
            session: scoped_session,
            api_name: str,
-           path: str=None) -> str:
+           path: str=None) -> int:
     """Update an object properties based on the given object [PUT].
     :param id_: if of object to be updated
     :param type_: type of object to be updated
diff --git a/hydrus/data/db_models.py b/hydrus/data/db_models.py
index c341e8f..a461ee4 100644
--- a/hydrus/data/db_models.py
+++ b/hydrus/data/db_models.py
@@ -4,7 +4,6 @@ from sqlalchemy import create_engine, ForeignKey
 from sqlalchemy.ext.declarative import declarative_base
 from sqlalchemy import Column, Integer, String, DateTime
 from typing import Any
-import uuid
 # from hydrus.settings import DB_URL
 
 engine = create_engine('sqlite:///database.db')
@@ -19,12 +18,7 @@ class RDFClass(Base):
 
     __tablename__ = "classes"
 
-    id = Column(
-        String,
-        default=lambda: str(
-            uuid.uuid4()),
-        unique=True,
-        primary_key=True)
+    id = Column(Integer, primary_key=True)
     name = Column(String, unique=True)
 
     def __repr__(self) -> str:
@@ -39,13 +33,8 @@ class Instance(Base):
 
     __tablename__ = "instances"
 
-    id = Column(
-        String,
-        default=lambda: str(
-            uuid.uuid4()),
-        unique=True,
-        primary_key=True)
-    type_ = Column(String, ForeignKey("classes.id"), nullable=True)
+    id = Column(Integer, primary_key=True)
+    type_ = Column(Integer, ForeignKey("classes.id"), nullable=True)
 
 
 class BaseProperty(Base):
@@ -53,12 +42,7 @@ class BaseProperty(Base):
 
     __tablename__ = "property"
 
-    id = Column(
-        String,
-        default=lambda: str(
-            uuid.uuid4()),
-        unique=True,
-        primary_key=True)
+    id = Column(Integer, primary_key=True)
     name = Column(String, unique=True, nullable=False)
     type_ = Column(String)
 
@@ -81,8 +65,7 @@ class InstanceProperty(BaseProperty):
 
     def __repr__(self) -> str:
         """Verbose object name."""
-        return "<id='%s', name='%s', type='%s'>" % (
-            self.id, self.name, self.type_)
+        return "<id='%s', name='%s', type='%s'>" % (self.id, self.name, self.type_)
 
 
 class AbstractProperty(BaseProperty):
@@ -100,8 +83,7 @@ class AbstractProperty(BaseProperty):
 
     def __repr__(self) -> str:
         """Verbose object name."""
-        return "<id='%s', name='%s', type='%s'>" % (
-            self.id, self.name, self.type_)
+        return "<id='%s', name='%s', type='%s'>" % (self.id, self.name, self.type_)
 
 
 class Terminal(Base):
@@ -114,19 +96,13 @@ class Terminal(Base):
 
     __tablename__ = "terminals"
 
-    id = Column(
-        String,
-        default=lambda: str(
-            uuid.uuid4()),
-        unique=True,
-        primary_key=True)
+    id = Column(Integer, primary_key=True)
     value = Column(String)
     unit = Column(String)
 
     def __repr__(self) -> str:
         """Verbose object name."""
-        return "<id='%s', value='%s', unit='%s'>" % (
-            self.id, self.value, self.unit)
+        return "<id='%s', value='%s', unit='%s'>" % (self.id, self.value, self.unit)
 
 
 class Graph(Base):
@@ -134,12 +110,7 @@ class Graph(Base):
 
     __tablename__ = "graph"
 
-    id = Column(
-        String,
-        default=lambda: str(
-            uuid.uuid4()),
-        unique=True,
-        primary_key=True)
+    id = Column(Integer, primary_key=True)
     type = Column(String)
 
     __mapper_args__ = {
@@ -152,10 +123,10 @@ class GraphCAC(Graph):
     """Graph model for Class >> AbstractProperty >> Class."""
 
     __tablename__ = 'graphcac'
-    id = Column(String, ForeignKey('graph.id'), primary_key=True)
-    subject = Column(String, ForeignKey("classes.id"))
-    predicate = Column(String, ForeignKey("property.id"))
-    object_ = Column(String, ForeignKey("classes.id"))
+    id = Column(Integer, ForeignKey('graph.id'), primary_key=True)
+    subject = Column(Integer, ForeignKey("classes.id"))
+    predicate = Column(Integer, ForeignKey("property.id"))
+    object_ = Column(Integer, ForeignKey("classes.id"))
 
     __mapper_args__ = {
         'polymorphic_identity': 'graphcac',
@@ -163,19 +134,17 @@ class GraphCAC(Graph):
 
     def __repr__(self) -> str:
         """Verbose object name."""
-        return "<subject='%s', predicate='%s', object_='%s'>" % (
-            self.subject, self.predicate, self.object_)
+        return "<subject='%s', predicate='%s', object_='%s'>" % (self.subject, self.predicate, self.object_)
 
 
 class GraphIAC(Graph):
     """Graph model for Instance >> AbstractProperty >> Class."""
 
     __tablename__ = 'graphiac'
-    id = Column(String, ForeignKey('graph.id'), primary_key=True,default=lambda: str(
-            uuid.uuid4()))
-    subject = Column(String, ForeignKey("instances.id"))
-    predicate = Column(String, ForeignKey("property.id"))
-    object_ = Column(String, ForeignKey("classes.id"))
+    id = Column(Integer, ForeignKey('graph.id'), primary_key=True)
+    subject = Column(Integer, ForeignKey("instances.id"))
+    predicate = Column(Integer, ForeignKey("property.id"))
+    object_ = Column(Integer, ForeignKey("classes.id"))
 
     __mapper_args__ = {
         'polymorphic_identity': 'graphiac',
@@ -183,19 +152,17 @@ class GraphIAC(Graph):
 
     def __repr__(self) -> str:
         """Verbose object name."""
-        return "<subject='%s', predicate='%s', object_='%s'>" % (
-            self.subject, self.predicate, self.object_)
+        return "<subject='%s', predicate='%s', object_='%s'>" % (self.subject, self.predicate, self.object_)
 
 
 class GraphIII(Graph):
     """Graph model for Instance >> InstanceProperty >> Instance."""
 
     __tablename__ = 'graphiii'
-    id = Column(String, ForeignKey('graph.id'), primary_key=True,default=lambda: str(
-            uuid.uuid4()))
-    subject = Column(String, ForeignKey("instances.id"))
-    predicate = Column(String, ForeignKey("property.id"))
-    object_ = Column(String, ForeignKey("instances.id"))
+    id = Column(Integer, ForeignKey('graph.id'), primary_key=True)
+    subject = Column(Integer, ForeignKey("instances.id"))
+    predicate = Column(Integer, ForeignKey("property.id"))
+    object_ = Column(Integer, ForeignKey("instances.id"))
 
     __mapper_args__ = {
         'polymorphic_identity': 'graphiii',
@@ -203,19 +170,17 @@ class GraphIII(Graph):
 
     def __repr__(self) -> str:
         """Verbose object name."""
-        return "<subject='%s', predicate='%s', object_='%s'>" % (
-            self.subject, self.predicate, self.object_)
+        return "<subject='%s', predicate='%s', object_='%s'>" % (self.subject, self.predicate, self.object_)
 
 
 class GraphIIT(Graph):
     """Graph model for Instance >> InstanceProperty >> Terminal."""
 
     __tablename__ = 'graphiit'
-    id = Column(String, ForeignKey('graph.id'), primary_key=True,default=lambda: str(
-            uuid.uuid4()))
-    subject = Column(String, ForeignKey("instances.id"))
-    predicate = Column(String, ForeignKey("property.id"))
-    object_ = Column(String, ForeignKey("terminals.id"))
+    id = Column(Integer, ForeignKey('graph.id'), primary_key=True)
+    subject = Column(Integer, ForeignKey("instances.id"))
+    predicate = Column(Integer, ForeignKey("property.id"))
+    object_ = Column(Integer, ForeignKey("terminals.id"))
 
     __mapper_args__ = {
         'polymorphic_identity': 'graphiit',
@@ -223,8 +188,7 @@ class GraphIIT(Graph):
 
     def __repr__(self) -> str:
         """Verbose object name."""
-        return "<subject='%s', predicate='%s', object_='%s'>" % (
-            self.subject, self.predicate, self.object_)
+        return "<subject='%s', predicate='%s', object_='%s'>" % (self.subject, self.predicate, self.object_)
 
 
 class User(Base):
diff --git a/hydrus/data/exceptions.py b/hydrus/data/exceptions.py
index 7d6f7a6..0e94bd9 100644
--- a/hydrus/data/exceptions.py
+++ b/hydrus/data/exceptions.py
@@ -17,7 +17,7 @@ class ClassNotFound(Exception):
 class InstanceNotFound(Exception):
     """Error when the Instance is not found."""
 
-    def __init__(self, type_: str, id_: Union[str, None] =None) -> None:
+    def __init__(self, type_: str, id_: Union[int, None] =None) -> None:
         """Constructor."""
         self.type_ = type_
         self.id_ = id_
@@ -45,7 +45,7 @@ class PropertyNotFound(Exception):
 class InstanceExists(Exception):
     """Error when the Instance already exists."""
 
-    def __init__(self, type_: str, id_: Union[str, None]=None) -> None:
+    def __init__(self, type_: str, id_: Union[int, None]=None) -> None:
         """Constructor."""
         self.type_ = type_
         self.id_ = id_
diff --git a/requirements.txt b/requirements.txt
index e0594e3..78cbb22 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,26 +1,24 @@
-Flask==1.0.2
-Flask-RESTful==0.3.6
-Jinja2==2.10
-MarkupSafe==1.0
-SQLAlchemy==1.1.10
-Werkzeug==0.14.1
-aniso8601==1.2.1
+aniso8601==3.0.2
 appdirs==1.4.3
-argparse==1.2.1
+blinker==1.4
+certifi==2018.4.16
 click==6.7
+Flask==1.0.2
+Flask-Cors==3.0.6
+Flask-RESTful==0.3.6
+gevent==1.3.5
+greenlet==0.4.14
 itsdangerous==0.24
+Jinja2==2.10
 lifter==0.4.1
-packaging==16.8
+MarkupSafe==1.0
+packaging==17.1
 persisting-theory==0.2.1
-psycopg2
+psycopg2==2.7.5
 pyparsing==2.2.0
-python-dateutil==2.6.0
-pytz==2017.2
-six==1.10.0
-thespian==3.5.2
-flask-cors
-blinker==1.4
-typing==3.6.4
-gevent==1.2.2
-mypy
-pyyaml
+python-dateutil==2.7.3
+pytz==2018.5
+six==1.11.0
+SQLAlchemy==1.2.10
+thespian==3.9.2
+Werkzeug==0.14.1


Test patch:
diff --git a/hydrus/tests/test_crud.py b/hydrus/tests/test_crud.py
index ba6e90b..ef61624 100644
--- a/hydrus/tests/test_crud.py
+++ b/hydrus/tests/test_crud.py
@@ -57,24 +57,24 @@ class TestCRUD(unittest.TestCase):
     def test_insert(self):
         """Test CRUD insert."""
         object_ = gen_dummy_object("dummyClass", self.doc)
-        response = crud.insert(object_=object_, id_="1", session=self.session)
-        assert isinstance(response, str)
+        response = crud.insert(object_=object_, id_=1, session=self.session)
+        assert isinstance(response, int)
 
     def test_get(self):
         """Test CRUD get."""
         object_ = gen_dummy_object("dummyClass", self.doc)
-        id_ = "2"
+        id_ = 2
         response = crud.insert(object_=object_, id_=id_, session=self.session)
         object_ = crud.get(id_=id_, type_=object_[
                            "@type"], session=self.session, api_name="api")
-        assert isinstance(response, str)
-        assert object_["@id"].split("/")[-1] == id_
+        assert isinstance(response, int)
+        assert int(object_["@id"].split("/")[-1]) == id_
 
     def test_update(self):
         """Test CRUD update."""
         object_ = gen_dummy_object("dummyClass", self.doc)
         new_object = gen_dummy_object("dummyClass", self.doc)
-        id_ = "30"
+        id_ = 30
         insert_response = crud.insert(
             object_=object_, id_=id_, session=self.session)
         update_response = crud.update(
@@ -85,20 +85,20 @@ class TestCRUD(unittest.TestCase):
             api_name="api")
         test_object = crud.get(id_=id_, type_=object_[
                                "@type"], session=self.session, api_name="api")
-        assert isinstance(insert_response, str)
-        assert isinstance(update_response, str)
+        assert isinstance(insert_response, int)
+        assert isinstance(update_response, int)
         assert insert_response == update_response
-        assert test_object["@id"].split("/")[-1] == id_
+        assert int(test_object["@id"].split("/")[-1]) == id_
 
     def test_delete(self):
         """Test CRUD delete."""
         object_ = gen_dummy_object("dummyClass", self.doc)
-        id_ = "4"
+        id_ = 4
         insert_response = crud.insert(
             object_=object_, id_=id_, session=self.session)
         delete_response = crud.delete(
             id_=id_, type_=object_["@type"], session=self.session)
-        assert isinstance(insert_response, str)
+        assert isinstance(insert_response, int)
         response_code = None
         try:
             get_response = crud.get(
@@ -112,7 +112,7 @@ class TestCRUD(unittest.TestCase):
 
     def test_get_id(self):
         """Test CRUD get when wrong/undefined ID is given."""
-        id_ = "999"
+        id_ = 999
         type_ = "dummyClass"
         response_code = None
         try:
@@ -124,7 +124,7 @@ class TestCRUD(unittest.TestCase):
 
     def test_get_type(self):
         """Test CRUD get when wrong/undefined class is given."""
-        id_ = "1"
+        id_ = 1
         type_ = "otherClass"
         response_code = None
         try:
@@ -137,10 +137,10 @@ class TestCRUD(unittest.TestCase):
     def test_delete_type(self):
         """Test CRUD delete when wrong/undefined class is given."""
         object_ = gen_dummy_object("dummyClass", self.doc)
-        id_ = "50"
+        id_ = 50
         insert_response = crud.insert(
             object_=object_, id_=id_, session=self.session)
-        assert isinstance(insert_response, str)
+        assert isinstance(insert_response, int)
         assert insert_response == id_
         response_code = None
         try:
@@ -153,7 +153,7 @@ class TestCRUD(unittest.TestCase):
     def test_delete_id(self):
         """Test CRUD delete when wrong/undefined ID is given."""
         object_ = gen_dummy_object("dummyClass", self.doc)
-        id_ = "6"
+        id_ = 6
         insert_response = crud.insert(
             object_=object_, id_=id_, session=self.session)
         response_code = None
@@ -163,7 +163,7 @@ class TestCRUD(unittest.TestCase):
         except Exception as e:
             response_code, message = e.get_HTTP()
         assert 404 == response_code
-        assert isinstance(insert_response, str)
+        assert isinstance(insert_response, int)
         assert insert_response == id_
 
     def test_insert_type(self):
@@ -182,7 +182,7 @@ class TestCRUD(unittest.TestCase):
     def test_insert_id(self):
         """Test CRUD insert when used ID is given."""
         object_ = gen_dummy_object("dummyClass", self.doc)
-        id_ = "1"
+        id_ = 1
         response_code = None
         try:
             insert_response = crud.insert(
diff --git a/hydrus/tests/test_parser.py b/hydrus/tests/test_parser.py
index 7f43ffc..c3e0a70 100644
--- a/hydrus/tests/test_parser.py
+++ b/hydrus/tests/test_parser.py
@@ -67,6 +67,7 @@ class TestParser(unittest.TestCase):
         """Test if the variables can be removed from the path"""
         path = "A/B/C/{id}"
         result = openapi_parser.sanitise_path(path)
+        assert result == 'A/B/C'
         assert isinstance(result, str)
 
     def test_allow_parameter(self):