[PATCH 5 of 7 saem_ref] Add a custom value generator for automatic web tests for "ark" attribute

Denis Laxalde denis.laxalde at logilab.fr
Wed Feb 21 12:03:30 CET 2018

# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1519209699 -3600
#      Wed Feb 21 11:41:39 2018 +0100
# Node ID ce883b461791559111b9bd0fe337d9dfc68aa9ad
# Parent  606373c1a4aaabe08e676b389ab05ca32dd0c59a
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r ce883b461791
# EXP-Topic ark/unique-overall
Add a custom value generator for automatic web tests for "ark" attribute

We will soon require that inserted "ark" attribute match a regexp
pattern. In test_saem_ref.py's automatic web tests, ark attribute values
are automatically generated and will most of the times not match this
regexp. So we need to implement a custom "value generator" for
"ark" attribute so that it matches expected regular expression.

(How does this work? Apparently, the metaclass of ValueGenerator make is
automagically used by AutomaticWebTest subclasses defined in the same

diff --git a/test/test_saem_ref.py b/test/test_saem_ref.py
--- a/test/test_saem_ref.py
+++ b/test/test_saem_ref.py
@@ -16,9 +16,11 @@
 """cubicweb-saem-ref automatic tests"""
 from functools import partial
+import random
 from unittest import TestCase
 from logilab.common import attrdict
+from cubicweb.devtools.fill import ValueGenerator
 from cubicweb.devtools import (
@@ -90,6 +92,15 @@ class ArkURLTC(testlib.CubicWebTC):
             self.fail('entity types not checked {}'.format(ark_etypes))
+class MyValueGenerator(ValueGenerator):
+    def generate_Any_ark(self, entity, index):
+        return '/'.join([
+            ''.join(random.sample('0123456789', 5)),
+            ''.join(random.sample('qwertyuvckj87932141', 10)),
+        ])
 class AutomaticWebTest(testlib.AutomaticWebTest):
     configcls = PostgresApptestConfiguration
     test_ten_each_config = None  # deactivate attempt to auto populate

More information about the saem-devel mailing list