Skip to content

Commit

Permalink
Added missing content type header in create and mkdir methods (#186)
Browse files Browse the repository at this point in the history
* Added missing content type header in create and mkdir methods
  • Loading branch information
zonia3000 authored Jul 5, 2021
1 parent 6d80dc6 commit 7df0d1d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 18 additions & 1 deletion vos/vos/tests/test_vos.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def test_create(self):
node2 = Node(str(node))
self.assertEqual(node, node2)
data = str(node)
headers = {'size': str(len(data))}
headers = {'size': str(len(data)), 'Content-Type': 'text/xml'}

client = Client()
# client.get_node_url = Mock(return_value='http://foo.com/bar')
Expand Down Expand Up @@ -781,6 +781,23 @@ def test_delete(self):
client.delete(uri1)
mock_session.delete.assert_called_once_with(url)

@patch('vos.vos.net.ws.WsCapabilities.get_access_url',
Mock(return_value='http://www.canfar.phys.uvic.ca/vospace/nodes'))
def test_mkdir(self):
uri = 'vos://create.vospace.auth!vospace/bar'
client = Client()
node = Node(client.fix_uri(uri), Node.CONTAINER_NODE)
headers = {'Content-Type': 'text/xml'}

client = Client()
session_mock = MagicMock()
client.get_session = Mock(return_value=session_mock)

client.mkdir(uri)
session_mock.put.assert_called_with(
'http://www.canfar.phys.uvic.ca/vospace/nodes/bar',
headers=headers, data=str(node))


class TestNode(unittest.TestCase):
"""Test the vos Node class.
Expand Down
4 changes: 2 additions & 2 deletions vos/vos/vos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2541,7 +2541,7 @@ def create(self, uri):
data = str(node)
size = len(data)
return Node(self.get_session(uri).put(
url, data=data, headers={'size': str(size)}).content)
url, data=data, headers={'size': str(size), 'Content-Type': 'text/xml'}).content)

def update(self, node, recursive=False):
"""Updates the node properties on the server. For non-recursive
Expand Down Expand Up @@ -2610,7 +2610,7 @@ def mkdir(self, uri):
node = Node(uri, node_type="vos:ContainerNode")
url = self.get_node_url(uri)
try:
response = self.get_session(uri).put(url, data=str(node))
response = self.get_session(uri).put(url, data=str(node), headers={'Content-Type': 'text/xml'})
response.raise_for_status()
except HTTPError as http_error:
if http_error.response.status_code != 409:
Expand Down

0 comments on commit 7df0d1d

Please sign in to comment.