def test_wrap_for_output(): """Test that an output object is wrapped and contains the appropriate content.""" m = catalog.Metadata( **{ 'title': 'my cool catalog', 'last-modified': datetime.now(), 'version': '0.0.1', 'oscal-version': '1.0.0' }) c = catalog.Catalog(metadata=m, uuid=str(uuid4())) wrapped = parser.wrap_for_output(c) assert (wrapped.catalog.metadata.title == c.metadata.title) # Test with target definition t_m = target.Metadata( **{ 'title': 'my cool target definition', 'last-modified': datetime.now(), 'version': '0.0.1', 'oscal-version': '1.0.0' }) t = target.TargetDefinition(metadata=t_m) wrapped = parser.wrap_for_output(t) assert (wrapped.target_definition.metadata.title == t.metadata.title)
def test_broken_tz() -> None: """Deliberately break tz to trigger exception.""" class BrokenTimezone(tzinfo): # TODO: Type annotations here. """Broken TZ class which returns null offset.""" def fromutc(self, dt): return dt def utcoffset(self, dt): return None def dst(self, dt): return dt def tzname(self, dt): return 'Broken' def _isdst(self, dt): return True taz = BrokenTimezone() m = oscatalog.Metadata( **{ 'title': 'My simple catalog', 'last-modified': datetime.now(tz=taz), 'version': '0.0.0', 'oscal-version': '1.0.0-Milestone3' }) catalog = oscatalog.Catalog(metadata=m, uuid=str(uuid4())) with pytest.raises(Exception): jsoned_catalog = catalog.json(exclude_none=True, by_alias=True, indent=2) type(jsoned_catalog)
def test_copy_to(): """Test the copy to functionality.""" # Root variable copy too catalog_title = oscatalog.Title.parse_obj('my_fun_title') target_description = catalog_title.copy_to(ostarget.Description) assert (target_description == catalog_title) target_title = catalog_title.copy_to(ostarget.Title) assert (target_title == catalog_title) # Complex variable c_m = oscatalog.Metadata( **{ 'title': 'My simple catalog', 'last-modified': datetime.now(), 'version': '0.0.0', 'oscal-version': '1.0.0-Milestone3' }) target_metadata = c_m.copy_to(ostarget.Metadata) assert (target_metadata.title == c_m.title) # Non matching object with pytest.raises(Exception): c_m.copy_to(ostarget.Target)
def simple_catalog_with_tz() -> oscatalog.Catalog: """Return a skeleton catalog with datetime.now().""" m = oscatalog.Metadata( **{ 'title': 'My simple catalog', 'last-modified': datetime.now().astimezone(), 'version': '0.0.0', 'oscal-version': '1.0.0-Milestone3' }) catalog = oscatalog.Catalog(metadata=m, uuid=str(uuid4())) return catalog
def test_copy_from() -> None: """Test copy from function.""" m = oscatalog.Metadata( **{ 'title': 'My simple catalog', 'last-modified': datetime.now().astimezone(), 'version': '0.0.0', 'oscal-version': '1.0.0-Milestone3' }) catalog = oscatalog.Catalog(metadata=m, uuid=str(uuid4())) target_md = ostarget.Metadata( **{ 'title': 'My simple target_title', 'last-modified': datetime.now().astimezone(), 'version': '99.0.0', 'oscal-version': '1.0.0-Milestone3' }) catalog.metadata.copy_from(target_md) assert catalog.metadata.title == target_md.title
def test_copy_to() -> None: """Test the copy to functionality.""" # Complex variable c_m = oscatalog.Metadata( **{ 'title': 'My simple catalog', 'last-modified': datetime.now(), 'version': '0.0.0', 'oscal-version': '1.0.0-Milestone3' }) target_metadata = c_m.copy_to(ostarget.Metadata) assert (target_metadata.title == c_m.title) # Non matching object with pytest.raises(err.TrestleError): c_m.copy_to(ostarget.DefinedTarget) # Testing of root fields. This is is subject to change. # component.Remarks (type str) # poam.ParameterValue (type str) # note the testing conducntio remark = component.Remarks(__root__='hello') _ = remark.copy_to(poam.ParameterValue)