From 4edb8cfd39f12dbe36231a670cb59c6f019d05fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 25 Apr 2016 11:45:52 +0200 Subject: [PATCH] Ensure that the returned project contains the correct etag. The etag of the post_internal response was used, which is NOT the same as the etag of the project document itself. --- pillar/application/modules/projects.py | 6 ++++++ tests/test_project_management.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/pillar/application/modules/projects.py b/pillar/application/modules/projects.py index 4291a1e3..3bb5dbcb 100644 --- a/pillar/application/modules/projects.py +++ b/pillar/application/modules/projects.py @@ -149,6 +149,12 @@ def _create_new_project(project_name, user_id, overrides): return abort_with_error(status) project.update(result) + # Now re-fetch the etag, as both the initial document and the returned + # result do not contain the same etag as the database. + document = current_app.data.driver.db['projects'].find_one(project['_id'], + projection={'_etag': 1}) + project.update(document) + log.info('Created project %s for user %s', project['_id'], user_id) return project diff --git a/tests/test_project_management.py b/tests/test_project_management.py index af06de36..e905a9de 100644 --- a/tests/test_project_management.py +++ b/tests/test_project_management.py @@ -50,6 +50,11 @@ class ProjectCreationTest(AbstractPillarTest): self.assertEqual('p-%s' % project_id, project['url']) self.assertEqual(1, len(project['permissions']['groups'])) + # Check the etag + resp = self.client.get('/projects/%s' % project_id) + from_db = json.loads(resp.data) + self.assertEqual(from_db['_etag'], project['_etag']) + group_id = ObjectId(project['permissions']['groups'][0]['group']) # Check that there is a group for the project, and that the user is member of it.