test_ldp.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import pytest
  2. import uuid
  3. from flask import url_for
  4. @pytest.fixture(scope='module')
  5. def random_uuid():
  6. return str(uuid.uuid4())
  7. def test_get_root_node(client, db):
  8. assert client.get(url_for('ldp.get_resource')).status_code == 200
  9. def test_post_resource(client, db):
  10. '''
  11. Check response headers for a POST operation with empty payload.
  12. '''
  13. res = client.post('/ldp/')
  14. assert res.status_code == 201
  15. assert 'Location' in res.headers
  16. def test_put_empty_resource(client, db, random_uuid):
  17. '''
  18. Check response headers for a PUT operation with empty payload.
  19. '''
  20. res = client.put('/ldp/{}'.format(random_uuid))
  21. assert res.status_code == 201
  22. def test_put_existing_resource(client, db, random_uuid):
  23. '''
  24. Trying to PUT an existing resource should:
  25. - Return a 204 if the payload is empty
  26. - Return a 204 if the payload is RDF, server-managed triples are included
  27. and the 'Prefer' header is set to 'handling=lenient'
  28. - Return a 409 (ServerManagedTermError) if the payload is RDF,
  29. server-managed triples are included and handling is set to 'strict'
  30. '''
  31. assert client.get('/ldp/{}'.format(random_uuid)).status_code == 200
  32. assert client.put('/ldp/{}'.format(random_uuid)).status_code == 204