test_describe.py (removed)

Last source

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Module holding BDD tests for isshub Repository code_repository entity."""

import pytest
from pytest import mark
from pytest_bdd import given, parsers, scenario, scenarios, then

from isshub.domain.utils.testing.validation import (
    check_field,
    check_field_not_nullable,
    check_field_value,
    positive_integer_only,
    string_only,
)

from ...namespace.tests.fixtures import namespace
from .fixtures import repository_factory


@mark.parametrize(["value", "exception"], positive_integer_only)
@scenario("../features/describe.feature", "A Repository id is a positive integer")
def test_repository_id_is_a_positive_integer(value, exception):
    pass


@mark.parametrize(["value", "exception"], string_only)
@scenario("../features/describe.feature", "A Repository name is a string")
def test_repository_name_is_a_string(value, exception):
    pass


@mark.parametrize(
    ["value", "exception"],
    [(pytest.lazy_fixture("namespace"), None), ("foo", TypeError), (1, TypeError)],
)
@scenario("../features/describe.feature", "A Repository namespace is a Namespace")
def test_repository_namespace_is_a_namespace(value, exception):
    pass


scenarios("../features/describe.feature")


@given("a Repository")
def repository(repository_factory):
    return repository_factory()


@then(parsers.parse("it must have a field named {field_name:w}"))
def repository_has_field(repository, field_name):
    check_field(repository, field_name)


@then(parsers.parse("its {field_name:w} must be a {field_type}"))
def repository_field_is_of_a_certain_type(
    repository_factory,
    field_name,
    field_type,
    # next args are for parametrize
    value,
    exception,
):
    check_field_value(repository_factory, field_name, value, exception)


@then(parsers.parse("its {field_name:w} cannot be none"))
def repository_field_cannot_be_none(repository_factory, field_name):
    check_field_not_nullable(repository_factory, field_name)

Changes

refactor(core): Rename core domain context to code_repository

Commit
Hash

07e279b370c0924f2b2cf32aea016b307001dfa0

Date

2019-08-15 23:31:33 +0200

Type

Renamed

New path

isshub/domain/contexts/code_repository/entities/repository/tests/test_describe.py

Stats

+1 -1

@@ -1,4 +1,4 @@
-"""Module holding BDD tests for isshub Repository core entity."""
+"""Module holding BDD tests for isshub Repository code_repository entity."""

 import pytest
 from pytest import mark

feat(namespace): Add Namespace entity in core domain context

Commit
Hash

3a2dd3cc6f6de1fa1b03db95eaa357628824f075

Date

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

Type

Modified

Stats

+18 -33

@@ -4,8 +4,15 @@ import pytest
 from pytest import mark
 from pytest_bdd import given, parsers, scenario, scenarios, then

-from isshub.domain.utils.testing.validation import positive_integer_only, string_only
-
+from isshub.domain.utils.testing.validation import (
+    check_field,
+    check_field_not_nullable,
+    check_field_value,
+    positive_integer_only,
+    string_only,
+)
+
+from ...namespace.tests.fixtures import namespace
 from .fixtures import repository_factory


@@ -21,9 +28,12 @@ def test_repository_name_is_a_string(value, exception):
     pass


-@mark.parametrize(["value", "exception"], string_only)
-@scenario("../features/describe.feature", "A Repository namespace is a string")
-def test_repository_namespace_is_a_string(value, exception):
+@mark.parametrize(
+    ["value", "exception"],
+    [(pytest.lazy_fixture("namespace"), None), ("foo", TypeError), (1, TypeError)],
+)
+@scenario("../features/describe.feature", "A Repository namespace is a Namespace")
+def test_repository_namespace_is_a_namespace(value, exception):
     pass


@@ -37,7 +47,7 @@ def repository(repository_factory):

 @then(parsers.parse("it must have a field named {field_name:w}"))
 def repository_has_field(repository, field_name):
-    assert hasattr(repository, field_name)
+    check_field(repository, field_name)


 @then(parsers.parse("its {field_name:w} must be a {field_type}"))
@@ -49,34 +59,9 @@ def repository_field_is_of_a_certain_type(
     value,
     exception,
 ):
-    # `field_type` is ignored: the type must be managed via parametrize at the
-    # scenario level, passing values to test and the exception that must be raised
-    # in case of failure, or `None` if the value is valid
-    if exception:
-        # When creating an instance
-        with pytest.raises(exception):
-            repository_factory(**{field_name: value})
-        # When updating the value
-        repository = repository_factory()
-        setattr(repository, field_name, value)
-        with pytest.raises(exception):
-            repository.validate()
-    else:
-        # When creating an instance
-        repository_factory(**{field_name: value})
-        # When updating the value
-        repository = repository_factory()
-        setattr(repository, field_name, value)
-        repository.validate()
+    check_field_value(repository_factory, field_name, value, exception)


 @then(parsers.parse("its {field_name:w} cannot be none"))
 def repository_field_cannot_be_none(repository_factory, field_name):
-    # When creating an instance
-    with pytest.raises(TypeError):
-        repository_factory(**{field_name: None})
-    # When updating the value
-    repository = repository_factory()
-    repository.id = None
-    with pytest.raises(TypeError):
-        repository.validate()
+    check_field_not_nullable(repository_factory, field_name)

feat(repository): Introduce entities validation (for Repository entity)

Commit
Hash

86ad505796b742a391684e2ef93695fdfb077abb

Date

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

Type

Modified

Stats

+65 -1

@@ -1,10 +1,32 @@
 """Module holding BDD tests for isshub Repository core entity."""

-from pytest_bdd import given, parsers, scenarios, then
+import pytest
+from pytest import mark
+from pytest_bdd import given, parsers, scenario, scenarios, then
+
+from isshub.domain.utils.testing.validation import positive_integer_only, string_only

 from .fixtures import repository_factory


+@mark.parametrize(["value", "exception"], positive_integer_only)
+@scenario("../features/describe.feature", "A Repository id is a positive integer")
+def test_repository_id_is_a_positive_integer(value, exception):
+    pass
+
+
+@mark.parametrize(["value", "exception"], string_only)
+@scenario("../features/describe.feature", "A Repository name is a string")
+def test_repository_name_is_a_string(value, exception):
+    pass
+
+
+@mark.parametrize(["value", "exception"], string_only)
+@scenario("../features/describe.feature", "A Repository namespace is a string")
+def test_repository_namespace_is_a_string(value, exception):
+    pass
+
+
 scenarios("../features/describe.feature")


@@ -16,3 +38,45 @@ def repository(repository_factory):
 @then(parsers.parse("it must have a field named {field_name:w}"))
 def repository_has_field(repository, field_name):
     assert hasattr(repository, field_name)
+
+
+@then(parsers.parse("its {field_name:w} must be a {field_type}"))
+def repository_field_is_of_a_certain_type(
+    repository_factory,
+    field_name,
+    field_type,
+    # next args are for parametrize
+    value,
+    exception,
+):
+    # `field_type` is ignored: the type must be managed via parametrize at the
+    # scenario level, passing values to test and the exception that must be raised
+    # in case of failure, or `None` if the value is valid
+    if exception:
+        # When creating an instance
+        with pytest.raises(exception):
+            repository_factory(**{field_name: value})
+        # When updating the value
+        repository = repository_factory()
+        setattr(repository, field_name, value)
+        with pytest.raises(exception):
+            repository.validate()
+    else:
+        # When creating an instance
+        repository_factory(**{field_name: value})
+        # When updating the value
+        repository = repository_factory()
+        setattr(repository, field_name, value)
+        repository.validate()
+
+
+@then(parsers.parse("its {field_name:w} cannot be none"))
+def repository_field_cannot_be_none(repository_factory, field_name):
+    # When creating an instance
+    with pytest.raises(TypeError):
+        repository_factory(**{field_name: None})
+    # When updating the value
+    repository = repository_factory()
+    repository.id = None
+    with pytest.raises(TypeError):
+        repository.validate()

feat(repository): Add 1st domain context (core) and entity (Repository)

Commit
Hash

37d8930e4da80b776842d3834d6bf81f860c5692

Date

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

Type

Added

Stats

+18 -0

@@ -0,0 +1,18 @@
+"""Module holding BDD tests for isshub Repository core entity."""
+
+from pytest_bdd import given, parsers, scenarios, then
+
+from .fixtures import repository_factory
+
+
+scenarios("../features/describe.feature")
+
+
+@given("a Repository")
+def repository(repository_factory):
+    return repository_factory()
+
+
+@then(parsers.parse("it must have a field named {field_name:w}"))
+def repository_has_field(repository, field_name):
+    assert hasattr(repository, field_name)