feat(namespace): Add Namespace entity a kind field

Description

Abstract

Adds a kind field to the Namespace entity of the core domain context.

Motivation

Even if the name of a namespace is the most important thing, it is useful to know which kind of namespace it is.

Rationale

We use an python Enum as it’s the simplest way to represent a list of choices.

We add a test dependency, fake-enum to easily add the kind field to the Namespace factory.

Info

Hash

a6b70f9e6649bbb656f3df110c0518c583e63336

Date

2019-06-07 21:03:51 +0200

Parents
  • feat(namespace): Add Namespace entity in core domain context [3a2dd3cc]2019-06-07 21:03:50 +0200

Children
  • feat(namespace): Add Namespace entity a `description` field [1568d2fa]2019-06-07 21:03:51 +0200

Branches
Tags

(No tags)

Changes

isshub/domain/contexts/core/entities/namespace/__init__.py

Type

Modified

Stats

+14 -0

@@ -1,5 +1,6 @@
 """Package defining the ``Namespace`` entity."""

+import enum
 from typing import Optional

 from isshub.domain.utils.entity import (
@@ -10,6 +11,14 @@ from isshub.domain.utils.entity import (
 )


+class NamespaceKind(enum.Enum):
+    """All the available kinds of namespace."""
+
+    ORGANIZATION = "Organization"
+    TEAM = "Team"
+    GROUP = "Group"
+
+
 @validated()  # type: ignore
 class _Namespace(BaseModelWithId):
     """A namespace can contain namespace and repositories.
@@ -27,11 +36,14 @@ class _Namespace(BaseModelWithId):
         The name of the namespace. Unique in its parent namespace.
     namespace : Optional[Namespace]
         Where the namespace can be found.
+    kind : NamespaceKind
+        The kind of namespace.

     """

     name: str = required_field(str)  # type: ignore
     namespace = None
+    kind: NamespaceKind = required_field(NamespaceKind)  # type: ignore


 @validated()  # type: ignore
@@ -46,6 +58,8 @@ class Namespace(_Namespace):
         The name of the namespace. Unique in its parent namespace.
     namespace : Optional[str]
         Where the namespace can be found.
+    kind : NamespaceKind
+        The kind of namespace.

     """

isshub/domain/contexts/core/entities/namespace/features/describe.feature

Type

Modified

Stats

+12 -0

@@ -35,3 +35,15 @@ Feature: Describing a Namespace
     Scenario: A Namespace namespace can be None
         Given a Namespace
         Then its namespace can be None
+
+    Scenario: A Namespace has a kind
+        Given a Namespace
+        Then it must have a field named kind
+
+    Scenario: A Namespace kind is a NamespaceKind
+        Given a Namespace
+        Then its kind must be a NamespaceKind
+
+    Scenario: A Namespace kind cannot be None
+        Given a Namespace
+        Then its kind cannot be None

isshub/domain/contexts/core/entities/namespace/tests/factories.py

Type

Modified

Stats

+7 -1

@@ -2,7 +2,12 @@

 import factory

-from isshub.domain.contexts.core.entities.namespace import Namespace
+from faker_enum import EnumProvider
+
+from isshub.domain.contexts.core.entities.namespace import Namespace, NamespaceKind
+
+
+factory.Faker.add_provider(EnumProvider)


 class NamespaceFactory(factory.Factory):
@@ -15,3 +20,4 @@ class NamespaceFactory(factory.Factory):

     id = factory.Faker("pyint", min=1)
     name = factory.Faker("pystr", min_chars=2)
+    kind = factory.Faker("enum", enum_cls=NamespaceKind)

isshub/domain/contexts/core/entities/namespace/tests/test_describe.py

Type

Modified

Stats

+10 -0

@@ -4,6 +4,7 @@ import pytest
 from pytest import mark
 from pytest_bdd import given, parsers, scenario, scenarios, then

+from isshub.domain.contexts.core.entities.namespace import NamespaceKind
 from isshub.domain.utils.testing.validation import (
     check_field,
     check_field_not_nullable,
@@ -37,6 +38,15 @@ def test_namespace_namespace_is_a_namespace(value, exception):
     pass


+@mark.parametrize(
+    ["value", "exception"],
+    [(NamespaceKind.GROUP, None), ("foo", TypeError), (1, TypeError)],
+)
+@scenario("../features/describe.feature", "A Namespace kind is a NamespaceKind")
+def test_namespace_kind_is_a_namespacekind(value, exception):
+    pass
+
+
 scenarios("../features/describe.feature")

setup.cfg

Type

Modified

Stats

+2 -0

@@ -38,6 +38,8 @@ dev =
     mypy
     wheel
 tests =
+    faker
+    faker-enum
     factory-boy
     pytest
     pytest-bdd