Skip to content

Commit

Permalink
Update test_bitmask.py
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleguido committed Nov 13, 2024
1 parent e3105f6 commit 8fcf1e2
Showing 1 changed file with 3 additions and 27 deletions.
30 changes: 3 additions & 27 deletions impresso/tests/utils/test_bitmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ def test_init_with_int(self):
str(BitMask64(0b101111)),
"0000000000000000000000000000000000000000000000000000000000101111",
)
self.assertEqual(
str(BitMask64(0b101111, reverse=True)),
"0000000000000000000000000000000000000000000000000000000000101111",
)
self.assertEqual(
str(BitMask64(10)),
"0000000000000000000000000000000000000000000000000000000000001010",
Expand All @@ -39,36 +35,16 @@ def test_init_with_int(self):
def test_is_access_allowed_edge_cases(self):
accessor_contents_expectedResult = [
(0b101111, 10, True),
(0b101111, 0b100000000, False),
]
for accessor, content, expected_result in accessor_contents_expectedResult:
accessor_bitmask = BitMask64(accessor, reverse=True)
content_bitmask = BitMask64(content, reverse=True)
accessor_bitmask = BitMask64(accessor)
content_bitmask = BitMask64(content)
result = is_access_allowed(accessor_bitmask, content_bitmask)

print("\nacccessor:\n", str(accessor_bitmask))
print("content:\n", str(content_bitmask))
print("is_access_allowed:", result)

self.assertEqual(
result,
expected_result,
"accessor: {} content: {} expected_result: {} result: {}".format(
accessor, content, expected_result, result
),
)

def test_is_access_allowed_known_cases(self):
self.assertTrue(
is_access_allowed(BitMask64("10000"), BitMask64("1")),
"Content is available, even if the user is not authentified: the content item is available in public domain",
)

self.assertFalse(
is_access_allowed(BitMask64("10000"), BitMask64("10", reverse=True)),
"Content is not available: the user is not authentified, the content item is available only to authentified users",
)

self.assertTrue(
is_access_allowed(BitMask64("11000"), BitMask64("01", reverse=True)),
"Content is available: the user is authentified, the content item is available only to authentified users",
)

0 comments on commit 8fcf1e2

Please sign in to comment.