[PATCH saem_ref v2] Add a test demonstrating that ARK identifiers are not unique overall

Denis Laxalde denis.laxalde at logilab.fr
Mon Feb 19 10:11:56 CET 2018


Frank Bessou a écrit :
> 
> 
> On 19/02/2018 09:48, Denis Laxalde wrote:
>> Frank Bessou a écrit :
>>> On 16/02/2018 16:14, Denis Laxalde wrote:
>>>> # HG changeset patch
>>>> # User Denis Laxalde <denis.laxalde at logilab.fr>
>>>> # Date 1518510957 -3600
>>>> #      Tue Feb 13 09:35:57 2018 +0100
>>>> # Node ID d934ae52b79d3f27c319687aafca525fde76efdb
>>>> # Parent  4a200f4623e28e2729c07d23cf62772d852ca007
>>>> # Available At http://hg.logilab.org/review/cubes/saem_ref
>>>> #              hg pull http://hg.logilab.org/review/cubes/saem_ref -r
>>>> d934ae52b79d
>>>> # EXP-Topic ark/unique-overall
>>>> Add a test demonstrating that ARK identifiers are not unique overall
>>>>
>>>> diff --git a/test/unittest_schema.py b/test/unittest_schema.py
>>>> --- a/test/unittest_schema.py
>>>> +++ b/test/unittest_schema.py
>>>> @@ -48,6 +48,15 @@ class SchemaConstraintsTC(CubicWebTC):
>>>>       configcls = PostgresApptestConfiguration
>>>>       assertValidationError = testutils.assertValidationError
>>>>   +    def test_ark_unique_overall(self):
>>>> +        # Demonstrate that we can create two entities with the same ARK
>>>> +        # identifier, this is a bug.
>>>> +        with self.admin_access.repo_cnx() as cnx:
>>>> +            authority = testutils.authority_with_naa(cnx)
>>>> +            agent = cnx.create_entity('Agent', name=u'bob',
>>>> authority=authority)
>>>> +            cnx.create_entity('ConceptScheme', ark=agent.ark)
>>>> +            cnx.commit()
>>>> +
>>> Wouldn't it be better to have a failing test and then make it pass (by
>>> fixing the bug) ?. #tdd
>> Sure, but I currently don't know how it should fail... nor do I know how
>> to fix the data model to make it pass. So this test, while not perfect,
>> is better than nothing.
> 
> I suppose that an assertRaise would be enough ? While the test does not
> pass, you can skip the test and when fixing the bug one can refine it to
> handle the correct exception.

assertRaise what and where?
Maybe assertRaise(Exception) but I'm not even sure the underlying code
(data model) would be kept the same...

Skipping a test brings another problem that we might very well forget
about it as it's not executed :)
I actually tried to mark it as @expectedFailure, but this does not work
for some obscure reason I don't have time to investigate...

> The problem here is that the light is green for the test
> *test_ark_unique_overall* but it shouldn't be if the code was working.

I don't think this is a problem. In TDD, it's quite usual to write a
test that demonstrates a broken behavior and then update it along with
the code once there is a fix. This way, when the fix gets implemented,
you clearly see the behavior change *in the patch itself*.

>>>>       def test_published_constraint_on_contact_point(self):
>>>>           """ create two agents: one published P and one not published N.
>>>>               create one OU and check that interface will only show P
>>>> that can become its
>>>>



More information about the saem-devel mailing list