Commit edc57ae1 authored by Sylvain's avatar Sylvain
Browse files

more tests + fixes

parent dfd6c8141f6b
......@@ -7,3 +7,24 @@ class Division(EntityType):
class Employee(EntityType):
works_for = SubjectRelation(('Company', 'Division'))
class require_permission(RelationType):
"""link a permission to the entity. This permission should be used in the
security definition of the entity's type to be useful.
"""
permissions = {
'read': ('managers', 'users', 'guests'),
'add': ('managers',),
'delete': ('managers',),
}
class missing_require_permission(RelationDefinition):
name = 'require_permission'
subject = ('Company', 'Division')
object = 'EPermission'
class EPermission(MetaEntityType):
"""entity type that may be used to construct some advanced security configuration
"""
name = String(required=True, indexed=True, internationalizable=True, maxsize=100,
description=_('name or identifier of the permission'))
"""unittests for schema2dot"""
import os
from logilab.common.testlib import TestCase, unittest_main
from logilab.common.compat import set
......@@ -23,35 +25,27 @@ class DummyDefaultHandler:
schema = SchemaLoader().load([DATADIR], default_handler=DummyDefaultHandler())
DOT_SOURCE = """digraph "Schema" {
DOT_SOURCE = """digraph "toto" {
rankdir=BT
ratio=compress
size="12,30"
charset="utf-8"
"Person" [label="Person"];
"Societe" [label="Societe"];
edge [label="travaille"];
"Person" [shape="box", fontname="Courier", style="filled", label="Person"];
"Societe" [shape="box", fontname="Courier", style="filled", label="Societe"];
edge [taillabel="0..n", style="filled", arrowhead="open", color="black", label="travaille", headlabel="0..n", arrowtail="none"];
"Person" -> "Societe"
}"""
class MyVisitor(schema2dot.SchemaVisitor):
"""customize drawing options for better control"""
def get_props_for_eschema(self, eschema):
return {'label' : eschema.type}
def get_props_for_rschema(self, rschema):
return {'label' : rschema.type}
class DotTC(TestCase):
def test_schema2dot(self):
"""tests dot conversion without attributes information"""
wanted_entities = set(('Person', 'Societe'))
skipped_entities = set(schema.entities()) - wanted_entities
visitor = MyVisitor()
visitor.visit(schema, skipped_entities=skipped_entities)
self.assertTextEquals(DOT_SOURCE, visitor.generator.source)
schema2dot.schema2dot(schema, '/tmp/toto.dot', skipentities=skipped_entities)
generated = open('/tmp/toto.dot').read()
os.remove('/tmp/toto.dot')
self.assertTextEquals(DOT_SOURCE, generated)
if __name__ == '__main__':
unittest_main()
......@@ -52,6 +52,11 @@ CREATE TABLE Division(
name text
);
CREATE TABLE EPermission(
name varchar(100) NOT NULL
);
CREATE INDEX epermission_name_idx ON EPermission(name);
CREATE TABLE Eetype(
name varchar(64) UNIQUE NOT NULL,
description text,
......@@ -158,6 +163,15 @@ CREATE TABLE obj_wildcard_relation (
CREATE INDEX obj_wildcard_relation_from_idx ON obj_wildcard_relation(eid_from);
CREATE INDEX obj_wildcard_relation_to_idx ON obj_wildcard_relation(eid_to);
CREATE TABLE require_permission_relation (
eid_from INTEGER NOT NULL,
eid_to INTEGER NOT NULL,
CONSTRAINT require_permission_relation_p_key PRIMARY KEY(eid_from, eid_to)
);
CREATE INDEX require_permission_relation_from_idx ON require_permission_relation(eid_from);
CREATE INDEX require_permission_relation_to_idx ON require_permission_relation(eid_to);
CREATE TABLE state_of_relation (
eid_from INTEGER NOT NULL,
eid_to INTEGER NOT NULL,
......
......@@ -54,7 +54,7 @@ class SchemaLoaderTC(TestCase):
self.assertEquals(schema.name, 'Test')
self.assertListEquals(sorted(schema.entities()),
['Affaire', 'Boolean', 'Bytes', 'Company', 'Date', 'Datetest', 'Datetime',
'Division', 'Eetype', 'Employee', 'Float', 'Int', 'Interval',
'Division', 'EPermission', 'Eetype', 'Employee', 'Float', 'Int', 'Interval',
'Note', 'Password', 'Person', 'Societe', 'State', 'String', 'Time',
'pkginfo'])
self.assertListEquals(sorted(schema.relations()),
......@@ -67,7 +67,7 @@ class SchemaLoaderTC(TestCase):
'mailinglist', 'meta', 'modname',
'name', 'next_state', 'nom', 'obj_wildcard',
'para', 'prenom', 'promo', 'pyversions',
'ref', 'rncs',
'ref', 'require_permission', 'rncs',
'salary', 'sexe', 'short_desc', 'state_of', 'subj_wildcard', 'sujet', 'sym_rel',
't1', 't2', 'tel', 'test', 'titre', 'travaille', 'type',
'version',
......@@ -178,7 +178,7 @@ class SchemaLoaderTC(TestCase):
self.assertEquals(rschema.description, '')
self.assertEquals(rschema.meta, False)
self.assertEquals(rschema.is_final(), True)
self.assertListEquals(sorted(rschema.subjects()), ['Company', 'Division', 'Eetype', 'State'])
self.assertListEquals(sorted(rschema.subjects()), ['Company', 'Division', 'EPermission', 'Eetype', 'State'])
self.assertListEquals(sorted(rschema.objects()), ['String'])
def test_cardinality(self):
......@@ -250,6 +250,11 @@ class SchemaLoaderTC(TestCase):
'add': ('managers', 'users', 'guests'),
'delete': ('managers', 'users', 'guests')})
rschema = schema.rschema('require_permission')
self.assertEquals(rschema._groups, {'read': ('managers', 'users', 'guests'),
'add': ('managers', ),
'delete': ('managers',)})
def test_entity_permissions(self):
eschema = schema.eschema('State')
self.assertEquals(eschema._groups,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment