Skip to content

tests: add unit tests for AugurUUID and subclasses#3749

Open
Inengs wants to merge 4 commits intoaugurlabs:mainfrom
Inengs:unit-tests/augur-uuid
Open

tests: add unit tests for AugurUUID and subclasses#3749
Inengs wants to merge 4 commits intoaugurlabs:mainfrom
Inengs:unit-tests/augur-uuid

Conversation

@Inengs
Copy link
Copy Markdown

@Inengs Inengs commented Mar 3, 2026

Description

  • Adds unit tests for AugurUUID and its subclasses

Tests cover:

  • Initialization with 16 zero bytes
  • Github and Gitlab produce different UUIDs for same user ID
  • Equality operations
  • Platform ID set correctly for each subclass
  • toUUID() returns valid uuid.UUID object
  • Error handling for invalid values and out of range indexes.

This PR fixes #3744

Notes for Reviewers

Signed commits

  • Yes, I signed my commits.

Signed-off-by: Inengs <inengiyeemmanuel@gmail.com>
@Inengs Inengs requested a review from sgoggins as a code owner March 3, 2026 09:24
# 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

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
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)

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
# checks that githubUUID sets its platform number to 1
def test_github_uuid_platform_is_1():
uid = GithubUUID()
assert uid["platform"] == 1

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
# checks that gitlabUUID sets its platform number to 2
def test_gitlab_uuid_platform_is_2():
uid = GitlabUUID()
assert uid["platform"] == 2

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

def test_unresolvable_uuid_platform_is_0():
uid = UnresolvableUUID()
assert uid["platform"] == 0

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
def test_gitlab_uuid_set_user():
uid = GitlabUUID()
uid["user"] = 99999
assert uid["user"] == 99999

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
uid = GithubUUID()
uid["user"] = 15
result = uid.to_UUID()
assert isinstance(result, uuid.UUID)

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
uid2 = GithubUUID()
uid1["user"] = 100
uid2["user"] = 100
assert uid1 == uid2

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
uid2 = GithubUUID()
uid1["user"] = 100
uid2["user"] = 200
assert uid1 != uid2

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
gitlab_uid = GitlabUUID()
github_uid["user"] = 100
gitlab_uid["user"] = 100
assert github_uid != gitlab_uid No newline at end of file

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
@MoralCode
Copy link
Copy Markdown
Collaborator

MoralCode commented Mar 3, 2026

yeah ignore bandit there

Can you add this test folder/file to the pytest section of pyproject.toml so that it gets run along with the rest of the test cases?

@Inengs
Copy link
Copy Markdown
Author

Inengs commented Mar 3, 2026

Alright I will do that as soon as possible, thank you

Signed-off-by: Inengs <inengiyeemmanuel@gmail.com>
@Inengs
Copy link
Copy Markdown
Author

Inengs commented Mar 4, 2026

Hi, I have added the test file to the pyproject.toml

please let me know if there is anything else needed, thank you!

Copy link
Copy Markdown
Collaborator

@MoralCode MoralCode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Id like to see fewer test cases that just assert that each type's identifier is correct and more tests that exercise the various edge cases and code branches within the logic of AugurUUID (even if you use a GitHubUUID instance for doing the test)

def test_gitlab_uuid_set_user():
uid = GitlabUUID()
uid["user"] = 99999
assert uid["user"] == 99999
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is probably redundant with other tests


def test_unresolvable_uuid_platform_is_0():
uid = UnresolvableUUID()
assert uid["platform"] == 0
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is pretty trivial and therefore not really that helpful

@Inengs
Copy link
Copy Markdown
Author

Inengs commented Mar 6, 2026

Alright, I will make those changes as soon as possible..

Signed-off-by: Inengs <inengiyeemmanuel@gmail.com>
@Inengs
Copy link
Copy Markdown
Author

Inengs commented Mar 6, 2026

Hi, I have updated the tests based on your feedback

please let me know if there is anything else needed, thank you!

Comment on lines +138 to +152
# 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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these tests arent really that helpful

Comment on lines +172 to +176
def test_iteration_over_bytes():
uid = AugurUUID()
bytes_list = list(uid)

assert len(bytes_list) == 16
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is effectively the same as the len() test

Signed-off-by: Inengiye Emmanuel <inengiyeemmanuel@gmail.com>
@Inengs
Copy link
Copy Markdown
Author

Inengs commented Mar 17, 2026

Hi, I have removed the redundant tests.

please let me know if there is anything needed to add, thank you!

@Inengs Inengs requested a review from MoralCode March 30, 2026 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unit test AugurUUID and its subclasses

3 participants