Skip to content

Commit

Permalink
Vultron ActivityStreams Examples: Python (#66)
Browse files Browse the repository at this point in the history
* add examples for activitystreams

* update requirements.txt
  • Loading branch information
ahouseholder authored Jan 29, 2024
1 parent 0c083cc commit d0cfce6
Show file tree
Hide file tree
Showing 15 changed files with 2,148 additions and 120 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dataclasses-json~=0.6.3
dataclasses-json==0.6.3
markdown-exec==1.8.0
mkdocs-include-markdown-plugin==6.0.4
mkdocs-material-extensions==1.3.1
Expand Down
28 changes: 17 additions & 11 deletions test/test_as_vocab/test_actvitities/test_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# (“Third Party Software”). See LICENSE.md for more details.
# Carnegie Mellon®, CERT® and CERT Coordination Center® are registered in the
# U.S. Patent and Trademark Office by Carnegie Mellon University
import json
import unittest
from typing import Type

Expand Down Expand Up @@ -66,8 +65,8 @@ def _test_base_actor_activity(
expect_type: str,
):
for actor_class in ACTOR_CLASSES:
_actor = actor_class()
_case = VulnerabilityCase()
_actor = actor_class(name=actor_class.__name__)
_case = VulnerabilityCase(name=f"{actor_class.__name__} Case")
_object = cls(as_object=_actor, target=_case)

# check activity is correct type
Expand All @@ -79,16 +78,23 @@ def _test_base_actor_activity(

# check json
_json = _object.to_json()
self.assertIn("object", _json)
self.assertIn("type", _json)
self.assertIn("target", _json)
self.assertIn('"object"', _json)
self.assertIn('"type"', _json)
self.assertIn('"target"', _json)

# check json loads back in correctly
reloaded = json.loads(_json)
# the type should be Reject, not RejectActorRecommendation
self.assertEqual(reloaded["type"], expect_type)
self.assertEqual(reloaded["object"], json.loads(_actor.to_json()))
self.assertEqual(reloaded["target"], json.loads(_case.to_json()))
reloaded = cls.from_json(_json)

# the type should be Reject, not RejectActorRecommendation, etc.
self.assertEqual(reloaded.as_type, expect_type)

self.assertEqual(reloaded.as_object.as_id, _actor.as_id)
self.assertEqual(reloaded.as_object.as_type, "Actor")
self.assertEqual(reloaded.as_object.name, actor_class.__name__)

self.assertEqual(reloaded.target.as_id, _case.as_id)
self.assertEqual(reloaded.target.as_type, _case.as_type)
self.assertEqual(reloaded.target.name, _case.name)


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit d0cfce6

Please sign in to comment.