Skip to content
Snippets Groups Projects
Commit c6466f4f authored by hkethi002's avatar hkethi002 Committed by GitHub
Browse files

Merge pull request #793 from scitran/group-upd-modified

Group modified updates correctly
parents b79fc519 9a0480dd
No related branches found
No related tags found
No related merge requests found
......@@ -74,7 +74,10 @@ class ListStorage(object):
query = {'_id': _id}
if exclude_params:
query[self.list_name] = {'$not': {'$elemMatch': exclude_params} }
update = {'$push': {self.list_name: payload} }
update = {
'$push': {self.list_name: payload},
'$set': {'modified': datetime.datetime.utcnow()}
}
log.debug('query {}'.format(query))
log.debug('update {}'.format(update))
result = self.dbc.update_one(query, update)
......@@ -96,6 +99,7 @@ class ListStorage(object):
{self.list_name: {'$elemMatch': query_params}},
{self.list_name: {'$not': {'$elemMatch': exclude_params} }}
]
mod_elem['modified'] = datetime.datetime.utcnow()
update = {
'$set': mod_elem
}
......@@ -106,7 +110,10 @@ class ListStorage(object):
def _delete_el(self, _id, query_params):
log.debug('query_params {}'.format(query_params))
query = {'_id': _id}
update = {'$pull': {self.list_name: query_params} }
update = {
'$pull': {self.list_name: query_params},
'$set': { 'modified': datetime.datetime.utcnow()}
}
log.debug('query {}'.format(query))
log.debug('update {}'.format(update))
result = self.dbc.update_one(query, update)
......@@ -162,7 +169,10 @@ class StringListStorage(ListStorage):
def _create_el(self, _id, payload, exclude_params):
log.debug('payload {}'.format(payload))
query = {'_id': _id, self.list_name: {'$ne': payload}}
update = {'$push': {self.list_name: payload}}
update = {
'$push': {self.list_name: payload},
'$set': {'modified': datetime.datetime.utcnow()}
}
log.debug('query {}'.format(query))
log.debug('update {}'.format(update))
result = self.dbc.update_one(query, update)
......@@ -180,7 +190,10 @@ class StringListStorage(ListStorage):
{self.list_name: {'$ne': payload} }
]
}
update = {'$set': {self.list_name + '.$': payload}}
update = {
'$set': {self.list_name + '.$': payload,
'modified': datetime.datetime.utcnow()}
}
log.debug('query {}'.format(query))
log.debug('update {}'.format(update))
return self.dbc.update_one(query, update)
......
......@@ -55,6 +55,7 @@ class GroupHandler(base.RequestHandler):
payload_schema_uri = validators.schema_uri('input', 'group-update.json')
payload_validator = validators.from_schema_path(payload_schema_uri)
payload_validator(payload, 'PUT')
payload['modified'] = datetime.datetime.utcnow()
result = mongo_validator(permchecker(self.storage.exec_op))('PUT', _id=_id, payload=payload)
if result.modified_count == 1:
return {'modified': result.modified_count}
......
from dateutil.parser import parse
def test_groups(as_admin, data_builder):
# Cannot find a non-existant group
r = as_admin.get('/groups/non-existent')
......@@ -8,12 +10,91 @@ def test_groups(as_admin, data_builder):
# Able to find new group
r = as_admin.get('/groups/' + group)
assert r.ok
first_modified = r.json()['modified']
# Able to change group name
group_name = 'New group name'
r = as_admin.put('/groups/' + group, json={'name': group_name})
assert r.ok
# Get the group again to compare timestamps
r = as_admin.get('/groups/' + group)
assert r.ok
second_modified = r.json()['modified']
d1 = parse(first_modified)
d2 = parse(second_modified)
assert d2 > d1
# Add a tag to the group
tag_name = 'Grey2'
r = as_admin.post('/groups/' + group + '/tags', json={'value': tag_name})
assert r.ok
# Get the group again to compare timestamps for the Add tag test groups
r = as_admin.get('/groups/' + group)
assert r.ok
third_modified = r.json()['modified']
d3 = parse(third_modified)
assert d3 > d2
# Edit the tag
new_tag_name = 'Brown'
r = as_admin.put('/groups/' + group + '/tags/' + tag_name, json={'value': new_tag_name})
assert r.ok
# Get the group again to compare timestamps for the Edit tag test groups
r = as_admin.get('/groups/' + group)
assert r.ok
fourth_modified = r.json()['modified']
d4 = parse(fourth_modified)
assert d4 > d3
# Delete the tag
r = as_admin.delete('/groups/' + group + '/tags/' + new_tag_name)
assert r.ok
# Get the group again to compare timestamps for the Delete tag test groups
r = as_admin.get('/groups/' + group)
assert r.ok
fith_modified = r.json()['modified']
d5 = parse(fith_modified)
assert d5 > d4
# Add a role to the group
user = {'access': 'rw', 'site': 'local', '_id': 'newUser@fakeuser.com'}
r = as_admin.post('/groups/' + group + '/roles', json=user)
assert r.ok
# Get the group again to compare timestamps for the Add role test groups
r = as_admin.get('/groups/' + group)
assert r.ok
six_modified = r.json()['modified']
d6 = parse(six_modified)
assert d6 > d5
# Edit a role in the group
user = {'access': 'ro', 'site': 'local', '_id': 'newUser@fakeuser.com'}
r = as_admin.put('/groups/' + group + '/roles/' + user['site'] + '/' + user['_id'], json=user)
assert r.ok
# Get the group again to compare timestamps for the Edit role test groups
r = as_admin.get('/groups/' + group)
assert r.ok
seven_modified = r.json()['modified']
d7 = parse(seven_modified)
assert d7 > d6
# Delete a role in the group
r = as_admin.delete('/groups/' + group + '/roles/' + user['site'] + '/' + user['_id'])
assert r.ok
# Get the group again to compare timestamps for the Edit role test groups
r = as_admin.get('/groups/' + group)
assert r.ok
eight_modified = r.json()['modified']
d8 = parse(eight_modified)
assert d8 > d7
r = as_admin.get('/groups/' + group)
assert r.ok
assert r.json()['name'] == group_name
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment