Skip to content
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

YDA-5578: add duplicate group check #8

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ python_irodsclient==1.1.1
enum34
six
humanize>=0.5
iteration_utilities==0.11.0
dnspython>=2.2.0
backports.functools-lru-cache>=1.6.4
typing_extensions==4.1.1
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'enum34',
'six',
'humanize>=0.5',
'iteration_utilities==0.11.0',
'dnspython>=2.2.0',
'backports.functools-lru-cache>=1.6.4',
'PyYaml'
Expand Down
3 changes: 3 additions & 0 deletions unit-tests/files/no-duplicates.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
category,subcategory,groupname,manager
test-automation,initial,groupteama,[email protected]
test-automation,initial,groupteamb,[email protected]
5 changes: 5 additions & 0 deletions unit-tests/files/with-duplicates.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
category,subcategory,groupname,manager
test-automation,initial,groupteama,[email protected]
test-automation,initial,groupteamb,[email protected]
test-automation,initial,data-duplicate,[email protected]
test-automation,initial,data-duplicate,[email protected]
11 changes: 10 additions & 1 deletion unit-tests/test_importgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

sys.path.append("../yclienttools")

from importgroups import _get_duplicate_columns, _process_csv_line, parse_csv_file
from importgroups import _get_duplicate_columns, _get_duplicate_groups, _process_csv_line, parse_csv_file


class ImportGroupsTest(TestCase):
Expand Down Expand Up @@ -139,3 +139,12 @@ def test_parse_invalid_csv_file(self, mock_stderr):
# csv that has too many items in the rows compared to the headers
with self.assertRaises(SystemExit):
parse_csv_file("files/more-entries-than-headers.csv", args, "1.9")

def test_parse_duplicate_groups(self):
args = {"offline_check": True}

data_no_duplicates = parse_csv_file("files/no-duplicates.csv", args, "1.9")
self.assertEqual(_get_duplicate_groups(data_no_duplicates), [])

data_with_duplicates = parse_csv_file("files/with-duplicates.csv", args, "1.9")
self.assertEqual(_get_duplicate_groups(data_with_duplicates), ["research-data-duplicate"])
12 changes: 12 additions & 0 deletions yclienttools/importgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import csv
import sys

from iteration_utilities import duplicates, unique_everseen

from yclienttools import common_args, common_config

from yclienttools import session as s
Expand Down Expand Up @@ -110,6 +112,11 @@ def _get_duplicate_columns(fields_list, yoda_version):
return duplicate_fields


def _get_duplicate_groups(row_data):
group_names = list(map(lambda r: r[2], row_data))
return list(unique_everseen(duplicates(group_names)))


def _process_csv_line(line, args, yoda_version):
if ('category' not in line or not len(line['category'])
or 'subcategory' not in line or not len(line['subcategory'])
Expand Down Expand Up @@ -387,6 +394,11 @@ def entry():
_exit_with_error(
"The --creator-user and --creator-zone options are only supported with Yoda versions 1.9 and higher.")

duplicate_groups = _get_duplicate_groups(data)
if duplicate_groups:
_exit_with_error(
"The group list has multiple rows with the same group name(s): " + ",".join(duplicate_groups))

if args.offline_check:
sys.exit(0)

Expand Down