19 from cubicweb.web import Redirect |
19 from cubicweb.web import Redirect |
20 |
20 |
21 from cubicweb.devtools import ApptestConfiguration, init_test_database |
21 from cubicweb.devtools import ApptestConfiguration, init_test_database |
22 from cubicweb.devtools.fake import FakeRequest |
22 from cubicweb.devtools.fake import FakeRequest |
23 |
23 |
24 SYSTEM_ENTITIES = ('EGroup', 'EUser', |
24 SYSTEM_ENTITIES = ('CWGroup', 'CWUser', |
25 'EFRDef', 'ENFRDef', |
25 'CWAttribute', 'CWRelation', |
26 'EConstraint', 'EConstraintType', 'EProperty', |
26 'CWConstraint', 'CWConstraintType', 'CWProperty', |
27 'EEType', 'ERType', |
27 'CWEType', 'CWRType', |
28 'State', 'Transition', 'TrInfo', |
28 'State', 'Transition', 'TrInfo', |
29 'RQLExpression', |
29 'RQLExpression', |
30 ) |
30 ) |
31 SYSTEM_RELATIONS = ( |
31 SYSTEM_RELATIONS = ( |
32 # virtual relation |
32 # virtual relation |
48 # deducted from other relations |
48 # deducted from other relations |
49 'primary_email', |
49 'primary_email', |
50 ) |
50 ) |
51 |
51 |
52 def unprotected_entities(app_schema, strict=False): |
52 def unprotected_entities(app_schema, strict=False): |
53 """returned a Set of each non final entity type, excluding EGroup, and EUser... |
53 """returned a Set of each non final entity type, excluding CWGroup, and CWUser... |
54 """ |
54 """ |
55 if strict: |
55 if strict: |
56 protected_entities = yams.schema.BASE_TYPES |
56 protected_entities = yams.schema.BASE_TYPES |
57 else: |
57 else: |
58 protected_entities = yams.schema.BASE_TYPES.union(set(SYSTEM_ENTITIES)) |
58 protected_entities = yams.schema.BASE_TYPES.union(set(SYSTEM_ENTITIES)) |
88 self.app = CubicWebPublisher(config, vreg=vreg) |
88 self.app = CubicWebPublisher(config, vreg=vreg) |
89 self.verbose = verbose |
89 self.verbose = verbose |
90 schema = self.vreg.schema |
90 schema = self.vreg.schema |
91 # else we may run into problems since email address are ususally share in app tests |
91 # else we may run into problems since email address are ususally share in app tests |
92 # XXX should not be necessary anymore |
92 # XXX should not be necessary anymore |
93 schema.rschema('primary_email').set_rproperty('EUser', 'EmailAddress', 'composite', False) |
93 schema.rschema('primary_email').set_rproperty('CWUser', 'EmailAddress', 'composite', False) |
94 self.deletable_entities = unprotected_entities(schema) |
94 self.deletable_entities = unprotected_entities(schema) |
95 |
95 |
96 def restore_database(self): |
96 def restore_database(self): |
97 """called by unittests' tearDown to restore the original database |
97 """called by unittests' tearDown to restore the original database |
98 """ |
98 """ |
117 |
117 |
118 |
118 |
119 def create_user(self, login, groups=('users',), req=None): |
119 def create_user(self, login, groups=('users',), req=None): |
120 req = req or self.create_request() |
120 req = req or self.create_request() |
121 cursor = self._orig_cnx.cursor(req) |
121 cursor = self._orig_cnx.cursor(req) |
122 rset = cursor.execute('INSERT EUser X: X login %(login)s, X upassword %(passwd)s,' |
122 rset = cursor.execute('INSERT CWUser X: X login %(login)s, X upassword %(passwd)s,' |
123 'X in_state S WHERE S name "activated"', |
123 'X in_state S WHERE S name "activated"', |
124 {'login': unicode(login), 'passwd': login.encode('utf8')}) |
124 {'login': unicode(login), 'passwd': login.encode('utf8')}) |
125 user = rset.get_entity(0, 0) |
125 user = rset.get_entity(0, 0) |
126 cursor.execute('SET X in_group G WHERE X eid %%(x)s, G name IN(%s)' |
126 cursor.execute('SET X in_group G WHERE X eid %%(x)s, G name IN(%s)' |
127 % ','.join(repr(g) for g in groups), |
127 % ','.join(repr(g) for g in groups), |