Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt and modify tests #299

Merged
merged 5 commits into from
Dec 22, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions hydrus/samples/doc_writer_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
BASE_URL = "https://hydrus.com/" # The base url at which the API is hosted
# NOTE: The API will be accessible at BASE_URL + ENTRY_POINT (http://hydrus.com/api/)

"""Create ApiDoc Object"""
api_doc = HydraDoc(API_NAME,
"Title for the API Documentation",
"Description for the API Documentation",
Expand All @@ -19,8 +20,20 @@
class_uri = "dummyClass" # URI of class for the HydraClass
class_title = "dummyClass" # Title of the Class
class_description = "A dummyClass for demo" # Description of the class

class_ = HydraClass(class_uri, class_title, class_description, endpoint=False)

"""Class with single instance"""
class_2_uri = "singleClass"
class_2_title = "singleClass"
class_2_description = "A non collection class"
class_2 = HydraClass(class_2_uri, class_2_title, class_2_description, endpoint=True)

"""Class not having any methods except put and get"""
class_3_uri = "extraClass"
class_3_title = "extraClass"
class_3_description = "Class without any explicit methods"
class_3 = HydraClass(class_3_uri, class_3_title, class_3_description, endpoint=False)

# NOTE: Setting endpoint=True creates an endpoint for the class itself, this is usually for classes that have single instances.
# These classes should not ideally have a Collection, although Hydrus will allow creation of Collections for them

Expand Down Expand Up @@ -58,17 +71,46 @@
op_returns,
op_status)


"""Add the operation to the Class"""
"""Same way add DELETE, PUT and GET operations"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vddesai1871 Looks good! Could you please replace the """ with simple comments.

op2_status = [{"statusCode": 200, "description": "dummyClass deleted"}]
op2 = HydraClassOp("DeleteClass", "DELETE", None, None, op2_status)
op3_status = [{"statusCode": 201, "description": "dummyClass successfully added"}]
op3 = HydraClassOp("AddClass", "PUT", "vocab:dummyClass", None, op3_status)
op4_status = [{"statusCode": 200, "description": "dummyClass returned"}]
op4 = HydraClassOp("GetClass", "GET", None, "vocab:dummyClass", op4_status)

"""Operations for non collection class"""
class_2_op1_status = [{"statusCode": 200, "description": "singleClass changed"}]
class_2_op1 = HydraClassOp("UpdateClass", "POST", "vocab:singleClass", None, class_2_op1_status)
class_2_op2_status = [{"statusCode": 200, "description": "singleClass deleted"}]
class_2_op2 = HydraClassOp("DeleteClass", "DELETE", None, None, class_2_op2_status)
class_2_op3_status = [{"statusCode": 201, "description": "singleClass successfully added"}]
class_2_op3 = HydraClassOp("AddClass", "PUT", "vocab:singleClass", None, op3_status)
class_2_op4_status = [{"statusCode": 200, "description": "singleClass returned"}]
class_2_op4 = HydraClassOp("GetClass", "GET", None, "vocab:singleClass", op4_status)

"""Add the properties to the classes"""
class_.add_supported_prop(dummyProp1)
class_.add_supported_prop(dummyProp2)
class_2.add_supported_prop(dummyProp1)
class_2.add_supported_prop(dummyProp2)

"""Add the properties to the Class"""
"""Add the operations to the classes"""
class_.add_supported_op(op1)
class_.add_supported_op(op2)
class_.add_supported_op(op3)
class_.add_supported_op(op4)
class_2.add_supported_op(class_2_op1)
class_2.add_supported_op(class_2_op2)
class_2.add_supported_op(class_2_op3)
class_2.add_supported_op(class_2_op4)



"""Add the classes to the HydraDoc"""
api_doc.add_supported_class(class_, collection=True, collection_path="DcTest")
api_doc.add_supported_class(class_3, collection=True, collection_path="EcTest")
api_doc.add_supported_class(class_2, collection=False)
# NOTE: Using collection=True creates a HydraCollection for the class.
# The name of the Collection is class_.title+"Collection"
# The collection inherently supports GET and PUT operations
Expand Down
285 changes: 285 additions & 0 deletions hydrus/samples/doc_writer_sample_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,92 @@
"description": "Description for the API Documentation",
"possibleStatus": [],
"supportedClass": [
{
"@id": "vocab:extraClass",
"@type": "hydra:Class",
"description": "Class without any explicit methods",
"supportedOperation": [],
"supportedProperty": [],
"title": "extraClass"
},
{
"@id": "vocab:singleClass",
"@type": "hydra:Class",
"description": "A non collection class",
"supportedOperation": [
{
"@type": "http://schema.org/DeleteAction",
"expects": "vocab:singleClass",
"method": "DELETE",
"possibleStatus": [
{
"description": "singleClass changed",
"statusCode": 200
}
],
"returns": "null",
"title": "UpdateClass"
},
{
"@type": "http://schema.org/DeleteAction",
"expects": "null",
"method": "DELETE",
"possibleStatus": [
{
"description": "singleClass deleted",
"statusCode": 200
}
],
"returns": "null",
"title": "DeleteClass"
},
{
"@type": "http://schema.org/AddAction",
"expects": "vocab:singleClass",
"method": "PUT",
"possibleStatus": [
{
"description": "dummyClass successfully added",
"statusCode": 201
}
],
"returns": "null",
"title": "AddClass"
},
{
"@type": "http://schema.org/FindAction",
"expects": "null",
"method": "GET",
"possibleStatus": [
{
"description": "dummyClass returned",
"statusCode": 200
}
],
"returns": "vocab:singleClass",
"title": "GetClass"
}
],
"supportedProperty": [
{
"@type": "SupportedProperty",
"property": "http://props.hydrus.com/prop1",
"readonly": "false",
"required": "false",
"title": "Prop1",
"writeonly": "true"
},
{
"@type": "SupportedProperty",
"property": "http://props.hydrus.com/prop1",
"readonly": "false",
"required": "false",
"title": "Prop2",
"writeonly": "true"
}
],
"title": "singleClass"
},
{
"@id": "vocab:dummyClass",
"@type": "hydra:Class",
Expand All @@ -67,6 +153,45 @@
],
"returns": "null",
"title": "UpdateClass"
},
{
"@type": "http://schema.org/DeleteAction",
"expects": "null",
"method": "DELETE",
"possibleStatus": [
{
"description": "dummyClass deleted",
"statusCode": 200
}
],
"returns": "null",
"title": "DeleteClass"
},
{
"@type": "http://schema.org/AddAction",
"expects": "vocab:dummyClass",
"method": "PUT",
"possibleStatus": [
{
"description": "dummyClass successfully added",
"statusCode": 201
}
],
"returns": "null",
"title": "AddClass"
},
{
"@type": "http://schema.org/FindAction",
"expects": "null",
"method": "GET",
"possibleStatus": [
{
"description": "dummyClass returned",
"statusCode": 200
}
],
"returns": "vocab:dummyClass",
"title": "GetClass"
}
],
"supportedProperty": [
Expand Down Expand Up @@ -157,6 +282,49 @@
],
"title": "dummyClassCollection"
},
{
"@id": "vocab:extraClassCollection",
"@type": "hydra:Class",
"description": "A collection of extraclass",
"subClassOf": "http://www.w3.org/ns/hydra/core#Collection",
"supportedOperation": [
{
"@id": "_:extraclass_collection_retrieve",
"@type": "http://schema.org/FindAction",
"description": "Retrieves all extraClass entities",
"expects": "null",
"method": "GET",
"returns": "vocab:extraClassCollection",
"statusCodes": []
},
{
"@id": "_:extraclass_create",
"@type": "http://schema.org/AddAction",
"description": "Create new extraClass entitity",
"expects": "vocab:extraClass",
"method": "PUT",
"returns": "vocab:extraClass",
"statusCodes": [
{
"description": "If the extraClass entity was created successfully.",
"statusCode": 201
}
]
}
],
"supportedProperty": [
{
"@type": "SupportedProperty",
"description": "The extraclass",
"property": "http://www.w3.org/ns/hydra/core#member",
"readonly": "false",
"required": "false",
"title": "members",
"writeonly": "false"
}
],
"title": "extraClassCollection"
},
{
"@id": "vocab:EntryPoint",
"@type": "hydra:Class",
Expand All @@ -173,6 +341,83 @@
}
],
"supportedProperty": [
{
"hydra:description": "The singleClass Class",
"hydra:title": "singleclass",
"property": {
"@id": "vocab:EntryPoint/singleClass",
"@type": "hydra:Link",
"description": "A non collection class",
"domain": "vocab:EntryPoint",
"label": "singleClass",
"range": "vocab:singleClass",
"supportedOperation": [
{
"@id": "updateclass",
"@type": "http://schema.org/DeleteAction",
"description": "null",
"expects": "vocab:singleClass",
"label": "UpdateClass",
"method": "DELETE",
"returns": "null",
"statusCodes": [
{
"description": "singleClass changed",
"statusCode": 200
}
]
},
{
"@id": "deleteclass",
"@type": "http://schema.org/DeleteAction",
"description": "null",
"expects": "null",
"label": "DeleteClass",
"method": "DELETE",
"returns": "null",
"statusCodes": [
{
"description": "singleClass deleted",
"statusCode": 200
}
]
},
{
"@id": "addclass",
"@type": "http://schema.org/AddAction",
"description": "null",
"expects": "vocab:singleClass",
"label": "AddClass",
"method": "PUT",
"returns": "null",
"statusCodes": [
{
"description": "dummyClass successfully added",
"statusCode": 201
}
]
},
{
"@id": "getclass",
"@type": "http://schema.org/FindAction",
"description": "null",
"expects": "null",
"label": "GetClass",
"method": "GET",
"returns": "vocab:singleClass",
"statusCodes": [
{
"description": "dummyClass returned",
"statusCode": 200
}
]
}
]
},
"readonly": "true",
"required": "null",
"writeonly": "false"
},
{
"hydra:description": "The dummyClassCollection collection",
"hydra:title": "dummyclasscollection",
Expand Down Expand Up @@ -212,6 +457,46 @@
"readonly": "true",
"required": "null",
"writeonly": "false"
},
{
"hydra:description": "The extraClassCollection collection",
"hydra:title": "extraclasscollection",
"property": {
"@id": "vocab:EntryPoint/EcTest",
"@type": "hydra:Link",
"description": "The extraClassCollection collection",
"domain": "vocab:EntryPoint",
"label": "extraClassCollection",
"range": "vocab:extraClassCollection",
"supportedOperation": [
{
"@id": "_:extraclass_collection_retrieve",
"@type": "http://schema.org/FindAction",
"description": "Retrieves all extraClass entities",
"expects": "null",
"method": "GET",
"returns": "vocab:extraClassCollection",
"statusCodes": []
},
{
"@id": "_:extraclass_create",
"@type": "http://schema.org/AddAction",
"description": "Create new extraClass entitity",
"expects": "vocab:extraClass",
"method": "PUT",
"returns": "vocab:extraClass",
"statusCodes": [
{
"description": "If the extraClass entity was created successfully.",
"statusCode": 201
}
]
}
]
},
"readonly": "true",
"required": "null",
"writeonly": "false"
}
],
"title": "EntryPoint"
Expand Down
Loading