From d89611dc06c58a3828268d30d8cb32f206a1e3c9 Mon Sep 17 00:00:00 2001 From: Inengs Date: Tue, 3 Mar 2026 10:13:46 +0100 Subject: [PATCH 1/4] tests: add unit tests for AugurUUID and subclasses Signed-off-by: Inengs --- .../test_util/test_augur_uuid.py | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tests/test_tasks/test_task_utilities/test_util/test_augur_uuid.py diff --git a/tests/test_tasks/test_task_utilities/test_util/test_augur_uuid.py b/tests/test_tasks/test_task_utilities/test_util/test_augur_uuid.py new file mode 100644 index 0000000000..0202980dcd --- /dev/null +++ b/tests/test_tasks/test_task_utilities/test_util/test_augur_uuid.py @@ -0,0 +1,86 @@ +import pytest +import uuid +from augur.tasks.util.AugurUUID import AugurUUID, GithubUUID, GitlabUUID, UnresolvableUUID + +# AugurUUID tests + +# this checks whether a brand new AugurUUID object starts as 16 zero bytes +def test_augur_uuid_initializes_with_16_zero_bytes(): + uid = AugurUUID() + assert len(uid.bytes) == 16 + assert all(b == 0 for b in uid.bytes) + +# checks that githubUUID sets its platform number to 1 +def test_github_uuid_platform_is_1(): + uid = GithubUUID() + assert uid["platform"] == 1 + +# checks that gitlabUUID sets its platform number to 2 +def test_gitlab_uuid_platform_is_2(): + uid = GitlabUUID() + assert uid["platform"] == 2 + +def test_unresolvable_uuid_platform_is_0(): + uid = UnresolvableUUID() + assert uid["platform"] == 0 + +# checks the that you can store a value in the user field +def test_github_uuid_set_user(): + uid = GithubUUID() + uid["user"] = 12345 + assert uid["user"] == 12345 + +# checks the that you can store a value in the user field +def test_gitlab_uuid_set_user(): + uid = GitlabUUID() + uid["user"] = 99999 + assert uid["user"] == 99999 + +# checks that to_UUID returs the uuid.UUID object +def test_to_uuid_returns_valid_uuid(): + uid = GithubUUID() + uid["user"] = 15 + result = uid.to_UUID() + assert isinstance(result, uuid.UUID) + +# checks that set_byte correctly rejects a value that is too large +def test_set_byte_raises_on_invalid_value(): + uid = AugurUUID() + with pytest.raises(ValueError): + uid.set_byte(0, 256) # too big for one byte + +# checks that set_byte rejects an index that doesnt exist +def test_set_byte_raises_on_out_of_range_index(): + uid = AugurUUID() + with pytest.raises(IndexError): + uid.set_byte(16, 1) # index 16 is out of bounds + +# checks that 2 UUIDs with the same values are considered equal. +def test_equality(): + uid1 = GithubUUID() + uid2 = GithubUUID() + uid1["user"] = 100 + uid2["user"] = 100 + assert uid1 == uid2 + +# checks that 2 UUIDs with different values are not equal +def test_inequality(): + uid1 = GithubUUID() + uid2 = GithubUUID() + uid1["user"] = 100 + uid2["user"] = 200 + assert uid1 != uid2 + +# checks that writeint correctly rejects a number +def test_write_int_raises_on_overflow(): + uid = GithubUUID() + with pytest.raises(ValueError): + uid["user"] = 99999999999 # too big for 4 bytes + +# checks that the same user produces different user IDs across platforms +def test_github_and_gitlab_different_for_same_user(): + github_uid = GithubUUID() + gitlab_uid = GitlabUUID() + github_uid["user"] = 100 + gitlab_uid["user"] = 100 + assert github_uid != gitlab_uid \ No newline at end of file From c8a61b57ec6e658be089780e59afcbc85daa574d Mon Sep 17 00:00:00 2001 From: Inengs Date: Wed, 4 Mar 2026 01:04:34 +0100 Subject: [PATCH 2/4] tests: add test_augur_uuid.py to pytest testpaths in pyproject.toml Signed-off-by: Inengs --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 1929ca83b0..35f568b477 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -151,6 +151,7 @@ addopts = "-ra -s" testpaths = [ "tests/test_classes", "tests/test_application/test_cli/test_csv_utils.py", + "tests/test_tasks/test_task_utilities/test_util/test_augur_uuid.py", # "tests/test_routes", # runs, but needs a fixture for connecting to the web interface of Augur # "tests/test_metrics", # "tests/test_tasks", From cd2208ad2bc1c0a435002d4768e61081c8c713cc Mon Sep 17 00:00:00 2001 From: Inengs Date: Fri, 6 Mar 2026 07:29:05 +0100 Subject: [PATCH 3/4] tests: add edge case and boundary tests for AugurUUID Signed-off-by: Inengs --- .../test_util/test_augur_uuid.py | 128 +++++++++++++++--- 1 file changed, 112 insertions(+), 16 deletions(-) diff --git a/tests/test_tasks/test_task_utilities/test_util/test_augur_uuid.py b/tests/test_tasks/test_task_utilities/test_util/test_augur_uuid.py index 0202980dcd..2f81a8f84a 100644 --- a/tests/test_tasks/test_task_utilities/test_util/test_augur_uuid.py +++ b/tests/test_tasks/test_task_utilities/test_util/test_augur_uuid.py @@ -20,21 +20,32 @@ def test_gitlab_uuid_platform_is_2(): uid = GitlabUUID() assert uid["platform"] == 2 -def test_unresolvable_uuid_platform_is_0(): - uid = UnresolvableUUID() - assert uid["platform"] == 0 - # checks the that you can store a value in the user field def test_github_uuid_set_user(): uid = GithubUUID() uid["user"] = 12345 assert uid["user"] == 12345 -# checks the that you can store a value in the user field -def test_gitlab_uuid_set_user(): - uid = GitlabUUID() - uid["user"] = 99999 - assert uid["user"] == 99999 +# tests platform_id edge cases +def test_set_platform_id_raises_on_non_integer(): + uid = AugurUUID() + with pytest.raises(ValueError): + uid.set_platform_id("github") + +def test_set_platform_id_raises_on_overflow(): + uid = AugurUUID() + with pytest.raises(ValueError): + uid.set_platform_id(256) # too big for 1 byte + +# checks that writing to one field doesnt accidentally overwrite bytes belonging to another field +def test_fields_dont_overlap(): + uid = GithubUUID() + + uid["user"] = 12345 + uid["repo"] = 99999 + + assert uid["user"] == 12345 + assert uid["repo"] == 99999 # checks that to_UUID returs the uuid.UUID object def test_to_uuid_returns_valid_uuid(): @@ -43,6 +54,46 @@ def test_to_uuid_returns_valid_uuid(): result = uid.to_UUID() assert isinstance(result, uuid.UUID) +# checks the start_byte is within range(0, 16) for set_bytes +def test_set_bytes_raises_on_invalid_start_byte(): + uid = AugurUUID() + with pytest.raises(ValueError): + uid.set_bytes([1, 2, 3], 16) + +# checks that set_bytes correctly raises an error when you write more bytes that will fit in the UUID starting at a given position +def test_set_bytes_raises_on_too_many_bytes(): + uid = AugurUUID() + with pytest.raises(ValueError): + uid.set_bytes([1] * 10, 10) + +# checks that writeint correctly rejects a number +def test_write_int_raises_on_overflow(): + uid = GithubUUID() + with pytest.raises(ValueError): + uid["user"] = 99999999999 # too big for 4 bytes + +def test_write_int_with_non_integer(): + uid = GithubUUID() + + with pytest.raises(ValueError): + uid.write_int("abc", 1, 4) + +def test_write_int_and_get_int_roundtrip(): + uid = AugurUUID() + uid.write_int(65535, 1, 2) + assert uid.get_int(1, 2) == 65535 + +# checks __int__ method +def test_int_conversion(): + uid = AugurUUID() + uid.set_byte(15, 1) + assert int(uid) == 1 + +def test_get_byte_invalid_index(): + uid = AugurUUID() + with pytest.raises(IndexError): + uid.get_byte(20) + # checks that set_byte correctly rejects a value that is too large def test_set_byte_raises_on_invalid_value(): uid = AugurUUID() @@ -55,6 +106,11 @@ def test_set_byte_raises_on_out_of_range_index(): with pytest.raises(IndexError): uid.set_byte(16, 1) # index 16 is out of bounds +def test_set_byte_raises_on_non_integer(): + uid = AugurUUID() + with pytest.raises(ValueError): + uid.set_byte(0, "hello") + # checks that 2 UUIDs with the same values are considered equal. def test_equality(): uid1 = GithubUUID() @@ -71,16 +127,56 @@ def test_inequality(): uid2["user"] = 200 assert uid1 != uid2 -# checks that writeint correctly rejects a number -def test_write_int_raises_on_overflow(): - uid = GithubUUID() - with pytest.raises(ValueError): - uid["user"] = 99999999999 # too big for 4 bytes - # checks that the same user produces different user IDs across platforms def test_github_and_gitlab_different_for_same_user(): github_uid = GithubUUID() gitlab_uid = GitlabUUID() github_uid["user"] = 100 gitlab_uid["user"] = 100 - assert github_uid != gitlab_uid \ No newline at end of file + assert github_uid != gitlab_uid + +# checks the maximum value that fits into user field +def test_user_field_max_value(): + uid = GithubUUID() + uid["user"] = 4294967295 + assert uid["user"] == 4294967295 + +# checks the minimum boundary +def test_user_field_zero_value(): + uid = GithubUUID() + uid["user"] = 0 + assert uid["user"] == 0 + +def test_len_returns_16(): + uid = AugurUUID() + assert len(uid) == 16 + +def test_dict_representation(): + uid = GithubUUID() + uid["user"] = 10 + + result = uid.__dict__() + + assert result["platform"] == 1 + assert result["user"] == 10 + +def test_string_representation(): + uid = GithubUUID() + uid["user"] = 10 + + result = str(uid) + + assert "user" in result + assert "platform" in result + +def test_iteration_over_bytes(): + uid = AugurUUID() + bytes_list = list(uid) + + assert len(bytes_list) == 16 + +def test_setting_same_field_twice(): + uid = GithubUUID() + uid["user"] = 42 + uid["user"] = 100 # overwrite with different value + assert uid["user"] == 100 \ No newline at end of file From c4220f8104157405ad4c3f14dcae701d9855162c Mon Sep 17 00:00:00 2001 From: Inengiye Emmanuel Date: Tue, 17 Mar 2026 18:09:09 +0100 Subject: [PATCH 4/4] Remove redundant UUID tests Signed-off-by: Inengiye Emmanuel --- .../test_util/test_augur_uuid.py | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/tests/test_tasks/test_task_utilities/test_util/test_augur_uuid.py b/tests/test_tasks/test_task_utilities/test_util/test_augur_uuid.py index 2f81a8f84a..a377468e40 100644 --- a/tests/test_tasks/test_task_utilities/test_util/test_augur_uuid.py +++ b/tests/test_tasks/test_task_utilities/test_util/test_augur_uuid.py @@ -135,22 +135,6 @@ def test_github_and_gitlab_different_for_same_user(): gitlab_uid["user"] = 100 assert github_uid != gitlab_uid -# checks the maximum value that fits into user field -def test_user_field_max_value(): - uid = GithubUUID() - uid["user"] = 4294967295 - assert uid["user"] == 4294967295 - -# checks the minimum boundary -def test_user_field_zero_value(): - uid = GithubUUID() - uid["user"] = 0 - assert uid["user"] == 0 - -def test_len_returns_16(): - uid = AugurUUID() - assert len(uid) == 16 - def test_dict_representation(): uid = GithubUUID() uid["user"] = 10 @@ -169,12 +153,6 @@ def test_string_representation(): assert "user" in result assert "platform" in result -def test_iteration_over_bytes(): - uid = AugurUUID() - bytes_list = list(uid) - - assert len(bytes_list) == 16 - def test_setting_same_field_twice(): uid = GithubUUID() uid["user"] = 42