diff options
author | Aleksey Lim <alsroot@sugarlabs.org> | 2014-05-04 07:59:26 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@sugarlabs.org> | 2014-05-04 07:59:26 (GMT) |
commit | 0684b55b5f66da1c2dc61f15105ef5e0632019bf (patch) | |
tree | 848a31a82345dd38643c4be76620fe3f16f52adf | |
parent | a57e9537c034ee4566f8cf694518619588097f76 (diff) |
Simplify code and return author property as-is
-rw-r--r-- | sugar_network/db/__init__.py | 2 | ||||
-rw-r--r-- | sugar_network/db/metadata.py | 32 | ||||
-rw-r--r-- | sugar_network/db/resource.py | 4 | ||||
-rw-r--r-- | sugar_network/db/routes.py | 17 | ||||
-rw-r--r-- | sugar_network/toolkit/router.py | 19 | ||||
-rwxr-xr-x | tests/units/db/db_routes.py | 229 | ||||
-rwxr-xr-x | tests/units/node/node_model.py | 32 | ||||
-rwxr-xr-x | tests/units/node/node_routes.py | 56 |
8 files changed, 134 insertions, 257 deletions
diff --git a/sugar_network/db/__init__.py b/sugar_network/db/__init__.py index 6a6b27c..c486a70 100644 --- a/sugar_network/db/__init__.py +++ b/sugar_network/db/__init__.py @@ -351,7 +351,7 @@ Volume from sugar_network.db.metadata import \ stored_property, indexed_property, Property, Numeric, Boolean, Dict, \ - Enum, List, Aggregated, Blob, Localized, Reference + Enum, List, Aggregated, Blob, Localized, Reference, Author from sugar_network.db.index import index_flush_timeout, \ index_flush_threshold, index_write_queue from sugar_network.db.resource import Resource diff --git a/sugar_network/db/metadata.py b/sugar_network/db/metadata.py index 53d3f40..b0c8917 100644 --- a/sugar_network/db/metadata.py +++ b/sugar_network/db/metadata.py @@ -413,38 +413,14 @@ class Guid(Property): acl=ACL.CREATE | ACL.READ) -class Authors(Dict): +class Author(Dict): - def typecast(self, value): - if type(value) not in (list, tuple): - return dict(value) - result = {} - for order, author in enumerate(value): - user = author.pop('guid') - author['order'] = order - result[user] = author - return result - - def reprcast(self, value): - result = [] - for guid, props in sorted(value.items(), - cmp=lambda x, y: cmp(x[1]['order'], y[1]['order'])): - if 'name' in props: - result.append({ - 'guid': guid, - 'name': props['name'], - 'role': props['role'], - }) - else: - result.append({ - 'name': guid, - 'role': props['role'], - }) - return result + INSYSTEM = 1 << 0 + ORIGINAL = 1 << 16 def encode(self, value): for guid, props in value.items(): if 'name' in props: yield toolkit.ascii(props['name']) - if not (props['role'] & ACL.INSYSTEM): + if not (props['role'] & Author.INSYSTEM): yield guid diff --git a/sugar_network/db/resource.py b/sugar_network/db/resource.py index 1bf46c6..24d4ea1 100644 --- a/sugar_network/db/resource.py +++ b/sugar_network/db/resource.py @@ -16,7 +16,7 @@ import time from sugar_network.db.metadata import indexed_property, Localized -from sugar_network.db.metadata import Numeric, List, Authors, Enum +from sugar_network.db.metadata import Numeric, List, Author, Enum from sugar_network.db.metadata import Composite, Aggregated from sugar_network.toolkit.router import ACL from sugar_network.toolkit import ranges @@ -67,7 +67,7 @@ class Resource(object): def mtime(self, value): return value - @indexed_property(Authors, prefix='RA', default={}, full_text=True, + @indexed_property(Author, prefix='RA', default={}, full_text=True, acl=ACL.READ) def author(self, value): return value diff --git a/sugar_network/db/routes.py b/sugar_network/db/routes.py index 4c29780..29507d3 100644 --- a/sugar_network/db/routes.py +++ b/sugar_network/db/routes.py @@ -19,7 +19,7 @@ import logging from contextlib import contextmanager from sugar_network import toolkit -from sugar_network.db.metadata import Aggregated +from sugar_network.db.metadata import Aggregated, Author from sugar_network.toolkit.router import ACL, File from sugar_network.toolkit.router import route, fallbackroute, preroute from sugar_network.toolkit.coroutine import this @@ -46,7 +46,7 @@ class Routes(object): doc.created() if this.principal: authors = doc.posts['author'] = {} - self._useradd(authors, this.principal, ACL.ORIGINAL) + self._useradd(authors, this.principal, Author.ORIGINAL) self.volume[this.request.resource].create(doc.posts) return doc['guid'] @@ -238,19 +238,14 @@ class Routes(object): user_doc = self.volume['user'][user] if user_doc.available: props['name'] = user_doc['name'] - role |= ACL.INSYSTEM + role |= Author.INSYSTEM else: - role &= ~ACL.INSYSTEM - props['role'] = role & (ACL.INSYSTEM | ACL.ORIGINAL) + role &= ~Author.INSYSTEM + props['role'] = role & (Author.INSYSTEM | Author.ORIGINAL) if user in authors: authors[user].update(props) else: - if authors: - top = max(authors.values(), key=lambda x: x['order']) - props['order'] = top['order'] + 1 - else: - props['order'] = 0 authors[user] = props def _aggpost(self, acl): @@ -282,7 +277,7 @@ class Routes(object): if this.principal: authors = aggvalue['author'] = {} - role = ACL.ORIGINAL if this.principal in doc['author'] else 0 + role = Author.ORIGINAL if this.principal in doc['author'] else 0 self._useradd(authors, this.principal, role) doc.posts[request.prop] = {aggid: aggvalue} doc.updated() diff --git a/sugar_network/toolkit/router.py b/sugar_network/toolkit/router.py index ec89fec..ba498d6 100644 --- a/sugar_network/toolkit/router.py +++ b/sugar_network/toolkit/router.py @@ -74,23 +74,20 @@ def postroute(func): class ACL(object): - INSYSTEM = 1 << 0 - ORIGINAL = 1 << 1 - - CREATE = 1 << 2 - WRITE = 1 << 3 - READ = 1 << 4 - DELETE = 1 << 5 - INSERT = 1 << 6 - REMOVE = 1 << 7 - REPLACE = 1 << 8 + CREATE = 1 << 0 + WRITE = 1 << 1 + READ = 1 << 2 + DELETE = 1 << 3 + INSERT = 1 << 4 + REMOVE = 1 << 5 + REPLACE = 1 << 6 PUBLIC = CREATE | WRITE | READ | DELETE | INSERT | REMOVE AUTH = 1 << 10 AUTHOR = 1 << 11 AGG_AUTHOR = 1 << 12 - LOCAL = 1 << 14 + LOCAL = 1 << 20 NAMES = { CREATE: 'Create', diff --git a/tests/units/db/db_routes.py b/tests/units/db/db_routes.py index 9a0648e..e9f3b28 100755 --- a/tests/units/db/db_routes.py +++ b/tests/units/db/db_routes.py @@ -1108,20 +1108,20 @@ class DbRoutesTest(tests.Test): guid = this.call(method='POST', path=['document'], content={}) self.assertEqual( - [{'name': 'user', 'role': 2}], + {'user': {'role': db.Author.ORIGINAL}}, this.call(method='GET', path=['document', guid, 'author'])) self.assertEqual( - {'user': {'role': 2, 'order': 0}}, + {'user': {'role': db.Author.ORIGINAL}}, volume['document'].get(guid)['author']) volume['user'].create({'guid': 'user', 'pubkey': '', 'name': 'User'}) guid = this.call(method='POST', path=['document'], content={}) self.assertEqual( - [{'guid': 'user', 'name': 'User', 'role': 3}], + {'user': {'name': 'User', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, this.call(method='GET', path=['document', guid, 'author'])) self.assertEqual( - {'user': {'name': 'User', 'role': 3, 'order': 0}}, + {'user': {'name': 'User', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, volume['document'].get(guid)['author']) def test_FindByAuthor(self): @@ -1174,7 +1174,7 @@ class DbRoutesTest(tests.Test): ]), sorted(this.call(method='GET', path=['document'], query='author:Name')['result'])) - def test_PreserveAuthorsOrder(self): + def test_AddUser(self): class User(db.Resource): @@ -1194,148 +1194,57 @@ class DbRoutesTest(tests.Test): volume['user'].create({'guid': 'user1', 'pubkey': '', 'name': 'User1'}) volume['user'].create({'guid': 'user2', 'pubkey': '', 'name': 'User2'}) - volume['user'].create({'guid': 'user3', 'pubkey': '', 'name': 'User3'}) this.principal = 'user1' guid = this.call(method='POST', path=['document'], content={}) - this.call(method='PUT', path=['document', guid], cmd='useradd', user='user2', role=0) - this.call(method='PUT', path=['document', guid], cmd='useradd', user='user3', role=0) - - self.assertEqual([ - {'guid': 'user1', 'name': 'User1', 'role': 3}, - {'guid': 'user2', 'name': 'User2', 'role': 1}, - {'guid': 'user3', 'name': 'User3', 'role': 1}, - ], - this.call(method='GET', path=['document', guid, 'author'])) self.assertEqual({ - 'user1': {'name': 'User1', 'role': 3, 'order': 0}, - 'user2': {'name': 'User2', 'role': 1, 'order': 1}, - 'user3': {'name': 'User3', 'role': 1, 'order': 2}, + 'user1': {'name': 'User1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}, }, - volume['document'].get(guid)['author']) - - this.principal = 'user1' - this.call(method='PUT', path=['document', guid], cmd='userdel', user='user2') - this.call(method='PUT', path=['document', guid], cmd='useradd', user='user2', role=0) - - self.assertEqual([ - {'guid': 'user1', 'name': 'User1', 'role': 3}, - {'guid': 'user3', 'name': 'User3', 'role': 1}, - {'guid': 'user2', 'name': 'User2', 'role': 1}, - ], this.call(method='GET', path=['document', guid, 'author'])) self.assertEqual({ - 'user1': {'name': 'User1', 'role': 3, 'order': 0}, - 'user3': {'name': 'User3', 'role': 1, 'order': 2}, - 'user2': {'name': 'User2', 'role': 1, 'order': 3}, + 'user1': {'name': 'User1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}, }, volume['document'].get(guid)['author']) - this.principal = 'user1' - this.call(method='PUT', path=['document', guid], cmd='userdel', user='user2') - this.call(method='PUT', path=['document', guid], cmd='useradd', user='user2', role=0) - - self.assertEqual([ - {'guid': 'user1', 'name': 'User1', 'role': 3}, - {'guid': 'user3', 'name': 'User3', 'role': 1}, - {'guid': 'user2', 'name': 'User2', 'role': 1}, - ], - this.call(method='GET', path=['document', guid, 'author'])) + this.call(method='PUT', path=['document', guid], cmd='useradd', user='user2', role=db.Author.ORIGINAL) self.assertEqual({ - 'user1': {'name': 'User1', 'role': 3, 'order': 0}, - 'user3': {'name': 'User3', 'role': 1, 'order': 2}, - 'user2': {'name': 'User2', 'role': 1, 'order': 3}, + 'user1': {'name': 'User1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}, + 'user2': {'name': 'User2', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}, }, - volume['document'].get(guid)['author']) - - this.principal = 'user1' - this.call(method='PUT', path=['document', guid], cmd='userdel', user='user3') - this.call(method='PUT', path=['document', guid], cmd='useradd', user='user3', role=0) - - self.assertEqual([ - {'guid': 'user1', 'name': 'User1', 'role': 3}, - {'guid': 'user2', 'name': 'User2', 'role': 1}, - {'guid': 'user3', 'name': 'User3', 'role': 1}, - ], this.call(method='GET', path=['document', guid, 'author'])) self.assertEqual({ - 'user1': {'name': 'User1', 'role': 3, 'order': 0}, - 'user2': {'name': 'User2', 'role': 1, 'order': 3}, - 'user3': {'name': 'User3', 'role': 1, 'order': 4}, + 'user1': {'name': 'User1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}, + 'user2': {'name': 'User2', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}, }, volume['document'].get(guid)['author']) - def test_AddUser(self): - - class User(db.Resource): - - @db.indexed_property(slot=1) - def name(self, value): - return value - - @db.stored_property() - def pubkey(self, value): - return value - - class Document(db.Resource): - pass - - volume = db.Volume(tests.tmpdir, [User, Document]) - router = Router(db.Routes(volume)) - - volume['user'].create({'guid': 'user1', 'pubkey': '', 'name': 'User1'}) - volume['user'].create({'guid': 'user2', 'pubkey': '', 'name': 'User2'}) - - this.principal = 'user1' - guid = this.call(method='POST', path=['document'], content={}) - self.assertEqual([ - {'guid': 'user1', 'name': 'User1', 'role': 3}, - ], - this.call(method='GET', path=['document', guid, 'author'])) + this.call(method='PUT', path=['document', guid], cmd='useradd', user='User3', role=db.Author.INSYSTEM | db.Author.ORIGINAL) self.assertEqual({ - 'user1': {'name': 'User1', 'role': 3, 'order': 0}, + 'user1': {'name': 'User1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}, + 'user2': {'name': 'User2', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}, + 'User3': {'role': db.Author.ORIGINAL}, }, - volume['document'].get(guid)['author']) - - this.call(method='PUT', path=['document', guid], cmd='useradd', user='user2', role=2) - self.assertEqual([ - {'guid': 'user1', 'name': 'User1', 'role': 3}, - {'guid': 'user2', 'name': 'User2', 'role': 3}, - ], this.call(method='GET', path=['document', guid, 'author'])) self.assertEqual({ - 'user1': {'name': 'User1', 'role': 3, 'order': 0}, - 'user2': {'name': 'User2', 'role': 3, 'order': 1}, + 'user1': {'name': 'User1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}, + 'user2': {'name': 'User2', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}, + 'User3': {'role': db.Author.ORIGINAL}, }, volume['document'].get(guid)['author']) - this.call(method='PUT', path=['document', guid], cmd='useradd', user='User3', role=3) - self.assertEqual([ - {'guid': 'user1', 'name': 'User1', 'role': 3}, - {'guid': 'user2', 'name': 'User2', 'role': 3}, - {'name': 'User3', 'role': 2}, - ], - this.call(method='GET', path=['document', guid, 'author'])) + this.call(method='PUT', path=['document', guid], cmd='useradd', user='User4', role=1 << 32) self.assertEqual({ - 'user1': {'name': 'User1', 'role': 3, 'order': 0}, - 'user2': {'name': 'User2', 'role': 3, 'order': 1}, - 'User3': {'role': 2, 'order': 2}, + 'user1': {'name': 'User1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}, + 'user2': {'name': 'User2', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}, + 'User3': {'role': db.Author.ORIGINAL}, + 'User4': {'role': 0}, }, - volume['document'].get(guid)['author']) - - this.call(method='PUT', path=['document', guid], cmd='useradd', user='User4', role=4) - self.assertEqual([ - {'guid': 'user1', 'name': 'User1', 'role': 3}, - {'guid': 'user2', 'name': 'User2', 'role': 3}, - {'name': 'User3', 'role': 2}, - {'name': 'User4', 'role': 0}, - ], this.call(method='GET', path=['document', guid, 'author'])) self.assertEqual({ - 'user1': {'name': 'User1', 'role': 3, 'order': 0}, - 'user2': {'name': 'User2', 'role': 3, 'order': 1}, - 'User3': {'role': 2, 'order': 2}, - 'User4': {'role': 0, 'order': 3}, + 'user1': {'name': 'User1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}, + 'user2': {'name': 'User2', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}, + 'User3': {'role': db.Author.ORIGINAL}, + 'User4': {'role': 0}, }, volume['document'].get(guid)['author']) @@ -1362,38 +1271,38 @@ class DbRoutesTest(tests.Test): guid = this.call(method='POST', path=['document'], content={}) this.call(method='PUT', path=['document', guid], cmd='useradd', user='User2', role=0) - self.assertEqual([ - {'guid': 'user1', 'name': 'User1', 'role': 3}, - {'name': 'User2', 'role': 0}, - ], + self.assertEqual({ + 'user1': {'name': 'User1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}, + 'User2': {'role': 0}, + }, this.call(method='GET', path=['document', guid, 'author'])) self.assertEqual({ - 'user1': {'name': 'User1', 'role': 3, 'order': 0}, - 'User2': {'role': 0, 'order': 1}, + 'user1': {'name': 'User1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}, + 'User2': {'role': 0}, }, volume['document'].get(guid)['author']) this.call(method='PUT', path=['document', guid], cmd='useradd', user='user1', role=0) - self.assertEqual([ - {'guid': 'user1', 'name': 'User1', 'role': 1}, - {'name': 'User2', 'role': 0}, - ], + self.assertEqual({ + 'user1': {'name': 'User1', 'role': db.Author.INSYSTEM}, + 'User2': {'role': 0}, + }, this.call(method='GET', path=['document', guid, 'author'])) self.assertEqual({ - 'user1': {'name': 'User1', 'role': 1, 'order': 0}, - 'User2': {'role': 0, 'order': 1}, + 'user1': {'name': 'User1', 'role': db.Author.INSYSTEM}, + 'User2': {'role': 0}, }, volume['document'].get(guid)['author']) - this.call(method='PUT', path=['document', guid], cmd='useradd', user='User2', role=2) - self.assertEqual([ - {'guid': 'user1', 'name': 'User1', 'role': 1}, - {'name': 'User2', 'role': 2}, - ], + this.call(method='PUT', path=['document', guid], cmd='useradd', user='User2', role=db.Author.ORIGINAL) + self.assertEqual({ + 'user1': {'name': 'User1', 'role': db.Author.INSYSTEM}, + 'User2': {'role': db.Author.ORIGINAL}, + }, this.call(method='GET', path=['document', guid, 'author'])) self.assertEqual({ - 'user1': {'name': 'User1', 'role': 1, 'order': 0}, - 'User2': {'role': 2, 'order': 1}, + 'user1': {'name': 'User1', 'role': db.Author.INSYSTEM}, + 'User2': {'role': db.Author.ORIGINAL}, }, volume['document'].get(guid)['author']) @@ -1421,16 +1330,16 @@ class DbRoutesTest(tests.Test): guid = this.call(method='POST', path=['document'], content={}) this.call(method='PUT', path=['document', guid], cmd='useradd', user='user2') this.call(method='PUT', path=['document', guid], cmd='useradd', user='User3') - self.assertEqual([ - {'guid': 'user1', 'name': 'User1', 'role': 3}, - {'guid': 'user2', 'name': 'User2', 'role': 1}, - {'name': 'User3', 'role': 0}, - ], + self.assertEqual({ + 'user1': {'name': 'User1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}, + 'user2': {'name': 'User2', 'role': db.Author.INSYSTEM}, + 'User3': {'role': 0}, + }, this.call(method='GET', path=['document', guid, 'author'])) self.assertEqual({ - 'user1': {'name': 'User1', 'role': 3, 'order': 0}, - 'user2': {'name': 'User2', 'role': 1, 'order': 1}, - 'User3': {'role': 0, 'order': 2}, + 'user1': {'name': 'User1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}, + 'user2': {'name': 'User2', 'role': db.Author.INSYSTEM}, + 'User3': {'role': 0}, }, volume['document'].get(guid)['author']) @@ -1442,25 +1351,25 @@ class DbRoutesTest(tests.Test): this.principal = 'user2' this.call(method='PUT', path=['document', guid], cmd='userdel', user='user1') - self.assertEqual([ - {'guid': 'user2', 'name': 'User2', 'role': 1}, - {'name': 'User3', 'role': 0}, - ], + self.assertEqual({ + 'user2': {'name': 'User2', 'role': db.Author.INSYSTEM}, + 'User3': {'role': 0}, + }, this.call(method='GET', path=['document', guid, 'author'])) self.assertEqual({ - 'user2': {'name': 'User2', 'role': 1, 'order': 1}, - 'User3': {'role': 0, 'order': 2}, + 'user2': {'name': 'User2', 'role': db.Author.INSYSTEM}, + 'User3': {'role': 0}, }, volume['document'].get(guid)['author']) this.principal = 'user2' this.call(method='PUT', path=['document', guid], cmd='userdel', user='User3') - self.assertEqual([ - {'guid': 'user2', 'name': 'User2', 'role': 1}, - ], + self.assertEqual({ + 'user2': {'name': 'User2', 'role': db.Author.INSYSTEM}, + }, this.call(method='GET', path=['document', guid, 'author'])) self.assertEqual({ - 'user2': {'name': 'User2', 'role': 1, 'order': 1}, + 'user2': {'name': 'User2', 'role': db.Author.INSYSTEM}, }, volume['document'].get(guid)['author']) @@ -1789,22 +1698,22 @@ class DbRoutesTest(tests.Test): this.principal = tests.UID guid = this.call(method='POST', path=['document'], content={}) - assert ACL.ORIGINAL & volume['document'][guid]['author'][tests.UID]['role'] + assert db.Author.ORIGINAL & volume['document'][guid]['author'][tests.UID]['role'] this.principal = tests.UID agg_guid1 = this.call(method='POST', path=['document', guid, 'prop'], content=1) assert tests.UID2 not in volume['document'][guid]['prop'][agg_guid1]['author'] - assert ACL.ORIGINAL & volume['document'][guid]['prop'][agg_guid1]['author'][tests.UID]['role'] + assert db.Author.ORIGINAL & volume['document'][guid]['prop'][agg_guid1]['author'][tests.UID]['role'] this.principal = tests.UID2 agg_guid2 = this.call(method='POST', path=['document', guid, 'prop'], content=1) assert tests.UID not in volume['document'][guid]['prop'][agg_guid2]['author'] - assert not (ACL.ORIGINAL & volume['document'][guid]['prop'][agg_guid2]['author'][tests.UID2]['role']) + assert not (db.Author.ORIGINAL & volume['document'][guid]['prop'][agg_guid2]['author'][tests.UID2]['role']) this.principal = tests.UID2 this.call(method='DELETE', path=['document', guid, 'prop', agg_guid2]) assert tests.UID not in volume['document'][guid]['prop'][agg_guid2]['author'] - assert not (ACL.ORIGINAL & volume['document'][guid]['prop'][agg_guid2]['author'][tests.UID2]['role']) + assert not (db.Author.ORIGINAL & volume['document'][guid]['prop'][agg_guid2]['author'][tests.UID2]['role']) def test_AggregatedBlobs(self): self.override(time, 'time', lambda: 0) diff --git a/tests/units/node/node_model.py b/tests/units/node/node_model.py index afb42cd..ae7e56c 100755 --- a/tests/units/node/node_model.py +++ b/tests/units/node/node_model.py @@ -1155,7 +1155,7 @@ class NodeModelTest(tests.Test): }) self.assertEqual({ '*': { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': {'binary': ['pkg1.bin', 'pkg2.bin'], 'devel': ['pkg3.devel']}, 'ctime': 0, 'seqno': 3, @@ -1180,7 +1180,7 @@ class NodeModelTest(tests.Test): }) self.assertEqual({ 'Gentoo': { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': {'binary': ['pkg1.bin', 'pkg2.bin'], 'devel': ['pkg3.devel']}, 'ctime': 0, 'seqno': 5, @@ -1203,7 +1203,7 @@ class NodeModelTest(tests.Test): }) self.assertEqual({ 'Debian-6.0': { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': {'binary': ['pkg1.bin', 'pkg2.bin'], 'devel': ['pkg3.devel']}, 'ctime': 0, 'seqno': 7, @@ -1236,7 +1236,7 @@ class NodeModelTest(tests.Test): }) self.assertEqual({ '*': { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': {'binary': ['pkg1.bin', 'pkg2.bin'], 'devel': ['pkg3.devel']}, 'ctime': 0, 'seqno': 3, @@ -1268,7 +1268,7 @@ class NodeModelTest(tests.Test): conn.put(['context', guid, 'releases', '*'], {'binary': '1'}) self.assertEqual({ '*': { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': {'binary': ['1']}, 'ctime': 0, 'seqno': 3, @@ -1285,13 +1285,13 @@ class NodeModelTest(tests.Test): conn.put(['context', guid, 'releases', 'Debian'], {'binary': '2'}) self.assertEqual({ '*': { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': {'binary': ['1']}, 'ctime': 0, 'seqno': 3, }, 'Debian': { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': {'binary': ['2']}, 'ctime': 0, 'seqno': 4, @@ -1308,19 +1308,19 @@ class NodeModelTest(tests.Test): conn.put(['context', guid, 'releases', 'Debian-6.0'], {'binary': '3'}) self.assertEqual({ '*': { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': {'binary': ['1']}, 'ctime': 0, 'seqno': 3, }, 'Debian': { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': {'binary': ['2']}, 'ctime': 0, 'seqno': 4, }, 'Debian-6.0': { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': {'binary': ['3']}, 'ctime': 0, 'seqno': 5, @@ -1337,19 +1337,19 @@ class NodeModelTest(tests.Test): conn.put(['context', guid, 'releases', 'Debian'], {'binary': '4'}) self.assertEqual({ '*': { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': {'binary': ['1']}, 'ctime': 0, 'seqno': 3, }, 'Debian': { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': {'binary': ['4']}, 'ctime': 0, 'seqno': 6, }, 'Debian-6.0': { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': {'binary': ['3']}, 'ctime': 0, 'seqno': 5, @@ -2242,7 +2242,7 @@ class NodeModelTest(tests.Test): self.assertEqual(['image/bmp', 'image/gif'], context['mime_types']) assert context['ctime'] > 0 assert context['mtime'] > 0 - self.assertEqual({tests.UID: {'role': 3, 'name': 'user', 'order': 0}}, context['author']) + self.assertEqual({tests.UID: {'role': db.Author.INSYSTEM | db.Author.ORIGINAL, 'name': 'user'}}, context['author']) post = volume['post'][release['announce']] assert tests.UID in post['author'] @@ -2464,8 +2464,8 @@ class NodeModelTest(tests.Test): model.apply_batch('./batch') self.assertEqual(sorted([ - {'prop': '1', 'author': [{'name': 'test', 'role': ACL.ORIGINAL}]}, - {'prop': '2', 'author': [{'name': 'test', 'role': ACL.ORIGINAL}]}, + {'prop': '1', 'author': {'test': {'role': db.Author.ORIGINAL}}}, + {'prop': '2', 'author': {'test': {'role': db.Author.ORIGINAL}}}, ]), sorted(this.call(method='GET', path=['document'], reply=['prop', 'author'])['result'])) assert not exists('batch') diff --git a/tests/units/node/node_routes.py b/tests/units/node/node_routes.py index 77b57cc..9ebd117 100755 --- a/tests/units/node/node_routes.py +++ b/tests/units/node/node_routes.py @@ -255,7 +255,7 @@ class NodeRoutesTest(tests.Test): 'description': 'description', }) self.assertEqual( - [{'guid': tests.UID, 'name': 'user', 'role': 3}], + {tests.UID: {'name': 'user', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, this.call(method='GET', path=['context', guid, 'author'])) def test_find_MaxLimit(self): @@ -435,7 +435,7 @@ class NodeRoutesTest(tests.Test): assert release1 == str(hashlib.sha1(bundle1).hexdigest()) self.assertEqual({ release1: { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': { 'license': ['Public Domain'], 'announce': next(volume['post'].find(query='title:1')[0]).guid, @@ -465,7 +465,7 @@ class NodeRoutesTest(tests.Test): assert release2 == str(hashlib.sha1(bundle2).hexdigest()) self.assertEqual({ release1: { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': { 'license': ['Public Domain'], 'announce': next(volume['post'].find(query='title:1')[0]).guid, @@ -479,7 +479,7 @@ class NodeRoutesTest(tests.Test): 'seqno': 6, }, release2: { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': { 'license': ['Public Domain'], 'announce': next(volume['post'].find(query='title:2')[0]).guid, @@ -499,12 +499,12 @@ class NodeRoutesTest(tests.Test): conn.delete(['context', context, 'releases', release1]) self.assertEqual({ release1: { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'ctime': ts, 'seqno': 11, }, release2: { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': { 'license': ['Public Domain'], 'announce': next(volume['post'].find(query='title:2')[0]).guid, @@ -524,12 +524,12 @@ class NodeRoutesTest(tests.Test): conn.delete(['context', context, 'releases', release2]) self.assertEqual({ release1: { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'ctime': ts, 'seqno': 11, }, release2: { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'ctime': ts, 'seqno': 13, }, @@ -562,7 +562,7 @@ class NodeRoutesTest(tests.Test): self.assertEqual({ release: { - 'author': {tests.UID: {'name': 'test', 'order': 0, 'role': 3}}, + 'author': {tests.UID: {'name': 'test', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': { 'license': ['Public Domain'], 'announce': announce, @@ -796,15 +796,15 @@ class NodeRoutesTest(tests.Test): agg1 = this.call(method='POST', path=['document', guid, 'prop1'], environ=auth_env(tests.UID)) agg2 = this.call(method='POST', path=['document', guid, 'prop1'], environ=auth_env(tests.UID2)) self.assertEqual({ - agg1: {'seqno': 4, 'author': {tests.UID: {'name': 'user1', 'order': 0, 'role': 3}}, 'value': None, 'ctime': 0}, - agg2: {'seqno': 5, 'author': {tests.UID2: {'name': 'user2', 'order': 0, 'role': 1}}, 'value': None, 'ctime': 0}, + agg1: {'seqno': 4, 'author': {tests.UID: {'name': 'user1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': None, 'ctime': 0}, + agg2: {'seqno': 5, 'author': {tests.UID2: {'name': 'user2', 'role': db.Author.INSYSTEM}}, 'value': None, 'ctime': 0}, }, volume['document'][guid]['prop1']) agg3 = this.call(method='POST', path=['document', guid, 'prop2'], environ=auth_env(tests.UID)) self.assertRaises(http. Forbidden, this.call, method='POST', path=['document', guid, 'prop2'], environ=auth_env(tests.UID2)) self.assertEqual({ - agg3: {'seqno': 6, 'author': {tests.UID: {'name': 'user1', 'order': 0, 'role': 3}}, 'value': None, 'ctime': 0}, + agg3: {'seqno': 6, 'author': {tests.UID: {'name': 'user1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': None, 'ctime': 0}, }, volume['document'][guid]['prop2']) @@ -831,8 +831,8 @@ class NodeRoutesTest(tests.Test): agg1 = this.call(method='POST', path=['document', guid, 'prop1'], environ=auth_env(tests.UID)) agg2 = this.call(method='POST', path=['document', guid, 'prop1'], environ=auth_env(tests.UID2)) self.assertEqual({ - agg1: {'seqno': 4, 'author': {tests.UID: {'name': 'user1', 'order': 0, 'role': 3}}, 'value': None, 'ctime': 0}, - agg2: {'seqno': 5, 'author': {tests.UID2: {'name': 'user2', 'order': 0, 'role': 1}}, 'value': None, 'ctime': 0}, + agg1: {'seqno': 4, 'author': {tests.UID: {'name': 'user1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': None, 'ctime': 0}, + agg2: {'seqno': 5, 'author': {tests.UID2: {'name': 'user2', 'role': db.Author.INSYSTEM}}, 'value': None, 'ctime': 0}, }, volume['document'][guid]['prop1']) self.assertRaises(http. Forbidden, this.call, method='PUT', path=['document', guid, 'prop1', agg1], environ=auth_env(tests.UID2)) @@ -841,7 +841,7 @@ class NodeRoutesTest(tests.Test): agg3 = this.call(method='POST', path=['document', guid, 'prop2'], environ=auth_env(tests.UID)) self.assertRaises(http. Forbidden, this.call, method='POST', path=['document', guid, 'prop2'], environ=auth_env(tests.UID2)) self.assertEqual({ - agg3: {'seqno': 7, 'author': {tests.UID: {'name': 'user1', 'order': 0, 'role': 3}}, 'value': None, 'ctime': 0}, + agg3: {'seqno': 7, 'author': {tests.UID: {'name': 'user1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'value': None, 'ctime': 0}, }, volume['document'][guid]['prop2']) @@ -867,45 +867,45 @@ class NodeRoutesTest(tests.Test): agg1 = this.call(method='POST', path=['document', guid, 'prop1'], environ=auth_env(tests.UID), content=True) agg2 = this.call(method='POST', path=['document', guid, 'prop1'], environ=auth_env(tests.UID2), content=True) self.assertEqual({ - agg1: {'seqno': 4, 'value': True, 'author': {tests.UID: {'name': 'user1', 'order': 0, 'role': 3}}, 'ctime': 0}, - agg2: {'seqno': 5, 'value': True, 'author': {tests.UID2: {'name': 'user2', 'order': 0, 'role': 1}}, 'ctime': 0}, + agg1: {'seqno': 4, 'value': True, 'author': {tests.UID: {'name': 'user1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'ctime': 0}, + agg2: {'seqno': 5, 'value': True, 'author': {tests.UID2: {'name': 'user2', 'role': db.Author.INSYSTEM}}, 'ctime': 0}, }, volume['document'][guid]['prop1']) self.assertRaises(http.Forbidden, this.call, method='DELETE', path=['document', guid, 'prop1', agg1], environ=auth_env(tests.UID2)) self.assertRaises(http.Forbidden, this.call, method='DELETE', path=['document', guid, 'prop1', agg2], environ=auth_env(tests.UID)) self.assertEqual({ - agg1: {'seqno': 4, 'value': True, 'author': {tests.UID: {'name': 'user1', 'order': 0, 'role': 3}}, 'ctime': 0}, - agg2: {'seqno': 5, 'value': True, 'author': {tests.UID2: {'name': 'user2', 'order': 0, 'role': 1}}, 'ctime': 0}, + agg1: {'seqno': 4, 'value': True, 'author': {tests.UID: {'name': 'user1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'ctime': 0}, + agg2: {'seqno': 5, 'value': True, 'author': {tests.UID2: {'name': 'user2', 'role': db.Author.INSYSTEM}}, 'ctime': 0}, }, volume['document'][guid]['prop1']) this.call(method='DELETE', path=['document', guid, 'prop1', agg1], environ=auth_env(tests.UID)) self.assertEqual({ - agg1: {'seqno': 6, 'author': {tests.UID: {'name': 'user1', 'order': 0, 'role': 3}}, 'ctime': 0}, - agg2: {'seqno': 5, 'value': True, 'author': {tests.UID2: {'name': 'user2', 'order': 0, 'role': 1}}, 'ctime': 0}, + agg1: {'seqno': 6, 'author': {tests.UID: {'name': 'user1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'ctime': 0}, + agg2: {'seqno': 5, 'value': True, 'author': {tests.UID2: {'name': 'user2', 'role': db.Author.INSYSTEM}}, 'ctime': 0}, }, volume['document'][guid]['prop1']) this.call(method='DELETE', path=['document', guid, 'prop1', agg2], environ=auth_env(tests.UID2)) self.assertEqual({ - agg1: {'seqno': 6, 'author': {tests.UID: {'name': 'user1', 'order': 0, 'role': 3}}, 'ctime': 0}, - agg2: {'seqno': 7, 'author': {tests.UID2: {'name': 'user2', 'order': 0, 'role': 1}}, 'ctime': 0}, + agg1: {'seqno': 6, 'author': {tests.UID: {'name': 'user1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'ctime': 0}, + agg2: {'seqno': 7, 'author': {tests.UID2: {'name': 'user2', 'role': db.Author.INSYSTEM}}, 'ctime': 0}, }, volume['document'][guid]['prop1']) agg3 = this.call(method='POST', path=['document', guid, 'prop2'], environ=auth_env(tests.UID), content=True) self.assertEqual({ - agg3: {'seqno': 8, 'value': True, 'author': {tests.UID: {'name': 'user1', 'order': 0, 'role': 3}}, 'ctime': 0}, + agg3: {'seqno': 8, 'value': True, 'author': {tests.UID: {'name': 'user1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'ctime': 0}, }, volume['document'][guid]['prop2']) self.assertRaises(http.Forbidden, this.call, method='DELETE', path=['document', guid, 'prop2', agg3], environ=auth_env(tests.UID2)) self.assertEqual({ - agg3: {'seqno': 8, 'value': True, 'author': {tests.UID: {'name': 'user1', 'order': 0, 'role': 3}}, 'ctime': 0}, + agg3: {'seqno': 8, 'value': True, 'author': {tests.UID: {'name': 'user1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'ctime': 0}, }, volume['document'][guid]['prop2']) this.call(method='DELETE', path=['document', guid, 'prop2', agg3], environ=auth_env(tests.UID)) self.assertEqual({ - agg3: {'seqno': 9, 'author': {tests.UID: {'name': 'user1', 'order': 0, 'role': 3}}, 'ctime': 0}, + agg3: {'seqno': 9, 'author': {tests.UID: {'name': 'user1', 'role': db.Author.INSYSTEM | db.Author.ORIGINAL}}, 'ctime': 0}, }, volume['document'][guid]['prop2']) @@ -1138,8 +1138,8 @@ class NodeRoutesTest(tests.Test): ) self.assertEqual(sorted([ - {'prop': '1', 'author': [{'guid': tests.UID, 'name': 'test', 'role': ACL.ORIGINAL | ACL.INSYSTEM}]}, - {'prop': '2', 'author': [{'guid': tests.UID, 'name': 'test', 'role': ACL.ORIGINAL | ACL.INSYSTEM}]}, + {'prop': '1', 'author': {tests.UID: {'name': 'test', 'role': db.Author.ORIGINAL | db.Author.INSYSTEM}}}, + {'prop': '2', 'author': {tests.UID: {'name': 'test', 'role': db.Author.ORIGINAL | db.Author.INSYSTEM}}}, ]), sorted(this.call(method='GET', path=['document'], reply=['prop', 'author'])['result'])) |