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

refactor test_issue_345 #415

Merged
merged 4 commits into from
Sep 28, 2022
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
12 changes: 0 additions & 12 deletions src/icalendar/tests/test_fixed_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,18 +373,6 @@ def test_issue_237(self):
self.assertEqual(dtstart.tzinfo.zone, expected_zone)
self.assertEqual(dtstart.tzname(), expected_tzname)

def test_issue_345(self):
"""Issue #345 - Why is tools.UIDGenerator a class (that must be instantiated) instead of a module? """
uid1 = icalendar.tools.UIDGenerator.uid()
uid2 = icalendar.tools.UIDGenerator.uid('test.test')
uid3 = icalendar.tools.UIDGenerator.uid(unique='123')
Copy link
Member

Choose a reason for hiding this comment

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

The tests are missing these cases:

  • one argument host_name
  • one argument unique
  • no arguments

Copy link
Member

Choose a reason for hiding this comment

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

I create a PR for that...

Copy link
Member

Choose a reason for hiding this comment

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

uid4 = icalendar.tools.UIDGenerator.uid('test.test', '123')

self.assertEqual(uid1.split('@')[1], 'example.com')
self.assertEqual(uid2.split('@')[1], 'test.test')
self.assertEqual(uid3.split('-')[1], '123@example.com')
self.assertEqual(uid4.split('-')[1], '123@test.test')

@pytest.mark.parametrize("zone", [
pytz.utc,
zoneinfo.ZoneInfo('UTC'),
Expand Down
28 changes: 27 additions & 1 deletion src/icalendar/tests/test_unit_tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import unittest
from icalendar.tools import UIDGenerator

from icalendar.tools import UIDGenerator

class TestTools(unittest.TestCase):

Expand All @@ -26,3 +27,28 @@ def test_tools_UIDGenerator(self):
txt = uid.to_ical()
self.assertTrue(len(txt) == length)
self.assertTrue(b'-/path/to/content@Example.ORG' in txt)


@pytest.mark.parametrize('split,expected,args,kw', [
# default argument host_name
("@", "example.com", (), {},),
("@", "example.com", ("example.com",), {}),
("@", "example.com", (), {"host_name":"example.com"}),
# replaced host_name
("@", "test.test", ("test.test",), {}),
("@", "test.test", (), {"host_name":"test.test"}),
# replace unique
("-", "123@example.com", (), {"unique": "123"},),
("-", "abc@example.com", (), {"unique": "abc"},),
# replace host_name and unique
("-", "1234@test.icalendar", (), {"unique": "1234", "host_name":"test.icalendar"},),
("-", "abc@test.example.com", ("test.example.com", "abc"), {},),

])
def test_uid_generator_issue_345(args, kw, split, expected):
'''Issue #345 - Why is tools.UIDGenerator a class (that must be instantiated) instead of a module?

see https://github.com/collective/icalendar/issues/345
'''
uid = UIDGenerator.uid(*args, **kw)
assert uid.split(split)[1] == expected