-
Notifications
You must be signed in to change notification settings - Fork 183
[9.0] feat: add scitag support #8263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fstagni
wants to merge
1
commit into
DIRACGrid:integration
Choose a base branch
from
fstagni:90_scitags
base: integration
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/DIRAC/DataManagementSystem/Client/test/Test_FTS3Job.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
from unittest.mock import Mock, patch | ||
|
||
import pytest | ||
|
||
from DIRAC.DataManagementSystem.Client.FTS3Job import get_scitag | ||
|
||
|
||
@pytest.fixture | ||
def sample_json_response(): | ||
"""Sample JSON response for testing.""" | ||
return { | ||
"experiments": [ | ||
{ | ||
"expName": "default", | ||
"expId": 1, | ||
"activities": [ | ||
{"activityName": "default", "activityId": 1}, | ||
{"activityName": "Data Challenge", "activityId": 4}, | ||
], | ||
}, | ||
{ | ||
"expName": "atlas", | ||
"expId": 100, | ||
"activities": [ | ||
{"activityName": "default", "activityId": 1}, | ||
{"activityName": "analysis", "activityId": 2}, | ||
{"activityName": "production", "activityId": 3}, | ||
], | ||
}, | ||
{ | ||
"expName": "cms", | ||
"expId": 200, | ||
"activities": [{"activityName": "default", "activityId": 1}, {"activityName": "mc", "activityId": 4}], | ||
}, | ||
] | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def mock_requests_success(sample_json_response): | ||
"""Mock successful HTTP request.""" | ||
with patch("requests.get") as mock_get: | ||
mock_response = Mock() | ||
mock_response.json.return_value = sample_json_response | ||
mock_response.raise_for_status.return_value = None | ||
mock_get.return_value = mock_response | ||
yield mock_get | ||
|
||
|
||
class TestGetScitag: | ||
def test_valid_vo_and_activity(self, mock_requests_success): | ||
"""Test get_scitag with valid VO and activity.""" | ||
result = get_scitag("atlas", "analysis") | ||
expected = 100 << 6 | 2 # atlas expId=100, analysis activityId=2 | ||
assert result == expected | ||
|
||
def test_valid_vo_no_activity(self, mock_requests_success): | ||
"""Test get_scitag with valid VO but no specific activity (should use default).""" | ||
result = get_scitag("cms") | ||
expected = 200 << 6 | 1 # cms expId=200, default activityId=1 | ||
assert result == expected | ||
|
||
def test_invalid_vo(self, mock_requests_success): | ||
"""Test get_scitag with invalid VO (should use default vo_id=1).""" | ||
result = get_scitag("nonexistent") | ||
expected = 1 << 6 | 1 # default vo_id=1, default activity_id=1 | ||
assert result == expected | ||
|
||
def test_valid_vo_invalid_activity(self, mock_requests_success): | ||
"""Test get_scitag with valid VO but invalid activity.""" | ||
result = get_scitag("atlas", "nonexistent_activity") | ||
expected = 100 << 6 | 1 # atlas expId=100, default activity_id=1 | ||
assert result == expected | ||
|
||
def test_case_insensitive_vo(self, mock_requests_success): | ||
"""Test that VO matching is case insensitive.""" | ||
result = get_scitag("ATLAS", "production") | ||
expected = 100 << 6 | 3 # atlas expId=100, production activityId=3 | ||
assert result == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"vo,activity,expected_vo_id,expected_activity_id", | ||
[ | ||
("atlas", "analysis", 100, 2), | ||
("atlas", "production", 100, 3), | ||
("cms", "mc", 200, 4), | ||
("cms", "default", 200, 1), | ||
("nonexistent", "any", 1, 1), # defaults | ||
("atlas", "nonexistent", 100, 1), # valid vo, invalid activity | ||
], | ||
) | ||
def test_parametrized_scenarios(mock_requests_success, vo, activity, expected_vo_id, expected_activity_id): | ||
"""Parametrized test for various VO and activity combinations.""" | ||
result = get_scitag(vo, activity) | ||
expected = expected_vo_id << 6 | expected_activity_id | ||
assert result == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"vo,expected_result", | ||
[ | ||
("atlas", 100 << 6 | 1), # Should use default activity | ||
("cms", 200 << 6 | 1), # Should use default activity | ||
("unknown", 1 << 6 | 1), # Should use all defaults | ||
], | ||
) | ||
def test_no_activity_parameter(mock_requests_success, vo, expected_result): | ||
"""Test behavior when no activity parameter is provided.""" | ||
result = get_scitag(vo) | ||
assert result == expected_result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.