Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor 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
calibration
pycalibration
Commits
696b3e23
Commit
696b3e23
authored
2 years ago
by
Cyril Danilevski
Committed by
Karim Ahmed
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Update tests to take beamtime dates into account
parent
db4399fc
No related branches found
No related tags found
1 merge request
!725
[webservice] Select partition based on beamtime dates
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_webservice.py
+41
-11
41 additions, 11 deletions
tests/test_webservice.py
with
41 additions
and
11 deletions
tests/test_webservice.py
+
41
−
11
View file @
696b3e23
...
@@ -21,6 +21,21 @@ from webservice.webservice import ( # noqa: import not at top of file
...
@@ -21,6 +21,21 @@ from webservice.webservice import ( # noqa: import not at top of file
config
,
config
,
)
)
VALID_BEAMTIME
=
{
"
begin_at
"
:
(
dt
.
datetime
.
today
()
-
dt
.
timedelta
(
days
=
1
)).
isoformat
(),
"
description
"
:
None
,
"
end_at
"
:
(
dt
.
datetime
.
today
()
+
dt
.
timedelta
(
days
=
1
)).
isoformat
(),
"
flg_available
"
:
True
,
"
id
"
:
772
,
}
INVALID_BEAMTIME
=
{
"
begin_at
"
:
"
1818-05-05T00:00:00.000+02:00
"
,
"
description
"
:
"
Karl
"
,
"
end_at
"
:
"
1883-03-14T00:00:00.000+02:00
"
,
"
flg_available
"
:
True
,
"
id
"
:
773
,
}
@pytest.mark.requires_gpfs
@pytest.mark.requires_gpfs
def
test_check_files
():
def
test_check_files
():
...
@@ -243,22 +258,33 @@ async def test_run_action(mode, cmd, retcode, expected, monkeypatch):
...
@@ -243,22 +258,33 @@ async def test_run_action(mode, cmd, retcode, expected, monkeypatch):
@pytest.mark.asyncio
@pytest.mark.asyncio
@pytest.mark.parametrize
(
@pytest.mark.parametrize
(
'
proposal_number, action, mock_proposal_status, expected_result
'
,
'
proposal_number, action, mock_proposal_status,
mock_beamtimes,
expected_result
'
,
[
[
(
42
,
'
correct
'
,
'
A
'
,
'
upex-middle
'
),
# active
(
42
,
'
correct
'
,
'
A
'
,
[
INVALID_BEAMTIME
,
VALID_BEAMTIME
],
'
upex-middle
'
),
# active
(
'
42
'
,
'
dark
'
,
'
R
'
,
'
upex-high
'
),
# active
(
'
42
'
,
'
dark
'
,
'
R
'
,
[
INVALID_BEAMTIME
,
VALID_BEAMTIME
],
'
upex-high
'
),
# active
(
404
,
'
correct
'
,
'
FR
'
,
'
exfel
'
),
# finished and reviewed
(
404
,
'
correct
'
,
'
FR
'
,
[
INVALID_BEAMTIME
,
VALID_BEAMTIME
],
'
exfel
'
),
# finished and reviewed
(
404
,
'
dark
'
,
'
CLO
'
,
'
exfel
'
),
# closed
(
404
,
'
dark
'
,
'
CLO
'
,
[
INVALID_BEAMTIME
,
VALID_BEAMTIME
],
'
exfel
'
),
# closed
(
42
,
'
correct
'
,
'
A
'
,
[
INVALID_BEAMTIME
,
INVALID_BEAMTIME
],
'
exfel
'
),
# active
(
42
,
'
correct
'
,
'
A
'
,
[
INVALID_BEAMTIME
],
'
exfel
'
),
# active but not in beamtime
(
42
,
'
correct
'
,
'
A
'
,
[
VALID_BEAMTIME
],
'
upex-middle
'
),
# active
(
'
42
'
,
'
dark
'
,
'
R
'
,
[
VALID_BEAMTIME
,
{}],
'
upex-high
'
),
# active
(
42
,
'
correct
'
,
'
A
'
,
[],
'
exfel
'
),
# active, no beatime?
(
42
,
'
correct
'
,
'
A
'
,
None
,
'
exfel
'
),
# active, no beatime?
],
],
)
)
async
def
test_get_slurm_partition
(
proposal_number
,
async
def
test_get_slurm_partition
(
action
,
proposal_number
,
action
,
mock_proposal_status
,
mock_beamtimes
,
expected_result
mock_proposal_status
,
):
expected_result
):
return_value
=
{
"
flg_beamtime_status
"
:
mock_proposal_status
,
}
if
mock_beamtimes
is
not
None
:
# Test that we handle missing field
return_value
[
"
beamtimes
"
]
=
mock_beamtimes
response
=
mock
.
Mock
()
response
=
mock
.
Mock
()
response
.
status_code
=
200
response
.
status_code
=
200
response
.
json
=
mock
.
Mock
(
return_value
=
{
'
flg_beamtime_status
'
:
mock_proposal_status
}
)
response
.
json
=
mock
.
Mock
(
return_value
=
return_value
)
client
=
mock
.
Mock
()
client
=
mock
.
Mock
()
client
.
get_proposal_by_number_api
=
mock
.
Mock
(
client
.
get_proposal_by_number_api
=
mock
.
Mock
(
return_value
=
response
)
return_value
=
response
)
...
@@ -295,7 +321,11 @@ async def test_get_slurm_partition_run_age(
...
@@ -295,7 +321,11 @@ async def test_get_slurm_partition_run_age(
# response for `get_proposal_by_number_api` AND `get_run_by_id_api`
# response for `get_proposal_by_number_api` AND `get_run_by_id_api`
response
=
mock
.
Mock
()
response
=
mock
.
Mock
()
response
.
status_code
=
200
response
.
status_code
=
200
response
.
json
=
lambda
:
{
"
flg_beamtime_status
"
:
"
A
"
,
"
begin_at
"
:
run_str
}
response
.
json
=
lambda
:
{
"
flg_beamtime_status
"
:
"
A
"
,
"
begin_at
"
:
run_str
,
"
beamtimes
"
:
[
INVALID_BEAMTIME
,
VALID_BEAMTIME
],
}
client
=
mock
.
Mock
()
client
=
mock
.
Mock
()
client
.
get_proposal_by_number_api
=
mock
.
Mock
(
return_value
=
response
)
client
.
get_proposal_by_number_api
=
mock
.
Mock
(
return_value
=
response
)
...
...
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