@@ -374,25 +374,69 @@ def test_load_from_json_prepretopics(self):
374374 assert "git-pull" in topic_list .topics
375375 assert topic_list .topics ["git-pull" ].description == "Versioning code with Git repositories"
376376
377- def test_to_json_simple (self ):
378- """Exporting a simple TopicList to JSON ."""
377+ def test_to_dict_simple (self ):
378+ """Exporting a simple TopicList to dictionary ."""
379379
380380 # Arrange
381381 topic_list = TopicList (
382382 owner = "github" ,
383383 name = "github-features" ,
384384 description = "Features of the GitHub platform" ,
385385 )
386- topic1 = Topic (id = "actions" , description = "Storing changes to the Git history" )
387- topic1 .add_subtopic ("automation" )
388- topic1 .add_pretopic ("yaml" )
386+ topic_list .add_topic (Topic (
387+ id = "actions" ,
388+ description = "Storing changes to the Git history" ,
389+ subtopics = ["automation" ],
390+ pretopics = ["yaml" ]
391+ ))
392+ topic_list .add_topic (Topic (
393+ id = "repositories" ,
394+ description = "Versioning code with Git repositories" ,
395+ subtopics = ["git-clone" ],
396+ pretopics = ["git-push" ]
397+ ))
389398
390- topic2 = Topic (id = "repositories" , description = "Versioning code with Git repositories" )
391- topic2 .add_subtopic ("git-clone" )
392- topic2 .add_pretopic ("git-push" )
399+ # Act
400+ data = topic_list .to_dict ()
393401
394- topic_list .add_topic (topic1 )
395- topic_list .add_topic (topic2 )
402+ # Assert - List Info
403+ assert data ["owner" ] == "github"
404+ assert data ["name" ] == "github-features"
405+ assert data ["description" ] == "Features of the GitHub platform"
406+
407+ # Assert - Topic 1
408+ assert "actions" in data ["topics" ]
409+ assert data ["topics" ]["actions" ]["description" ] == "Storing changes to the Git history"
410+ assert "automation" in data ["topics" ]["actions" ]["subtopics" ]
411+ assert "yaml" in data ["topics" ]["actions" ]["pretopics" ]
412+
413+ # Assert - Topic 2
414+ assert "repositories" in data ["topics" ]
415+ assert data ["topics" ]["repositories" ]["description" ] == "Versioning code with Git repositories"
416+ assert "git-clone" in data ["topics" ]["repositories" ]["subtopics" ]
417+ assert "git-push" in data ["topics" ]["repositories" ]["pretopics" ]
418+
419+ def test_to_json_simple (self ):
420+ """Exporting a simple TopicList to JSON string."""
421+
422+ # Arrange
423+ topic_list = TopicList (
424+ owner = "github" ,
425+ name = "github-features" ,
426+ description = "Features of the GitHub platform" ,
427+ )
428+ topic_list .add_topic (Topic (
429+ id = "actions" ,
430+ description = "Storing changes to the Git history" ,
431+ subtopics = ["automation" ],
432+ pretopics = ["yaml" ]
433+ ))
434+ topic_list .add_topic (Topic (
435+ id = "repositories" ,
436+ description = "Versioning code with Git repositories" ,
437+ subtopics = ["git-clone" ],
438+ pretopics = ["git-push" ]
439+ ))
396440
397441 # Act
398442 json_data = topic_list .to_json ()
0 commit comments