Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CaosDB Python Integration Tests
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Python Integration Tests
Commits
6e00a770
Commit
6e00a770
authored
4 years ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Update more tests
parent
8809e683
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/test_administration.py
+73
-119
73 additions, 119 deletions
tests/test_administration.py
tests/test_boolean.py
+4
-2
4 additions, 2 deletions
tests/test_boolean.py
tests/test_datatype_inheritance.py
+5
-5
5 additions, 5 deletions
tests/test_datatype_inheritance.py
with
82 additions
and
126 deletions
tests/test_administration.py
+
73
−
119
View file @
6e00a770
...
@@ -28,9 +28,12 @@
...
@@ -28,9 +28,12 @@
from
caosdb
import
(
administration
as
admin
,
get_config
)
from
caosdb
import
(
administration
as
admin
,
get_config
)
from
nose.tools
import
assert_true
,
assert_equal
,
assert_is_not_none
,
with_setup
,
assert_raises
from
nose.tools
import
assert_true
,
assert_equal
,
assert_is_not_none
,
with_setup
,
assert_raises
from
caosdb.exceptions
import
(
ClientErrorException
,
TransactionError
,
from
caosdb.exceptions
import
(
ClientErrorException
,
AuthorizationException
,
LoginFailedException
)
HTTPAuthorizationException
,
LoginFailedException
,
ResourceNotFoundException
)
from
caosdb.connection.connection
import
get_connection
,
configure_connection
from
caosdb.connection.connection
import
get_connection
,
configure_connection
from
pytest
import
raises
test_role
=
"
test_role
"
test_role
=
"
test_role
"
test_user
=
"
test_user
"
test_user
=
"
test_user
"
...
@@ -104,11 +107,9 @@ def test_insert_role_success():
...
@@ -104,11 +107,9 @@ def test_insert_role_success():
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
def
test_insert_role_failure_permission
():
def
test_insert_role_failure_permission
():
switch_to_normal_user
()
switch_to_normal_user
()
with
assert_
raises
(
AuthorizationException
)
as
cm
:
with
raises
(
HTTP
AuthorizationException
)
as
cm
:
admin
.
_insert_role
(
name
=
test_role
,
description
=
test_role_desc
)
admin
.
_insert_role
(
name
=
test_role
,
description
=
test_role_desc
)
assert_equal
(
assert
cm
.
value
.
msg
==
"
You are not permitted to insert a new role.
"
cm
.
exception
.
msg
,
"
You are not permitted to insert a new role.
"
)
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
...
@@ -135,18 +136,16 @@ def test_update_role_success():
...
@@ -135,18 +136,16 @@ def test_update_role_success():
def
test_update_role_failure_permissions
():
def
test_update_role_failure_permissions
():
test_insert_role_success
()
test_insert_role_success
()
switch_to_normal_user
()
switch_to_normal_user
()
with
assert_
raises
(
AuthorizationException
)
as
cm
:
with
raises
(
HTTP
AuthorizationException
)
as
cm
:
admin
.
_update_role
(
name
=
test_role
,
description
=
test_role_desc
+
"
asdf
"
)
admin
.
_update_role
(
name
=
test_role
,
description
=
test_role_desc
+
"
asdf
"
)
assert_equal
(
assert
cm
.
value
.
msg
==
"
You are not permitted to update this role.
"
cm
.
exception
.
msg
,
"
You are not permitted to update this role.
"
)
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
def
test_update_role_failure_non_existing
():
def
test_update_role_failure_non_existing
():
with
assert_raises
(
TransactionError
)
as
cm
:
with
raises
(
ResourceNotFoundException
)
as
cm
:
admin
.
_update_role
(
name
=
test_role
,
description
=
test_role_desc
+
"
asdf
"
)
admin
.
_update_role
(
name
=
test_role
,
description
=
test_role_desc
+
"
asdf
"
)
assert
_equal
(
cm
.
exception
.
msg
,
"
Role does not exist.
"
)
assert
cm
.
value
.
msg
==
"
Role does not exist.
"
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
...
@@ -159,18 +158,16 @@ def test_delete_role_success():
...
@@ -159,18 +158,16 @@ def test_delete_role_success():
def
test_delete_role_failure_permissions
():
def
test_delete_role_failure_permissions
():
test_insert_role_success
()
test_insert_role_success
()
switch_to_normal_user
()
switch_to_normal_user
()
with
assert_
raises
(
AuthorizationException
)
as
cm
:
with
raises
(
HTTP
AuthorizationException
)
as
cm
:
admin
.
_delete_role
(
name
=
test_role
)
admin
.
_delete_role
(
name
=
test_role
)
assert_equal
(
assert
cm
.
value
.
msg
==
"
You are not permitted to delete this role.
"
cm
.
exception
.
msg
,
"
You are not permitted to delete this role.
"
)
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
def
test_delete_role_failure_non_existing
():
def
test_delete_role_failure_non_existing
():
with
assert_raises
(
TransactionError
)
as
cm
:
with
raises
(
ResourceNotFoundException
)
as
cm
:
admin
.
_delete_role
(
name
=
test_role
)
admin
.
_delete_role
(
name
=
test_role
)
assert
_equal
(
cm
.
exception
.
msg
,
"
Role does not exist.
"
)
assert
cm
.
value
.
msg
==
"
Role does not exist.
"
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
...
@@ -184,18 +181,16 @@ def test_retrieve_role_success():
...
@@ -184,18 +181,16 @@ def test_retrieve_role_success():
def
test_retrieve_role_failure_permission
():
def
test_retrieve_role_failure_permission
():
test_insert_role_success
()
test_insert_role_success
()
switch_to_normal_user
()
switch_to_normal_user
()
with
assert_
raises
(
AuthorizationException
)
as
cm
:
with
raises
(
HTTP
AuthorizationException
)
as
cm
:
admin
.
_retrieve_role
(
name
=
test_role
)
admin
.
_retrieve_role
(
name
=
test_role
)
assert_equal
(
assert
cm
.
value
.
msg
==
"
You are not permitted to retrieve this role.
"
cm
.
exception
.
msg
,
"
You are not permitted to retrieve this role.
"
)
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
def
test_retrieve_role_failure_non_existing
():
def
test_retrieve_role_failure_non_existing
():
with
assert_raises
(
TransactionError
)
as
cm
:
with
raises
(
ResourceNotFoundException
)
as
cm
:
admin
.
_retrieve_role
(
name
=
test_role
)
admin
.
_retrieve_role
(
name
=
test_role
)
assert
_equal
(
cm
.
exception
.
msg
,
"
Role does not exist.
"
)
assert
cm
.
value
.
msg
==
"
Role does not exist.
"
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
...
@@ -214,24 +209,22 @@ def test_set_permissions_success():
...
@@ -214,24 +209,22 @@ def test_set_permissions_success():
def
test_set_permissions_failure_permissions
():
def
test_set_permissions_failure_permissions
():
test_insert_role_success
()
test_insert_role_success
()
switch_to_normal_user
()
switch_to_normal_user
()
with
assert_
raises
(
AuthorizationException
)
as
cm
:
with
raises
(
HTTP
AuthorizationException
)
as
cm
:
admin
.
_set_permissions
(
admin
.
_set_permissions
(
role
=
test_role
,
permission_rules
=
[
role
=
test_role
,
permission_rules
=
[
admin
.
PermissionRule
(
admin
.
PermissionRule
(
"
Grant
"
,
"
BLA:BLA:BLA
"
)])
"
Grant
"
,
"
BLA:BLA:BLA
"
)])
assert_equal
(
assert
cm
.
value
.
msg
==
"
You are not permitted to set this role
'
s permissions.
"
cm
.
exception
.
msg
,
"
You are not permitted to set this role
'
s permissions.
"
)
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
def
test_set_permissions_failure_non_existing
():
def
test_set_permissions_failure_non_existing
():
with
assert_raises
(
TransactionError
)
as
cm
:
with
raises
(
ResourceNotFoundException
)
as
cm
:
admin
.
_set_permissions
(
admin
.
_set_permissions
(
role
=
test_role
,
permission_rules
=
[
role
=
test_role
,
permission_rules
=
[
admin
.
PermissionRule
(
admin
.
PermissionRule
(
"
Grant
"
,
"
BLA:BLA:BLA
"
)])
"
Grant
"
,
"
BLA:BLA:BLA
"
)])
assert
_equal
(
cm
.
exception
.
msg
,
"
Role does not exist.
"
)
assert
cm
.
value
.
msg
==
"
Role does not exist.
"
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
...
@@ -246,18 +239,16 @@ def test_get_permissions_success():
...
@@ -246,18 +239,16 @@ def test_get_permissions_success():
def
test_get_permissions_failure_permissions
():
def
test_get_permissions_failure_permissions
():
test_set_permissions_success
()
test_set_permissions_success
()
switch_to_normal_user
()
switch_to_normal_user
()
with
assert_
raises
(
AuthorizationException
)
as
cm
:
with
raises
(
HTTP
AuthorizationException
)
as
cm
:
admin
.
_get_permissions
(
role
=
test_role
)
admin
.
_get_permissions
(
role
=
test_role
)
assert_equal
(
assert
cm
.
value
.
msg
==
"
You are not permitted to retrieve this role
'
s permissions.
"
cm
.
exception
.
msg
,
"
You are not permitted to retrieve this role
'
s permissions.
"
)
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
def
test_get_permissions_failure_non_existing
():
def
test_get_permissions_failure_non_existing
():
with
assert_raises
(
TransactionError
)
as
cm
:
with
raises
(
ResourceNotFoundException
)
as
cm
:
admin
.
_get_permissions
(
role
=
"
non-existing-role
"
)
admin
.
_get_permissions
(
role
=
"
non-existing-role
"
)
assert
_equal
(
cm
.
exception
.
msg
,
"
Role does not exist.
"
)
assert
cm
.
value
.
msg
==
"
Role does not exist.
"
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
...
@@ -272,18 +263,16 @@ def test_get_roles_success():
...
@@ -272,18 +263,16 @@ def test_get_roles_success():
def
test_get_roles_failure_permissions
():
def
test_get_roles_failure_permissions
():
test_insert_role_success
()
test_insert_role_success
()
switch_to_normal_user
()
switch_to_normal_user
()
with
assert_
raises
(
AuthorizationException
)
as
cm
:
with
raises
(
HTTP
AuthorizationException
)
as
cm
:
admin
.
_get_roles
(
username
=
test_user
)
admin
.
_get_roles
(
username
=
test_user
)
assert_equal
(
assert
cm
.
value
.
msg
==
"
You are not permitted to retrieve this user
'
s roles.
"
cm
.
exception
.
msg
,
"
You are not permitted to retrieve this user
'
s roles.
"
)
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
def
test_get_roles_failure_non_existing
():
def
test_get_roles_failure_non_existing
():
with
assert_raises
(
TransactionError
)
as
cm
:
with
raises
(
ResourceNotFoundException
)
as
cm
:
admin
.
_get_roles
(
username
=
"
non-existing-user
"
)
admin
.
_get_roles
(
username
=
"
non-existing-user
"
)
assert
_equal
(
cm
.
exception
.
msg
,
"
User does not exist.
"
)
assert
cm
.
value
.
msg
==
"
User does not exist.
"
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
...
@@ -311,11 +300,9 @@ def test_set_roles_failure_permissions():
...
@@ -311,11 +300,9 @@ def test_set_roles_failure_permissions():
roles
=
{
test_role
}
roles
=
{
test_role
}
roles
.
union
(
roles_old
)
roles
.
union
(
roles_old
)
switch_to_normal_user
()
switch_to_normal_user
()
with
assert_
raises
(
AuthorizationException
)
as
cm
:
with
raises
(
HTTP
AuthorizationException
)
as
cm
:
admin
.
_set_roles
(
username
=
test_user
,
roles
=
roles_old
)
admin
.
_set_roles
(
username
=
test_user
,
roles
=
roles_old
)
assert_equal
(
assert
cm
.
value
.
msg
==
"
You are not permitted to set this user
'
s roles.
"
cm
.
exception
.
msg
,
"
You are not permitted to set this user
'
s roles.
"
)
def
test_set_roles_failure_non_existing_role
():
def
test_set_roles_failure_non_existing_role
():
...
@@ -328,9 +315,9 @@ def test_set_roles_failure_non_existing_role():
...
@@ -328,9 +315,9 @@ def test_set_roles_failure_non_existing_role():
def
test_set_roles_failure_non_existing_user
():
def
test_set_roles_failure_non_existing_user
():
test_insert_role_success
()
test_insert_role_success
()
roles
=
{
test_role
}
roles
=
{
test_role
}
with
assert_raises
(
TransactionError
)
as
cm
:
with
raises
(
ResourceNotFoundException
)
as
cm
:
admin
.
_set_roles
(
username
=
"
non-existing-user
"
,
roles
=
roles
)
admin
.
_set_roles
(
username
=
"
non-existing-user
"
,
roles
=
roles
)
assert
_equal
(
cm
.
exception
.
msg
,
"
User does not exist.
"
)
assert
cm
.
value
.
msg
==
"
User does not exist.
"
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
...
@@ -346,16 +333,14 @@ def test_insert_user_success():
...
@@ -346,16 +333,14 @@ def test_insert_user_success():
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
def
test_insert_user_failure_permissions
():
def
test_insert_user_failure_permissions
():
switch_to_normal_user
()
switch_to_normal_user
()
with
assert_
raises
(
AuthorizationException
)
as
cm
:
with
raises
(
HTTP
AuthorizationException
)
as
cm
:
admin
.
_insert_user
(
admin
.
_insert_user
(
name
=
test_user
,
name
=
test_user
,
password
=
"
secret1P!
"
,
password
=
"
secret1P!
"
,
status
=
"
ACTIVE
"
,
status
=
"
ACTIVE
"
,
email
=
"
email@example.com
"
,
email
=
"
email@example.com
"
,
entity
=
None
)
entity
=
None
)
assert_equal
(
assert
cm
.
value
.
msg
==
"
You are not permitted to insert a new user.
"
cm
.
exception
.
msg
,
"
You are not permitted to insert a new user.
"
)
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
...
@@ -376,18 +361,16 @@ def test_delete_user_success():
...
@@ -376,18 +361,16 @@ def test_delete_user_success():
def
test_delete_user_failure_permissions
():
def
test_delete_user_failure_permissions
():
test_insert_user_success
()
test_insert_user_success
()
switch_to_normal_user
()
switch_to_normal_user
()
with
assert_
raises
(
AuthorizationException
)
as
cm
:
with
raises
(
HTTP
AuthorizationException
)
as
cm
:
admin
.
_delete_user
(
name
=
"
non_existing_user
"
)
admin
.
_delete_user
(
name
=
"
non_existing_user
"
)
assert_equal
(
assert
cm
.
value
.
msg
==
"
You are not permitted to delete this user.
"
cm
.
exception
.
msg
,
"
You are not permitted to delete this user.
"
)
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
def
test_delete_user_failure_non_existing
():
def
test_delete_user_failure_non_existing
():
with
assert_raises
(
TransactionError
)
as
cm
:
with
raises
(
ResourceNotFoundException
)
as
cm
:
admin
.
_delete_user
(
name
=
"
non_existing_user
"
)
admin
.
_delete_user
(
name
=
"
non_existing_user
"
)
assert
_equal
(
cm
.
exception
.
msg
,
"
User does not exist.
"
)
assert
cm
.
value
.
msg
==
"
User does not exist.
"
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
...
@@ -459,15 +442,12 @@ def test_update_user_success_password():
...
@@ -459,15 +442,12 @@ def test_update_user_success_password():
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
def
test_update_user_failure_permissions_status
():
def
test_update_user_failure_permissions_status
():
assert_is_not_none
(
assert
admin
.
_insert_user
(
name
=
test_user
+
"
2
"
,
admin
.
_insert_user
(
password
=
"
secret1P!
"
,
name
=
test_user
+
"
2
"
,
status
=
"
INACTIVE
"
,
password
=
"
secret1P!
"
,
email
=
"
email@example.com
"
,
entity
=
None
)
is
not
None
status
=
"
INACTIVE
"
,
email
=
"
email@example.com
"
,
entity
=
None
))
switch_to_normal_user
()
switch_to_normal_user
()
with
assert_
raises
(
AuthorizationException
)
as
cm
:
with
raises
(
HTTP
AuthorizationException
)
as
cm
:
admin
.
_update_user
(
admin
.
_update_user
(
realm
=
None
,
realm
=
None
,
name
=
test_user
+
"
2
"
,
name
=
test_user
+
"
2
"
,
...
@@ -475,22 +455,16 @@ def test_update_user_failure_permissions_status():
...
@@ -475,22 +455,16 @@ def test_update_user_failure_permissions_status():
status
=
"
ACTIVE
"
,
status
=
"
ACTIVE
"
,
email
=
None
,
email
=
None
,
entity
=
None
)
entity
=
None
)
assert_equal
(
assert
cm
.
value
.
msg
==
"
You are not permitted to update this user.
"
cm
.
exception
.
msg
,
"
You are not permitted to update this user.
"
)
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
def
test_update_user_failure_permissions_email
():
def
test_update_user_failure_permissions_email
():
assert_is_not_none
(
assert
admin
.
_insert_user
(
name
=
test_user
+
"
2
"
,
admin
.
_insert_user
(
password
=
"
secret1P!
"
,
status
=
"
ACTIVE
"
,
name
=
test_user
+
"
2
"
,
email
=
"
email@example.com
"
,
entity
=
None
)
is
not
None
password
=
"
secret1P!
"
,
status
=
"
ACTIVE
"
,
email
=
"
email@example.com
"
,
entity
=
None
))
switch_to_normal_user
()
switch_to_normal_user
()
with
assert_
raises
(
AuthorizationException
)
as
cm
:
with
raises
(
HTTP
AuthorizationException
)
as
cm
:
admin
.
_update_user
(
admin
.
_update_user
(
realm
=
None
,
realm
=
None
,
name
=
test_user
+
"
2
"
,
name
=
test_user
+
"
2
"
,
...
@@ -498,22 +472,16 @@ def test_update_user_failure_permissions_email():
...
@@ -498,22 +472,16 @@ def test_update_user_failure_permissions_email():
status
=
None
,
status
=
None
,
email
=
"
newemail@example.com
"
,
email
=
"
newemail@example.com
"
,
entity
=
None
)
entity
=
None
)
assert_equal
(
assert
cm
.
value
.
msg
==
"
You are not permitted to update this user.
"
cm
.
exception
.
msg
,
"
You are not permitted to update this user.
"
)
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
def
test_update_user_failure_permissions_entity
():
def
test_update_user_failure_permissions_entity
():
assert_is_not_none
(
assert
admin
.
_insert_user
(
name
=
test_user
+
"
2
"
,
admin
.
_insert_user
(
password
=
"
secret1P!
"
,
status
=
"
ACTIVE
"
,
name
=
test_user
+
"
2
"
,
email
=
"
email@example.com
"
,
entity
=
None
)
is
not
None
password
=
"
secret1P!
"
,
status
=
"
ACTIVE
"
,
email
=
"
email@example.com
"
,
entity
=
None
))
switch_to_normal_user
()
switch_to_normal_user
()
with
assert_
raises
(
AuthorizationException
)
as
cm
:
with
raises
(
HTTP
AuthorizationException
)
as
cm
:
admin
.
_update_user
(
admin
.
_update_user
(
realm
=
None
,
realm
=
None
,
name
=
test_user
+
"
2
"
,
name
=
test_user
+
"
2
"
,
...
@@ -521,22 +489,16 @@ def test_update_user_failure_permissions_entity():
...
@@ -521,22 +489,16 @@ def test_update_user_failure_permissions_entity():
status
=
None
,
status
=
None
,
email
=
None
,
email
=
None
,
entity
=
21
)
entity
=
21
)
assert_equal
(
assert
cm
.
value
.
msg
==
"
You are not permitted to update this user.
"
cm
.
exception
.
msg
,
"
You are not permitted to update this user.
"
)
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
def
test_update_user_failure_permissions_password
():
def
test_update_user_failure_permissions_password
():
assert_is_not_none
(
assert
admin
.
_insert_user
(
name
=
test_user
+
"
2
"
,
admin
.
_insert_user
(
password
=
"
secret1P!
"
,
status
=
"
ACTIVE
"
,
name
=
test_user
+
"
2
"
,
email
=
"
email@example.com
"
,
entity
=
None
)
is
not
None
password
=
"
secret1P!
"
,
status
=
"
ACTIVE
"
,
email
=
"
email@example.com
"
,
entity
=
None
))
switch_to_normal_user
()
switch_to_normal_user
()
with
assert_
raises
(
AuthorizationException
)
as
cm
:
with
raises
(
HTTP
AuthorizationException
)
as
cm
:
admin
.
_update_user
(
admin
.
_update_user
(
realm
=
None
,
realm
=
None
,
name
=
test_user
+
"
2
"
,
name
=
test_user
+
"
2
"
,
...
@@ -544,14 +506,12 @@ def test_update_user_failure_permissions_password():
...
@@ -544,14 +506,12 @@ def test_update_user_failure_permissions_password():
status
=
None
,
status
=
None
,
email
=
None
,
email
=
None
,
entity
=
None
)
entity
=
None
)
assert_equal
(
assert
cm
.
value
.
msg
==
"
You are not permitted to update this user.
"
cm
.
exception
.
msg
,
"
You are not permitted to update this user.
"
)
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
def
test_update_user_failure_non_existing_user
():
def
test_update_user_failure_non_existing_user
():
with
assert_raises
(
TransactionError
)
as
cm
:
with
raises
(
ResourceNotFoundException
)
as
cm
:
admin
.
_update_user
(
admin
.
_update_user
(
realm
=
None
,
realm
=
None
,
name
=
"
non-existing-user
"
,
name
=
"
non-existing-user
"
,
...
@@ -559,19 +519,15 @@ def test_update_user_failure_non_existing_user():
...
@@ -559,19 +519,15 @@ def test_update_user_failure_non_existing_user():
status
=
"
ACTIVE
"
,
status
=
"
ACTIVE
"
,
email
=
"
email@example.com
"
,
email
=
"
email@example.com
"
,
entity
=
None
)
entity
=
None
)
assert
_equal
(
cm
.
exception
.
msg
,
"
User does not exist.
"
)
assert
cm
.
value
.
msg
==
"
User does not exist.
"
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
def
test_update_user_failure_non_existing_entity
():
def
test_update_user_failure_non_existing_entity
():
assert_is_not_none
(
assert
admin
.
_insert_user
(
name
=
test_user
+
"
2
"
,
admin
.
_insert_user
(
password
=
"
secret1P!
"
,
status
=
"
ACTIVE
"
,
name
=
test_user
+
"
2
"
,
email
=
"
email@example.com
"
,
entity
=
None
)
is
not
None
password
=
"
secret1P!
"
,
with
raises
(
ClientErrorException
)
as
cm
:
status
=
"
ACTIVE
"
,
email
=
"
email@example.com
"
,
entity
=
None
))
with
assert_raises
(
ClientErrorException
)
as
cm
:
admin
.
_update_user
(
admin
.
_update_user
(
realm
=
None
,
realm
=
None
,
name
=
test_user
+
"
2
"
,
name
=
test_user
+
"
2
"
,
...
@@ -579,7 +535,7 @@ def test_update_user_failure_non_existing_entity():
...
@@ -579,7 +535,7 @@ def test_update_user_failure_non_existing_entity():
status
=
None
,
status
=
None
,
email
=
None
,
email
=
None
,
entity
=
100000
)
entity
=
100000
)
assert
_equal
(
cm
.
exception
.
msg
,
"
Entity does not exist.
"
)
assert
cm
.
value
.
msg
==
"
Entity does not exist.
"
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
...
@@ -592,18 +548,16 @@ def test_retrieve_user_success():
...
@@ -592,18 +548,16 @@ def test_retrieve_user_success():
def
test_retrieve_user_failure_permissions
():
def
test_retrieve_user_failure_permissions
():
test_insert_user_success
()
test_insert_user_success
()
switch_to_normal_user
()
switch_to_normal_user
()
with
assert_
raises
(
AuthorizationException
)
as
cm
:
with
raises
(
HTTP
AuthorizationException
)
as
cm
:
admin
.
_retrieve_user
(
realm
=
None
,
name
=
test_user
+
"
2
"
)
admin
.
_retrieve_user
(
realm
=
None
,
name
=
test_user
+
"
2
"
)
assert_equal
(
assert
cm
.
value
.
msg
==
"
You are not permitted to retrieve this user.
"
cm
.
exception
.
msg
,
"
You are not permitted to retrieve this user.
"
)
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
def
test_retrieve_user_failure_non_existing
():
def
test_retrieve_user_failure_non_existing
():
with
assert_raises
(
TransactionError
)
as
cm
:
with
raises
(
ResourceNotFoundException
)
as
cm
:
admin
.
_retrieve_user
(
realm
=
None
,
name
=
"
non_existing
"
)
admin
.
_retrieve_user
(
realm
=
None
,
name
=
"
non_existing
"
)
assert
_equal
(
cm
.
exception
.
msg
,
"
User does not exist.
"
)
assert
cm
.
value
.
msg
==
"
User does not exist.
"
@with_setup
(
setup
,
teardown
)
@with_setup
(
setup
,
teardown
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_boolean.py
+
4
−
2
View file @
6e00a770
...
@@ -29,7 +29,8 @@
...
@@ -29,7 +29,8 @@
import
caosdb
as
h
import
caosdb
as
h
# @UnresolvedImport
# @UnresolvedImport
from
nose.tools
import
assert_true
,
assert_equal
,
assert_false
,
assert_raises
from
nose.tools
import
assert_true
,
assert_equal
,
assert_false
,
assert_raises
from
caosdb.exceptions
import
EntityError
from
caosdb.exceptions
import
TransactionError
from
pytest
import
raises
def
test_property
():
def
test_property
():
...
@@ -126,7 +127,8 @@ def test_record():
...
@@ -126,7 +127,8 @@ def test_record():
rec3
=
h
.
Record
(
rec3
=
h
.
Record
(
name
=
"
SimpleRecord3
"
).
add_parent
(
rt
).
add_property
(
name
=
"
SimpleRecord3
"
).
add_parent
(
rt
).
add_property
(
p
.
name
,
value
=
"
BLABLA
"
)
p
.
name
,
value
=
"
BLABLA
"
)
assert_raises
(
EntityError
,
rec3
.
insert
)
with
raises
(
TransactionError
):
rec3
.
insert
()
assert_false
(
rec3
.
is_valid
())
assert_false
(
rec3
.
is_valid
())
assert_equal
(
assert_equal
(
...
...
This diff is collapsed.
Click to expand it.
tests/test_datatype_inheritance.py
+
5
−
5
View file @
6e00a770
...
@@ -28,7 +28,8 @@ from caosdb.connection.connection import get_connection
...
@@ -28,7 +28,8 @@ from caosdb.connection.connection import get_connection
# @UnresolvedImport
# @UnresolvedImport
from
nose.tools
import
assert_is_not_none
,
assert_true
,
assert_equal
,
with_setup
from
nose.tools
import
assert_is_not_none
,
assert_true
,
assert_equal
,
with_setup
from
caosdb.exceptions
import
EntityError
from
caosdb.exceptions
import
TransactionError
from
pytest
import
raises
def
setup
():
def
setup
():
...
@@ -150,12 +151,11 @@ def test_datatype_overriding_update():
...
@@ -150,12 +151,11 @@ def test_datatype_overriding_update():
str
(
"
TEXT
"
).
lower
(),
str
(
"
TEXT
"
).
lower
(),
rt
.
get_properties
()[
0
].
datatype
.
lower
())
rt
.
get_properties
()[
0
].
datatype
.
lower
())
try
:
with
raises
(
TransactionError
)
as
te
:
p
.
datatype
=
"
INT
"
p
.
datatype
=
"
INT
"
p
.
update
()
p
.
update
()
raise
AssertionError
(
"
This should raise an EntityError!
"
)
except
EntityError
as
e
:
assert
"
Unknown datatype.
"
==
te
.
value
.
get_errors
()[
0
].
msg
assert_equal
(
"
Unknown datatype.
"
,
e
.
msg
)
p
.
datatype
=
"
INTEGER
"
p
.
datatype
=
"
INTEGER
"
p
.
update
()
p
.
update
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment