Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
7e62363f
Commit
7e62363f
authored
7 years ago
by
yvesn
Browse files
Options
Downloads
Patches
Plain Diff
obis: fixed some tests
parent
834e3b3e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/python/OBis/obis/dm/data_mgmt_test.py
+16
-16
16 additions, 16 deletions
src/python/OBis/obis/dm/data_mgmt_test.py
with
16 additions
and
16 deletions
src/python/OBis/obis/dm/data_mgmt_test.py
+
16
−
16
View file @
7e62363f
...
@@ -18,6 +18,7 @@ import hashlib
...
@@ -18,6 +18,7 @@ import hashlib
from
datetime
import
datetime
from
datetime
import
datetime
from
.
import
data_mgmt
from
.
import
data_mgmt
from
.
import
git
from
.
import
utils
from
.
import
utils
from
.
import
CommandResult
from
.
import
CommandResult
from
unittest.mock
import
Mock
,
MagicMock
,
ANY
from
unittest.mock
import
Mock
,
MagicMock
,
ANY
...
@@ -109,8 +110,7 @@ def test_data_use_case(tmpdir):
...
@@ -109,8 +110,7 @@ def test_data_use_case(tmpdir):
# The txt files should be in git normally
# The txt files should be in git normally
result
=
utils
.
run_shell
([
'
git
'
,
'
annex
'
,
'
info
'
,
'
text-data.txt
'
])
result
=
utils
.
run_shell
([
'
git
'
,
'
annex
'
,
'
info
'
,
'
text-data.txt
'
])
present_p
=
result
.
output
.
split
(
'
'
)[
-
1
]
assert
'
Not a valid object name
'
in
result
.
output
assert
present_p
==
'
failed
'
result
=
utils
.
run_shell
([
'
git
'
,
'
log
'
,
'
--oneline
'
,
'
text-data.txt
'
])
result
=
utils
.
run_shell
([
'
git
'
,
'
log
'
,
'
--oneline
'
,
'
text-data.txt
'
])
present_p
=
"
"
.
join
(
result
.
output
.
split
(
'
'
)[
1
:])
present_p
=
"
"
.
join
(
result
.
output
.
split
(
'
'
)[
1
:])
assert
present_p
==
'
Added data.
'
assert
present_p
==
'
Added data.
'
...
@@ -152,11 +152,11 @@ def test_child_data_set(tmpdir):
...
@@ -152,11 +152,11 @@ def test_child_data_set(tmpdir):
assert
result
.
returncode
==
0
assert
result
.
returncode
==
0
child_ds_code
=
dm
.
config_resolver
.
config_dict
()[
'
data_set_id
'
]
child_ds_code
=
dm
.
config_resolver
.
config_dict
()[
'
data_set_id
'
]
assert
parent_ds_code
!=
child_ds_code
assert
parent_ds_code
!=
child_ds_code
commit_id
=
dm
.
git_wrapper
.
git_commit_
id
().
output
commit_id
=
dm
.
git_wrapper
.
git_commit_
hash
().
output
repository_id
=
dm
.
config_resolver
.
config_dict
()[
'
repository_id
'
]
repository_id
=
dm
.
config_resolver
.
config_dict
()[
'
repository_id
'
]
# TODO fail
assert
repository_id
is
not
None
assert
repository_id
is
not
None
contents
=
data_mgm
t
.
GitRepoFileInfo
(
dm
.
git_wrapper
).
contents
()
contents
=
gi
t
.
GitRepoFileInfo
(
dm
.
git_wrapper
).
contents
()
check_new_data_set_expectations
(
dm
,
tmp_dir_path
,
commit_id
,
repository_id
,
ANY
,
child_ds_code
,
parent_ds_code
,
check_new_data_set_expectations
(
dm
,
tmp_dir_path
,
commit_id
,
repository_id
,
ANY
,
child_ds_code
,
parent_ds_code
,
properties
,
contents
)
properties
,
contents
)
...
@@ -169,18 +169,18 @@ def test_external_dms_code_and_address():
...
@@ -169,18 +169,18 @@ def test_external_dms_code_and_address():
set_registration_configuration
(
dm
)
set_registration_configuration
(
dm
)
user
=
obis_sync
.
user
()
user
=
obis_sync
.
user
()
hostname
=
socket
.
gethostname
()
hostname
=
socket
.
gethostname
()
expected_edms_id
=
obis_sync
.
external_dms_id
()
result
=
obis_sync
.
git_wrapper
.
git_top_level_path
()
result
=
obis_sync
.
git_wrapper
.
git_top_level_path
()
assert
result
.
failure
()
==
False
assert
result
.
failure
()
==
False
edms_path
,
folder
=
os
.
path
.
split
(
result
.
output
)
edms_path
,
folder
=
os
.
path
.
split
(
result
.
output
)
path_hash
=
hashlib
.
sha1
(
edms_path
.
encode
(
"
utf-8
"
)).
hexdigest
()[
0
:
8
]
if
expected_edms_id
is
None
:
expected_edms_id
=
"
{}-{}-{}
"
.
format
(
user
,
hostname
,
path_hash
).
upper
()
# when
# when
result
,
edms
=
external_data_management_system
=
obis_sync
.
create_external_data_management_system
();
result
=
obis_sync
.
get_or_
create_external_data_management_system
();
# then
# then
assert
result
.
failure
()
==
False
assert
result
.
failure
()
==
False
path_hash
=
hashlib
.
sha1
(
edms_path
.
encode
(
"
utf-8
"
)).
hexdigest
()[
0
:
8
]
dm
.
openbis
.
get_external_data_management_system
.
assert_called_with
(
expected_edms_id
)
expected_edms_id
=
"
{}-{}-{}
"
.
format
(
user
,
hostname
,
path_hash
).
upper
()
expected_edms_address
=
"
{}:/{}
"
.
format
(
hostname
,
edms_path
)
dm
.
openbis
.
create_external_data_management_system
.
assert_called_with
(
expected_edms_id
,
expected_edms_id
,
expected_edms_address
)
def
test_undo_commit_when_sync_fails
(
tmpdir
):
def
test_undo_commit_when_sync_fails
(
tmpdir
):
...
@@ -195,7 +195,7 @@ def test_undo_commit_when_sync_fails(tmpdir):
...
@@ -195,7 +195,7 @@ def test_undo_commit_when_sync_fails(tmpdir):
result
=
dm
.
commit
(
"
Added data.
"
)
result
=
dm
.
commit
(
"
Added data.
"
)
# then
# then
assert
result
.
returncode
==
-
1
assert
result
.
returncode
==
-
1
dm
.
git_wrapper
.
git_
undo_commit
.
assert_called_once
()
dm
.
git_wrapper
.
git_
reset_to
.
assert_called_once
()
# TODO Test that if the data set registration fails, the data_set_id is reverted
# TODO Test that if the data set registration fails, the data_set_id is reverted
...
@@ -216,7 +216,7 @@ def prepare_registration_expectations(dm):
...
@@ -216,7 +216,7 @@ def prepare_registration_expectations(dm):
edms
=
ExternalDMS
(
dm
.
openbis
,
{
'
code
'
:
'
AUSER-MACHINE-ffffffff
'
,
'
label
'
:
'
AUSER-MACHINE-ffffffff
'
})
edms
=
ExternalDMS
(
dm
.
openbis
,
{
'
code
'
:
'
AUSER-MACHINE-ffffffff
'
,
'
label
'
:
'
AUSER-MACHINE-ffffffff
'
})
dm
.
openbis
.
create_external_data_management_system
=
MagicMock
(
return_value
=
edms
)
dm
.
openbis
.
create_external_data_management_system
=
MagicMock
(
return_value
=
edms
)
dm
.
openbis
.
get_external_data_management_system
=
MagicMock
(
return_value
=
edms
)
dm
.
openbis
.
get_external_data_management_system
=
MagicMock
(
return_value
=
edms
)
dm
.
openbis
.
create_permId
=
MagicMock
(
return_value
=
'
DUMMY_DATA_SET_CODE
'
)
dm
.
openbis
.
create_permId
.
side_effect
=
[
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
]
prepare_new_data_set_expectations
(
dm
)
prepare_new_data_set_expectations
(
dm
)
...
@@ -232,9 +232,9 @@ def prepare_new_data_set_expectations(dm, properties={}):
...
@@ -232,9 +232,9 @@ def prepare_new_data_set_expectations(dm, properties={}):
def
check_new_data_set_expectations
(
dm
,
tmp_dir_path
,
commit_id
,
repository_id
,
external_dms
,
data_set_id
,
parent_id
,
properties
,
def
check_new_data_set_expectations
(
dm
,
tmp_dir_path
,
commit_id
,
repository_id
,
external_dms
,
data_set_id
,
parent_id
,
properties
,
contents
):
contents
):
dm
.
openbis
.
new_git_data_set
.
assert_called_with
(
'
DS_TYPE
'
,
tmp_dir_path
,
commit_id
,
repository_id
,
external_dms
,
"
/SAMPLE/ID
"
,
dm
.
openbis
.
new_git_data_set
.
assert_called_with
(
'
DS_TYPE
'
,
tmp_dir_path
,
commit_id
,
repository_id
,
external_dms
,
data_set_code
=
data_set_id
,
parents
=
parent_id
,
properties
=
properties
,
data_set_code
=
data_set_id
,
experiment
=
None
,
parents
=
parent_id
,
properties
=
properties
,
contents
=
contents
)
contents
=
contents
,
sample
=
"
/SAMPLE/ID
"
)
def
copy_test_data
(
tmpdir
):
def
copy_test_data
(
tmpdir
):
...
...
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