Skip to content

Commit

Permalink
Minor changes in the API and Tests for Data and Schema.
Browse files Browse the repository at this point in the history
  • Loading branch information
gabmunrio committed Oct 29, 2015
1 parent 5422227 commit c8acda5
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 53 deletions.
22 changes: 11 additions & 11 deletions sylva/data/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def post(self, request, graph_slug, type_slug, format=None):

# We get the post data
data = request.data
if isinstance(data, unicode):
if isinstance(data, (str, unicode)):
# We check if we need to deserialize the object
data = json.loads(data)
nodes_ids = []
Expand Down Expand Up @@ -101,7 +101,7 @@ def delete(self, request, graph_slug, type_slug, format=None):

# We get the post data
data = request.data
if isinstance(data, unicode):
if isinstance(data, (str, unicode)):
# We check if we need to deserialize the object
data = json.loads(data)
nodes_ids = []
Expand Down Expand Up @@ -171,7 +171,7 @@ def post(self, request, graph_slug, type_slug, format=None):

# We get the post data
data = request.data
if isinstance(data, unicode):
if isinstance(data, (str, unicode)):
# We check if we need to deserialize the object
data = json.loads(data)
rels_ids = []
Expand All @@ -194,7 +194,7 @@ def post(self, request, graph_slug, type_slug, format=None):
transaction_ok = False
break
except Exception as e:
error = dict()
error = {}
error['detail'] = e.message
transaction_ok = False
break
Expand All @@ -213,7 +213,7 @@ def delete(self, request, graph_slug, type_slug, format=None):

# We get the post data
data = request.data
if isinstance(data, unicode):
if isinstance(data, (str, unicode)):
# We check if we need to deserialize the object
data = json.loads(data)
rels_ids = []
Expand Down Expand Up @@ -255,12 +255,12 @@ def patch(self, request, graph_slug, type_slug, node_id, format=None):
self.check_object_permissions(self.request, graph)

post_data = request.data
if isinstance(post_data, unicode):
if isinstance(post_data, (str, unicode)):
# We check if we need to deserialize the object
post_data = json.loads(post_data)
node = graph.nodes.get(node_id)

new_data = dict()
new_data = {}
new_data['id'] = post_data.get('id', node.id)
new_data['label'] = post_data.get('label', node.label)
new_data['label_display'] = (
Expand All @@ -284,12 +284,12 @@ def put(self, request, graph_slug, type_slug, node_id, format=None):
self.check_object_permissions(self.request, graph)

post_data = request.data
if isinstance(post_data, unicode):
if isinstance(post_data, (str, unicode)):
# We check if we need to deserialize the object
post_data = json.loads(post_data)
node = graph.nodes.get(node_id)

new_data = dict()
new_data = {}
new_data['id'] = post_data.get('id', node.id)
new_data['label'] = post_data.get('label', node.label)
new_data['label_display'] = (
Expand Down Expand Up @@ -346,7 +346,7 @@ def patch(self, request, graph_slug, type_slug, relationship_id,

relationship = graph.relationships.get(relationship_id)

new_data = dict()
new_data = {}
new_data['id'] = post_data.get('id', relationship.id)
new_data['label'] = post_data.get('label', relationship.label)
new_data['label_display'] = (
Expand Down Expand Up @@ -374,7 +374,7 @@ def put(self, request, graph_slug, type_slug, relationship_id,

relationship = graph.relationships.get(relationship_id)

new_data = dict()
new_data = {}
new_data['id'] = post_data.get('id', relationship.id)
new_data['label'] = post_data.get('label', relationship.label)
new_data['label_display'] = (
Expand Down
46 changes: 30 additions & 16 deletions sylva/data/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ def test_api_nodes_post(self):
'key': property_name,
'datatype': property_datatype
}

response = self.client.post(url, property_data)
property_data_serialized = json.dumps(property_data)
response = self.client.post(url, property_data_serialized,
format='json')

self.assertEqual(response.status_code, 201)
self.assertEqual(response.data['properties'][0]['name'], property_name)
Expand Down Expand Up @@ -284,8 +285,9 @@ def test_api_nodes_delete(self):
'key': property_name,
'datatype': property_datatype
}

response = self.client.post(url, property_data)
property_data_serialized = json.dumps(property_data)
response = self.client.post(url, property_data_serialized,
format='json')

self.assertEqual(response.status_code, 201)
self.assertEqual(response.data['properties'][0]['name'], property_name)
Expand Down Expand Up @@ -407,7 +409,9 @@ def test_api_relationships_post(self):
'key': property_name1,
'datatype': property_datatype
}
response = self.client.post(url, property_data)
property_data_serialized = json.dumps(property_data)
response = self.client.post(url, property_data_serialized,
format='json')
self.assertEqual(response.status_code, 201)
self.assertEqual(response.data['properties'][0]['name'],
property_name1)
Expand All @@ -420,7 +424,9 @@ def test_api_relationships_post(self):
'key': property_name2,
'datatype': property_datatype
}
response = self.client.post(url, property_data)
property_data_serialized = json.dumps(property_data)
response = self.client.post(url, property_data_serialized,
format='json')
self.assertEqual(response.status_code, 201)
self.assertEqual(response.data['properties'][0]['name'],
property_name2)
Expand Down Expand Up @@ -520,7 +526,9 @@ def test_api_relationships_delete(self):
'key': property_name1,
'datatype': property_datatype
}
response = self.client.post(url, property_data)
property_data_serialized = json.dumps(property_data)
response = self.client.post(url, property_data_serialized,
format='json')
self.assertEqual(response.status_code, 201)
self.assertEqual(response.data['properties'][0]['name'],
property_name1)
Expand All @@ -533,7 +541,9 @@ def test_api_relationships_delete(self):
'key': property_name2,
'datatype': property_datatype
}
response = self.client.post(url, property_data)
property_data_serialized = json.dumps(property_data)
response = self.client.post(url, property_data_serialized,
format='json')
self.assertEqual(response.status_code, 201)
self.assertEqual(response.data['properties'][0]['name'],
property_name2)
Expand Down Expand Up @@ -630,8 +640,9 @@ def test_api_node_get(self):
'key': property_name,
'datatype': property_datatype
}

response = self.client.post(url, property_data)
property_data_serialized = json.dumps(property_data)
response = self.client.post(url, property_data_serialized,
format='json')

self.assertEqual(response.status_code, 201)
self.assertEqual(response.data['properties'][0]['name'], property_name)
Expand Down Expand Up @@ -702,8 +713,9 @@ def test_api_node_patch(self):
'key': property_name,
'datatype': property_datatype
}

response = self.client.post(url, property_data)
property_data_serialized = json.dumps(property_data)
response = self.client.post(url, property_data_serialized,
format='json')

self.assertEqual(response.status_code, 201)
self.assertEqual(response.data['properties'][0]['name'], property_name)
Expand Down Expand Up @@ -779,8 +791,9 @@ def test_api_node_put(self):
'key': property_name,
'datatype': property_datatype
}

response = self.client.post(url, property_data)
property_data_serialized = json.dumps(property_data)
response = self.client.post(url, property_data_serialized,
format='json')

self.assertEqual(response.status_code, 201)
self.assertEqual(response.data['properties'][0]['name'], property_name)
Expand Down Expand Up @@ -856,8 +869,9 @@ def test_api_node_delete(self):
'key': property_name,
'datatype': property_datatype
}

response = self.client.post(url, property_data)
property_data_serialized = json.dumps(property_data)
response = self.client.post(url, property_data_serialized,
format='json')

self.assertEqual(response.status_code, 201)
self.assertEqual(response.data['properties'][0]['name'], property_name)
Expand Down

0 comments on commit c8acda5

Please sign in to comment.