-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTopicList_test.py
More file actions
1171 lines (933 loc) · 32.9 KB
/
TopicList_test.py
File metadata and controls
1171 lines (933 loc) · 32.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Tests for the TopicList class."""
import json
from datetime import datetime
from openproficiency import Topic, TopicList
class TestTopicList:
# Initializers
def test_init_required_params(self):
"""Create a topic list with required."""
# Arrange
owner = "example.com"
name = "example-topics-list"
# Act
topic_list = TopicList(
owner=owner,
name=name,
)
# Assert
assert topic_list.owner == owner
assert topic_list.name == name
assert topic_list.topics == {}
assert topic_list.dependencies == {}
def test_init_with_description(self):
"""Create a topic list with description field."""
# Arrange
owner = "example.com"
name = "example-topics-list"
description = "Features of the GitHub platform"
# Act
topic_list = TopicList(
owner=owner,
name=name,
description=description,
)
# Assert
assert topic_list.owner == owner
assert topic_list.name == name
assert topic_list.description == description
def test_init_with_version(self):
"""Create a topic list with custom version."""
# Arrange
owner = "example.com"
name = "example-topics-list"
version = "2.1.0"
# Act
topic_list = TopicList(
owner=owner,
name=name,
version=version,
)
# Assert
assert topic_list.version == version
def test_init_with_timestamp(self):
"""Create a topic list with custom timestamp."""
# Arrange
owner = "example.com"
name = "example-topics-list"
timestamp = "2025-01-15T10:30:00+00:00"
# Act
topic_list = TopicList(
owner=owner,
name=name,
timestamp=timestamp,
)
# Assert
assert topic_list.timestamp == datetime.fromisoformat(timestamp)
def test_init_with_certificate(self):
"""Create a topic list with custom certificate."""
# Arrange
owner = "example.com"
name = "example-topics-list"
certificate = "cert-12345"
# Act
topic_list = TopicList(
owner=owner,
name=name,
certificate=certificate,
)
# Assert
assert topic_list.certificate == certificate
print("Warning: Certificate format is currently not validated.")
def test_init_timestamp_defaults_to_current_utc(self):
"""Verify timestamp defaults to current UTC when not provided."""
# Act
topic_list = TopicList(
owner="example.com",
name="example",
)
# Assert
assert topic_list.timestamp is not None
assert isinstance(topic_list.timestamp, datetime)
# Should have UTC timezone info
assert topic_list.timestamp.tzinfo is not None
def test_version_default(self):
"""Verify version defaults to None."""
# Act
topic_list = TopicList(
owner="example.com",
name="example",
)
# Assert
assert topic_list.version is None
# Methods
def test_add_topic_string(self):
"""Add a new topic using a string ID."""
# Arrange
topic_list = TopicList(
owner="example.com",
name="example-topics-list",
)
topic_id = "git-commit"
# Act
topic_list.add_topic(topic_id)
# Assert
assert "git-commit" in topic_list.topics
assert isinstance(topic_list.topics["git-commit"], Topic)
def test_add_topic_topic(self):
"""Add a new topic using a Topic instance."""
# Arrange
topic_list = TopicList(
owner="example.com",
name="example-topics-list",
)
topic1 = Topic(
id="git-commit",
description="Storing changes to the Git history",
)
# Act
topic_list.add_topic(topic1)
# Assert
assert "git-commit" in topic_list.topics
assert topic_list.topics["git-commit"] == topic1
def test_get_topic(self):
"""Test retrieving a topic that exists in the list."""
# Arrange
topic_list = TopicList(
owner="example.com",
name="example-topics-list",
)
topic = Topic(id="git-commit")
topic_list.topics[topic.id] = topic
# Act
retrieved = topic_list.get_topic("git-commit")
# Assert
assert retrieved is not None
assert retrieved.id == "git-commit"
def test_get_topic_nonexistent(self):
"""Test retrieving a topic that does not exist in the list."""
# Arrange
topic_list = TopicList(
owner="example.com",
name="example-topics-list",
)
topic = Topic(id="git-commit")
topic_list.topics[topic.id] = topic
# Act
retrieved = topic_list.get_topic("nonexistent")
# Assert
assert retrieved is None
# Properties
def test_full_name(self):
"""Test getting the full name of the topic list."""
# Arrange
owner = "example.com"
name = "example-topic-list"
topic_list = TopicList(
owner=owner,
name=name,
)
# Act
full_name = topic_list.full_name
# Assert
assert full_name == "example.com/example-topic-list"
def test_full_name_with_version(self):
"""Test getting the full name of the topic list, including version."""
# Arrange
owner = "example.com"
name = "example-topic-list"
topic_list = TopicList(
owner=owner,
name=name,
version="1.2.3",
)
# Act
full_name = topic_list.full_name
# Assert
assert full_name == "example.com/example-topic-list@1.2.3"
def test_version_setter_valid_format(self):
"""Test setting version with valid semantic versioning."""
# Arrange
topic_list = TopicList(
owner="example.com",
name="example",
)
# Act
topic_list.version = "3.2.1"
# Assert
assert topic_list.version == "3.2.1"
def test_version_setter_invalid_format_missing_patch(self):
"""Test setting version with invalid format (missing patch number)."""
# Arrange
topic_list = TopicList(
owner="example.com",
name="example",
)
# Act & Assert
try:
topic_list.version = "3.2"
assert False, "Should have raised ValueError"
except ValueError as e:
assert "Invalid version format" in str(e)
assert "Must be semantic versioning" in str(e)
def test_version_setter_invalid_format_extra_component(self):
"""Test setting version with invalid format (too many components)."""
# Arrange
topic_list = TopicList(
owner="example.com",
name="example",
)
# Act
result = None
try:
topic_list.version = "3.2.1.5"
assert False, "Should have raised ValueError"
except Exception as e:
result = e
# Assert
assert isinstance(result, ValueError)
assert "Invalid" in str(result)
def test_version_setter_invalid_format_non_numeric(self):
"""Test setting version with invalid format (non-numeric components)."""
# Arrange
topic_list = TopicList(
owner="example.com",
name="example",
)
# Act
result = None
try:
topic_list.version = "v3.2.1"
assert False, "Should have raised ValueError"
except Exception as e:
result = e
# Assert
assert isinstance(result, ValueError)
assert "Invalid" in str(result)
def test_version_zero_values(self):
"""Test setting version with zero values."""
# Arrange
topic_list = TopicList(
owner="example.com",
name="example",
)
# Act
topic_list.version = "0.0.0"
# Assert
assert topic_list.version == "0.0.0"
# Methods - Class
def test_load_from_json_basic_info(self):
"""Load a list with only list info."""
# Arrange
json_data = """
{
"owner": "example.com",
"name": "example-features"
}
"""
# Act
topic_list = TopicList.from_json(json_data)
# Assert - list details
assert topic_list.owner == "example.com"
assert topic_list.name == "example-features"
def test_load_from_json_optional_inputs(self):
"""Load a list with version, timestamp, and certificate fields."""
# Arrange
json_data = """
{
"owner": "example.com",
"name": "example-features",
"description": "Features of the GitHub platform",
"version": "2.3.1",
"timestamp": "2025-01-15T10:30:00+00:00",
"certificate": "cert-abc123"
}
"""
# Act
topic_list = TopicList.from_json(json_data)
# Assert
assert topic_list.version == "2.3.1"
assert topic_list.timestamp == datetime.fromisoformat("2025-01-15T10:30:00+00:00")
assert topic_list.certificate == "cert-abc123"
def test_load_from_json_simple(self):
"""Load a list with only top-level topics."""
# Arrange
json_data = """
{
"owner": "example.com",
"name": "example-features",
"description": "Features of the GitHub platform",
"topics": {
"actions": {
"description": "Storing changes to the Git history"
},
"repositories": {
"description": "Versioning code with Git repositories"
}
}
}
"""
# Act
topic_list = TopicList.from_json(json_data)
# Assert - topics
assert "actions" in topic_list.topics
assert topic_list.topics["actions"].description == "Storing changes to the Git history"
assert "repositories" in topic_list.topics
assert topic_list.topics["repositories"].description == "Versioning code with Git repositories"
def test_load_from_json_subtopics(self):
"""Load a list with subtopics."""
# Arrange
json_data = """
{
"owner": "example.com",
"name": "example-features",
"description": "Features of the GitHub platform",
"topics": {
"git-branch": {
"description": "Parallel versions of work",
"pretopic": ["git-commit"]
},
"actions": {
"description": "Storing changes to the Git history",
"subtopics": ["git-branch"]
},
"repositories": {
"description": "Versioning code with Git repositories",
"subtopics": [
"commit-history",
"pull-request",
"fork"
]
}
}
}
"""
# Act
topic_list = TopicList.from_json(json_data)
# Assert - topics
assert "actions" in topic_list.topics
assert "git-branch" in topic_list.topics
assert topic_list.topics["git-branch"].description == "Parallel versions of work"
assert "repositories" in topic_list.topics
assert "commit-history" in topic_list.topics
assert "pull-request" in topic_list.topics
assert "fork" in topic_list.topics
def test_load_from_json_subsubtopics(self):
"""Load a list with multiple layers of subtopics."""
# Arrange
json_data = """
{
"owner": "example.com",
"name": "example",
"description": "Features of the GitHub platform",
"topics": {
"repositories": {
"description": "Versioning code with Git repositories",
"subtopics": [
"commit-history",
{
"id": "community-files",
"description": "Essential files for repository community health",
"subtopics": [
"code-of-conduct-file",
"codeowners-file",
"contributing-file",
"license-file",
"readme-file"
]
},
"pull-request",
"fork"
]
}
}
}
"""
# Act
topic_list = TopicList.from_json(json_data)
# Assert
assert "community-files" in topic_list.topics
assert topic_list.topics["community-files"].description == "Essential files for repository community health"
assert "code-of-conduct-file" in topic_list.topics
assert "codeowners-file" in topic_list.topics
assert "contributing-file" in topic_list.topics
assert "license-file" in topic_list.topics
assert "readme-file" in topic_list.topics
def test_load_from_json_pretopics(self):
"""Load a list with subtopics."""
# Arrange
json_data = """
{
"owner": "example.com",
"name": "example-features",
"description": "Features of the GitHub platform",
"topics": {
"actions": {
"description": "Storing changes to the Git history",
"pretopics": ["yaml"]
},
"git-commit": {
"description": "Saving changes to the Git history"
},
"repositories": {
"description": "Versioning code with Git repositories",
"pretopics": [
"git-commit",
"git-push",
"git-pull"
]
}
}
}
"""
# Act
topic_list = TopicList.from_json(json_data)
# Assert - topics
assert "actions" in topic_list.topics
assert topic_list.topics["yaml"].description == "Storing changes to the Git history"
assert "yaml" in topic_list.topics
assert "repositories" in topic_list.topics
assert topic_list.topics["repositories"].description == "Versioning code with Git repositories"
assert "git-commit" in topic_list.topics
assert "git-push" in topic_list.topics
assert "git-pull" in topic_list.topics
def test_load_from_json_prepretopics(self):
"""Load a list with multiple layers of pretopics."""
# Arrange
json_data = """
{
"owner": "example.com",
"name": "example-features",
"description": "Features of the GitHub platform",
"topics": {
"repositories": {
"description": "Versioning code with Git repositories",
"pretopics": [
"git-commit",
{
"id": "git-merge",
"description": "Essential files for repository community health",
"pretopics": [
"git1",
"git2",
"git3"
]
},
"git-pull"
]
}
}
}
"""
# Act
topic_list = TopicList.from_json(json_data)
# Assert - topics
assert "repositories" in topic_list.topics
assert "git-commit" in topic_list.topics
assert topic_list.topics["git-commit"].description == "Versioning code with Git repositories"
assert "git-merge" in topic_list.topics
assert topic_list.topics["git-merge"].description == "Essential files for repository community health"
assert "git1" in topic_list.topics
assert "git2" in topic_list.topics
assert "git3" in topic_list.topics
assert "git-pull" in topic_list.topics
assert topic_list.topics["git-pull"].description == "Versioning code with Git repositories"
def test_to_dict_simple(self):
"""Exporting a simple TopicList to dictionary."""
# Arrange
topic_list = TopicList(
owner="example.com",
name="example-features",
description="Features of the GitHub platform",
)
topic_list.add_topic(
Topic(
id="actions",
description="Storing changes to the Git history",
subtopics=["automation"],
pretopics=["yaml"],
)
)
topic_list.add_topic(
Topic(
id="repositories",
description="Versioning code with Git repositories",
subtopics=["git-clone"],
pretopics=["git-push"],
)
)
# Act
data = topic_list.to_dict()
# Assert - List Info
assert data["owner"] == "example.com"
assert data["name"] == "example-features"
assert data["description"] == "Features of the GitHub platform"
# Assert - Topic 1
assert "actions" in data["topics"]
assert data["topics"]["actions"]["description"] == "Storing changes to the Git history"
assert "automation" in data["topics"]["actions"]["subtopics"]
assert "yaml" in data["topics"]["actions"]["pretopics"]
# Assert - Topic 2
assert "repositories" in data["topics"]
assert data["topics"]["repositories"]["description"] == "Versioning code with Git repositories"
assert "git-clone" in data["topics"]["repositories"]["subtopics"]
assert "git-push" in data["topics"]["repositories"]["pretopics"]
def test_to_dict(self):
"""Test that to_dict excludes optional fields if set to None."""
# Arrange
topic_list = TopicList(
owner="example.com",
name="example-features",
)
# Act
data = topic_list.to_dict()
# Assert
assert "description" not in data
assert "version" not in data
assert "certificate" not in data
def test_to_dict_with_optionals(self):
"""Test that to_dict includes optional fields."""
# Arrange
topic_list = TopicList(
owner="example.com",
name="example-features",
description="Features of the GitHub platform",
version="2.1.0",
timestamp="2025-01-15T10:30:00+00:00",
certificate="cert-xyz789",
)
# Act
data = topic_list.to_dict()
# Assert
assert data["version"] == "2.1.0"
assert data["timestamp"] == "2025-01-15T10:30:00+00:00"
assert data["certificate"] == "cert-xyz789"
def test_json_roundtrip_integrity(self):
"""Test that JSON export/import preserves values."""
# Arrange
original = TopicList(
owner="example.com",
name="example-features",
description="Test description",
version="1.2.3",
timestamp="2025-02-16T14:25:00+00:00",
certificate="cert-example",
)
# Act
json_str = original.to_json()
restored = TopicList.from_json(json_str)
# Assert
assert restored.owner == original.owner
assert restored.name == original.name
assert restored.description == original.description
assert restored.version == original.version
assert restored.timestamp == original.timestamp
assert restored.certificate == original.certificate
def test_to_json_simple(self):
"""Exporting a simple TopicList to JSON string."""
# Arrange
topic_list = TopicList(
owner="example.com",
name="example-features",
description="Features of the GitHub platform",
)
topic_list.add_topic(
Topic(
id="actions",
description="Storing changes to the Git history",
subtopics=["automation"],
pretopics=["yaml"],
)
)
topic_list.add_topic(
Topic(
id="repositories",
description="Versioning code with Git repositories",
subtopics=["git-clone"],
pretopics=["git-push"],
)
)
# Act
json_data = topic_list.to_json()
data = json.loads(json_data)
# Assert - List Info
assert data["owner"] == "example.com"
assert data["name"] == "example-features"
assert data["description"] == "Features of the GitHub platform"
# Assert - Topic 1
assert "actions" in data["topics"]
assert data["topics"]["actions"]["description"] == "Storing changes to the Git history"
assert "automation" in data["topics"]["actions"]["subtopics"]
assert "yaml" in data["topics"]["actions"]["pretopics"]
# Assert - Topic 2
assert "repositories" in data["topics"]
assert data["topics"]["repositories"]["description"] == "Versioning code with Git repositories"
assert "git-clone" in data["topics"]["repositories"]["subtopics"]
assert "git-push" in data["topics"]["repositories"]["pretopics"]
def test_from_json_invalid_type(self):
"""Test that from_json raises TypeError for non-string input."""
# Act
result = None
try:
TopicList.from_json({"owner": "test"})
except Exception as e:
result = e
# Assert
assert isinstance(result, TypeError)
assert "must be a JSON string" in str(result)
def test_from_json_invalid_json(self):
"""Test that from_json raises exception for invalid JSON string."""
# Arrange
invalid_json = "{this is not valid json"
# Act
result = None
try:
TopicList.from_json(invalid_json)
except Exception as e:
result = e
# Assert
assert isinstance(result, json.JSONDecodeError)
assert "Expecting" in str(result)
# Debugging
def test_repr(self):
"""Test string representation of TopicList."""
# Arrange
topic_list = TopicList(
owner="example.com",
name="example-topics-list",
)
topic_list.add_topic("git-commit")
topic_list.add_topic("git-push")
# Act
repr_str = repr(topic_list)
# Assert
assert "TopicList" in repr_str
assert "example.com" in repr_str
assert "example-topics-list" in repr_str
assert "topics_count=2" in repr_str
class TestTopicListIdentifierValidation:
"""Tests for TopicList name and owner validation."""
# Valid TopicList names
def test_valid_name_single_word(self):
"""Test that single word lowercase names are valid."""
# Arrange
owner = "example.com"
name = "example-topic-list"
# Act
topic_list = TopicList(owner=owner, name=name)
# Assert
assert topic_list.name == name
def test_valid_name_kebab_case(self):
"""Test that kebab-case names are valid."""
# Arrange
owner = "example.com"
name = "topic-list"
# Act
topic_list = TopicList(owner=owner, name=name)
# Assert
assert topic_list.name == name
def test_valid_name_with_numbers(self):
"""Test that kebab-case names with numbers are valid."""
# Arrange
owner = "example.com"
name = "python-3"
# Act
topic_list = TopicList(owner=owner, name=name)
# Assert
assert topic_list.name == name
# Invalid TopicList names - construction time
def test_invalid_name_uppercase_construction(self):
"""Test that uppercase letters in name are rejected during construction."""
# Arrange
owner = "example.com"
invalid_name = "GitHub"
# Act
result = None
try:
TopicList(owner=owner, name=invalid_name)
except Exception as e:
result = e
# Assert
assert isinstance(result, ValueError)
assert "kebab-case" in str(result)
def test_invalid_name_underscore_construction(self):
"""Test that underscores in name are rejected during construction."""
# Arrange
owner = "example.com"
invalid_name = "topic_list"
# Act
result = None
try:
TopicList(owner=owner, name=invalid_name)
except Exception as e:
result = e
# Assert
assert isinstance(result, ValueError)
assert "kebab-case" in str(result)
def test_invalid_name_double_hyphen_construction(self):
"""Test that double hyphens in name are rejected during construction."""
# Arrange
owner = "example.com"
invalid_name = "topic--list"
# Act
result = None
try:
TopicList(owner=owner, name=invalid_name)
except Exception as e:
result = e
# Assert
assert isinstance(result, ValueError)
assert "kebab-case" in str(result)
def test_invalid_name_leading_hyphen_construction(self):
"""Test that leading hyphens in name are rejected during construction."""
# Arrange
owner = "example.com"
invalid_name = "-topic"
# Act
result = None
try:
TopicList(owner=owner, name=invalid_name)
except Exception as e:
result = e
# Assert
assert isinstance(result, ValueError)
assert "kebab-case" in str(result)
def test_invalid_name_trailing_hyphen_construction(self):
"""Test that trailing hyphens in name are rejected during construction."""
# Arrange
owner = "example.com"
invalid_name = "topic-"
# Act
result = None
try:
TopicList(owner=owner, name=invalid_name)
except Exception as e:
result = e
# Assert
assert isinstance(result, ValueError)
assert "kebab-case" in str(result)
def test_invalid_name_empty_construction(self):
"""Test that empty name is rejected during construction."""
# Arrange
owner = "example.com"
invalid_name = ""
# Act
result = None
try:
TopicList(owner=owner, name=invalid_name)
except Exception as e:
result = e
# Assert
assert isinstance(result, ValueError)
assert "cannot be empty" in str(result)
# Invalid TopicList names - property update
def test_invalid_name_update(self):
"""Test that invalid names are rejected during property update."""
# Arrange
topic_list = TopicList(
owner="example.com",
name="valid-name",
)
invalid_name = "Invalid_Name"
# Act
result = None
try:
topic_list.name = invalid_name
except Exception as e:
result = e
# Assert
assert isinstance(result, ValueError)
assert "kebab-case" in str(result)
# Valid owners
def test_valid_owner_single_word(self):
"""Test that single word lowercase owners are valid."""
# Arrange
owner = "example.com"
name = "example-topic-list"
# Act
topic_list = TopicList(owner=owner, name=name)
# Assert
assert topic_list.owner == owner
def test_valid_owner_with_hyphen(self):
"""Test that kebab-case owners are valid."""
# Arrange
owner = "acme-corp.com"
name = "example-topic-list"
# Act
topic_list = TopicList(owner=owner, name=name)
# Assert
assert topic_list.owner == owner
def test_valid_owner_domain(self):
"""Test that domain-style owners are valid."""