web/test/jstests/utils.js
author Julien Cristau <julien.cristau@logilab.fr>
Mon, 29 Jun 2015 16:58:43 +0200
changeset 10463 9add9b7f9df7
parent 8879 982a49239420
permissions -rw-r--r--
[server/test] fix random error in unittest_security When entering a new Connection, we cache the user and its 'login' attribute (with no permissions checking). This test makes 'CWUser.login' unreadable by guests, and then proceeds to make sure the 'anon' user can actually not read any 'login' attribute. However, due to the above cnx initialization, anon's login is actually cached, hence readable. This happens to make the test fail sometimes depending on the order in which CWUser entities are returned, because one of them has .complete() called, which as a side effect sets the attribute cache to None for unreadable attributes. Call .complete() on both entities to reset the login cache. While this is still highly debatable, at least it's consistent.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
function datetuple(d) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
    return [d.getFullYear(), d.getMonth()+1, d.getDate(),
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
	    d.getHours(), d.getMinutes()];
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
}
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
function pprint(obj) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
    print('{');
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     8
    for(k in obj) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     9
	print('  ' + k + ' = ' + obj[k]);
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    10
    }
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
    print('}');
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    12
}
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    13
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    14
function arrayrepr(array) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    15
    return '[' + array.join(', ') + ']';
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    16
}
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    17
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    18
function assertArrayEquals(array1, array2) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    19
    if (array1.length != array2.length) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
	throw new crosscheck.AssertionFailure(array1.join(', ') + ' != ' + array2.join(', '));
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
    }
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
    for (var i=0; i<array1.length; i++) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
	if (array1[i] != array2[i]) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
	    throw new crosscheck.AssertionFailure(arrayrepr(array1) + ' and ' + arrayrepr(array2)
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
						 + ' differs at index ' + i);
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
	}
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
    }
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
}