|
5 | 5 | import tempfile |
6 | 6 | import subprocess |
7 | 7 | import shutil |
| 8 | +from collections import defaultdict |
8 | 9 | from datetime import datetime, timedelta, date |
9 | 10 | import pytest |
10 | 11 | import pytz |
@@ -2893,3 +2894,38 @@ def test_mc_without_login(): |
2893 | 2894 | # without login should not be able to access workspaces |
2894 | 2895 | with pytest.raises(ClientError, match="Authentication information is missing or invalid."): |
2895 | 2896 | mc.workspaces_list() |
| 2897 | + |
| 2898 | +def sort_dict_of_files_by_path(d): |
| 2899 | + return { |
| 2900 | + k: sorted(v, key=lambda f: f["path"]) for k, v in d.items() |
| 2901 | + } |
| 2902 | + |
| 2903 | +def test_changes_handler(mc): |
| 2904 | + """ |
| 2905 | + Test methods of the ChangesHandler class |
| 2906 | + """ |
| 2907 | + # test _split_by_type |
| 2908 | + test_project = "test_changes_handler" |
| 2909 | + project = API_USER + "/" + test_project |
| 2910 | + project_dir = os.path.join(TMP_DIR, test_project) |
| 2911 | + cleanup(mc, project, [project_dir]) |
| 2912 | + shutil.copytree(TEST_DATA_DIR, project_dir) |
| 2913 | + mc.create_project(project) |
| 2914 | + project_info = mc.project_info(project) |
| 2915 | + mp = MerginProject(project_dir) |
| 2916 | + mp.write_metadata(project_dir, project_info) |
| 2917 | + |
| 2918 | + mixed_changes = mp.get_push_changes() |
| 2919 | + changes_handler = ChangesHandler(mc, project_info, mixed_changes) |
| 2920 | + split_changes = changes_handler._split_by_type(mixed_changes) |
| 2921 | + assert len(split_changes) == 2 |
| 2922 | + # all blocking files in the first dict and no blocking file in the second dict |
| 2923 | + assert all(ChangesHandler.is_blocking_file(f) for files in split_changes[0].values() for f in files) |
| 2924 | + assert all(not ChangesHandler.is_blocking_file(f) for files in split_changes[1].values() for f in files) |
| 2925 | + # merge the split changes dicts back into a single dict and check files are the same |
| 2926 | + merged = defaultdict(list) |
| 2927 | + for d in split_changes: |
| 2928 | + for k, v in d.items(): |
| 2929 | + merged[k].extend(v) |
| 2930 | + assert sort_dict_of_files_by_path(merged) == sort_dict_of_files_by_path(mixed_changes) |
| 2931 | + |
0 commit comments