Commit 3b90f26d authored by Laurent Peuch's avatar Laurent Peuch
Browse files

chore: black new version

parent f5b98251daf4
Pipeline #15498 failed with stages
in 1 minute and 16 seconds
......@@ -65,14 +65,20 @@ class missing_require_permission(RelationDefinition):
class EPermission(EntityType):
"""entity type that may be used to construct some advanced security configuration
"""
"""entity type that may be used to construct some advanced security configuration"""
__permissions__ = {
"read": ("managers", "users", "guests",),
"read": (
"managers",
"users",
"guests",
),
"add": ("managers",),
"delete": ("managers",),
"update": ("managers", "owners",),
"update": (
"managers",
"owners",
),
}
name = String(
required=True,
......
......@@ -27,10 +27,23 @@ class State(EntityType):
"""
__permissions__ = {
"read": ("managers", "users", "guests",),
"add": ("managers", "users",),
"delete": ("managers", "owners",),
"update": ("managers", "owners",),
"read": (
"managers",
"users",
"guests",
),
"add": (
"managers",
"users",
),
"delete": (
"managers",
"owners",
),
"update": (
"managers",
"owners",
),
}
# attributes
......@@ -51,8 +64,7 @@ class state_of(RelationType):
class next_state(RelationType):
"""define a workflow by associating a state to possible following states
"""
"""define a workflow by associating a state to possible following states"""
__permissions__ = RESTRICTED_RTYPE_PERMS
......@@ -63,9 +75,19 @@ class initial_state(RelationType):
"""
__permissions__ = {
"read": ("managers", "users", "guests",),
"add": ("managers", "users",),
"delete": ("managers", "users",),
"read": (
"managers",
"users",
"guests",
),
"add": (
"managers",
"users",
),
"delete": (
"managers",
"users",
),
}
subject = "Eetype"
object = "State"
......@@ -77,10 +99,17 @@ class Eetype(EntityType):
"""define an entity type, used to build the application schema"""
__permissions__ = {
"read": ("managers", "users", "guests",),
"read": (
"managers",
"users",
"guests",
),
"add": ("managers",),
"delete": ("managers",),
"update": ("managers", "owners",),
"update": (
"managers",
"owners",
),
}
name = String(
required=True,
......
......@@ -17,7 +17,11 @@
# with yams. If not, see <http://www.gnu.org/licenses/>.
"""test schema"""
RESTRICTED_RTYPE_PERMS = {
"read": ("managers", "users", "guests",),
"read": (
"managers",
"users",
"guests",
),
"add": ("managers",),
"delete": ("managers",),
}
......@@ -59,7 +59,12 @@ class Person(EntityType):
test = Boolean()
salary = Float()
travaille = SubjectRelation(
"Societe", __permissions__={"read": (), "add": (), "delete": ("managers",),}
"Societe",
__permissions__={
"read": (),
"add": (),
"delete": ("managers",),
},
)
evaluee = SubjectRelation("Note")
......
......@@ -171,7 +171,10 @@ class PropertiesFromTC(TestCase):
}
relation_definition = self.build_relation_definition(props_ref)
self.assertEqual(
{"__permissions__": self.expected_default_attr_perms, "order": 1,},
{
"__permissions__": self.expected_default_attr_perms,
"order": 1,
},
properties_from(relation_definition),
)
......
......@@ -381,10 +381,23 @@ class SchemaLoaderTC(TestCase):
self.assertEqual(
entity_schema.permissions,
{
"read": ("managers", "users", "guests",),
"add": ("managers", "users",),
"delete": ("managers", "owners",),
"update": ("managers", "owners",),
"read": (
"managers",
"users",
"guests",
),
"add": (
"managers",
"users",
),
"delete": (
"managers",
"owners",
),
"update": (
"managers",
"owners",
),
},
)
......@@ -392,10 +405,17 @@ class SchemaLoaderTC(TestCase):
self.assertEqual(
entity_schema.permissions,
{
"read": ("managers", "users", "guests",),
"read": (
"managers",
"users",
"guests",
),
"add": ("managers",),
"delete": ("managers",),
"update": ("managers", "owners",),
"update": (
"managers",
"owners",
),
},
)
......@@ -403,10 +423,23 @@ class SchemaLoaderTC(TestCase):
self.assertEqual(
entity_schema.permissions,
{
"read": ("managers", "users", "guests",),
"add": ("managers", "users",),
"delete": ("managers", "owners",),
"update": ("managers", "owners",),
"read": (
"managers",
"users",
"guests",
),
"add": (
"managers",
"users",
),
"delete": (
"managers",
"owners",
),
"update": (
"managers",
"owners",
),
},
)
......
......@@ -180,7 +180,13 @@ ATTRIBUTE_BAD_VALUES = (
("date", None),
],
),
("Affaire", [("ref", "ginco01"), ("ref", "GINCO"),],),
(
"Affaire",
[
("ref", "ginco01"),
("ref", "GINCO"),
],
),
)
ATTRIBUTE_GOOD_VALUES = (
......@@ -471,8 +477,7 @@ class RelationSchemaTC(BaseSchemaTC):
class SchemaTC(BaseSchemaTC):
def test_schema_base(self):
"""test base schema methods
"""
"""test base schema methods"""
all_types = [
"Affaire",
"BigInt",
......
......@@ -63,28 +63,57 @@ BASE_GROUPS: Set[str] = set((_("managers"), _("users"), _("guests"), _("owners")
# default permissions for entity types, relations and attributes
DEFAULT_ETYPEPERMS: yams_types.Permissions = {
"read": ("managers", "users", "guests",),
"update": ("managers", "owners",),
"read": (
"managers",
"users",
"guests",
),
"update": (
"managers",
"owners",
),
"delete": ("managers", "owners"),
"add": ("managers", "users",),
"add": (
"managers",
"users",
),
}
DEFAULT_RELPERMS: yams_types.Permissions = {
"read": ("managers", "users", "guests",),
"read": (
"managers",
"users",
"guests",
),
"delete": ("managers", "users"),
"add": ("managers", "users",),
"add": (
"managers",
"users",
),
}
DEFAULT_ATTRPERMS: yams_types.Permissions = {
"read": ("managers", "users", "guests",),
"read": (
"managers",
"users",
"guests",
),
"add": ("managers", "users"),
"update": ("managers", "owners"),
}
DEFAULT_COMPUTED_RELPERMS: yams_types.Permissions = {
"read": ("managers", "users", "guests",),
"read": (
"managers",
"users",
"guests",
),
"delete": (),
"add": (),
}
DEFAULT_COMPUTED_ATTRPERMS: yams_types.Permissions = {
"read": ("managers", "users", "guests",),
"read": (
"managers",
"users",
"guests",
),
"add": (),
"update": (),
}
......
......@@ -665,9 +665,12 @@ class EntityType(Definition, metaclass=metadefinition):
name: str = getattr(cls, "name", cls.__name__)
assert cls is not defined.get(name), "duplicate registration: %s" % name
assert name not in defined, (
"type '%s' was already defined here %s, new definition here %s"
% (name, defined[name].__module__, cls)
assert (
name not in defined
), "type '%s' was already defined here %s, new definition here %s" % (
name,
defined[name].__module__,
cls,
)
# mypy: "Type[EntityType]" has no attribute "_defined"
......@@ -849,8 +852,7 @@ class EntityType(Definition, metaclass=metadefinition):
@classmethod
def get_relation(cls: Type["EntityType"], name: str) -> ObjectRelation:
"""Return relation definitions by name. Fails if there is multiple one.
"""
"""Return relation definitions by name. Fails if there is multiple one."""
relations: Tuple[ObjectRelation, ...] = tuple(cls.get_relations(name))
assert len(relations) == 1, "can't use get_relation for relation with multiple definitions"
......
......@@ -41,12 +41,10 @@ class ISchema(Interface): # (IRQLSchema):
"""
def has_entity(self, e_type) -> bool:
"""return true the type is defined in the schema
"""
"""return true the type is defined in the schema"""
def eschema(self, e_type) -> Any:
"""return the entity's schema for the given type
"""
"""return the entity's schema for the given type"""
def relations(self, schema: yams_types.Schema = None) -> List:
"""return the list of possible relation'types
......@@ -56,12 +54,10 @@ class ISchema(Interface): # (IRQLSchema):
"""
def has_relation(self, rtype) -> bool:
"""return true the relation is defined in the schema
"""
"""return true the relation is defined in the schema"""
def rschema(self, rtype) -> None:
"""return the relation schema for the given relation type
"""
"""return the relation schema for the given relation type"""
class IRelationSchema(Interface): # (IRQLRelationSchema):
......@@ -159,12 +155,10 @@ class IEntitySchema(Interface): # (IRQLEntitySchema):
"""
def constraints(self, rtype) -> Any:
"""return the existing constraints on the <rtype> subject relation
"""
"""return the existing constraints on the <rtype> subject relation"""
def default(self, rtype) -> Any:
"""return the default value of a subject relation
"""
"""return the default value of a subject relation"""
def check(self, entity) -> None:
"""check the entity and raises an InvalidEntity exception if it
......@@ -173,8 +167,7 @@ class IEntitySchema(Interface): # (IRQLEntitySchema):
class IConstraint(Interface):
"""Represents a constraint on a relation.
"""
"""Represents a constraint on a relation."""
class IVocabularyConstraint(IConstraint):
......
......@@ -196,8 +196,7 @@ class SchemaLoader:
directories = [
(
not directory.endswith( # type: ignore
os.sep # type: ignore # retrocompat
+ self.main_schema_directory
os.sep + self.main_schema_directory # type: ignore # retrocompat
)
and join(directory, self.main_schema_directory) # type: ignore
or directory
......@@ -284,8 +283,7 @@ class SchemaLoader:
@deprecation.argument_renamed(old_name="filepath", new_name="file_path")
@deprecation.argument_renamed(old_name="modname", new_name="module_name")
def handle_file(self, file_path: str, module_name: Optional[str] = None) -> None:
"""handle a partial schema definition file according to its extension
"""
"""handle a partial schema definition file according to its extension"""
assert file_path.endswith(".py"), "not a python file"
if file_path not in self.loaded_files:
......
......@@ -629,7 +629,9 @@ class EntitySchema(PermissionMixIn, ERSchema):
@deprecation.argument_renamed(old_name="skiprels", new_name="skip_relations")
def is_subobject(
self, strict: bool = False, skip_relations: Sequence[Tuple["RelationSchema", str]] = (),
self,
strict: bool = False,
skip_relations: Sequence[Tuple["RelationSchema", str]] = (),
) -> bool:
"""return True if this entity type is contained by another. If strict,
return True if this entity type *must* be contained by another.
......@@ -779,8 +781,7 @@ class EntitySchema(PermissionMixIn, ERSchema):
@deprecation.argument_renamed(old_name="rtype", new_name="relation_type")
def vocabulary(self, relation_type: yams_types.DefinitionName) -> Tuple[str, ...]:
"""backward compat return the vocabulary of a subject relation
"""
"""backward compat return the vocabulary of a subject relation"""
constraint = self.relation_definition(relation_type).constraint_by_interface(
IVocabularyConstraint
)
......@@ -795,7 +796,7 @@ class EntitySchema(PermissionMixIn, ERSchema):
class RelationDefinitionSchema(PermissionMixIn):
"""a relation definition is fully caracterized relation, eg
<subject type> <relation type> <object type>
<subject type> <relation type> <object type>
"""
_RPROPERTIES: Dict[str, Any] = {
......@@ -1466,8 +1467,7 @@ class Schema:
@deprecation.argument_renamed(old_name="oldname", new_name="old_name")
@deprecation.argument_renamed(old_name="newname", new_name="new_name")
def rename_entity_type(self, old_name: str, new_name: str) -> None:
"""renames an entity type and update internal structures accordingly
"""
"""renames an entity type and update internal structures accordingly"""
entity_schema = self._entities.pop(old_name)
entity_schema.type = new_name
self._entities[new_name] = entity_schema
......
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