Exemplo n.º 1
0
def _make_sro(object_generator, source_id, rel_type, target_id):
    """
    Make an SRO.

    :param source_id: The ID of the source object (string)
    :param rel_type: The relationship type (string)
    :param target_id: The ID of the target object (string)
    :return: The SRO, as a dict
    """

    rel = object_generator.generate("relationship")
    rel["source_ref"] = source_id
    rel["target_ref"] = target_id
    rel["relationship_type"] = rel_type

    return rel
Exemplo n.º 2
0
def _make_object(object_generator, type_name, overlay_props=None):
    """
    Make an object via an object generator.

    :param object_generator: The generator to use
    :param type_name: The name of a spec, which the generator should recognize
    :param overlay_props: After having generated the object, a dict of
        property names and values which will be overlaid.  This can act to
        override generated property values.
    :return: The object, as a dict
    """

    sdo_dict = object_generator.generate(type_name)

    if overlay_props:
        sdo_dict.update(overlay_props)

    return sdo_dict
Exemplo n.º 3
0
def _make_sighting(object_generator, sighting_of, overlay_props=None):
    """
    Make a Sighting.

    :param sighting_of: A value for the sighting_of_ref property, or None to
        omit that property.
    :param overlay_props: After having generated the object, a dict of
        property names and values which will be overlaid.  This can act to
        override generated property values.
    :return: The sighting, as a dict
    """

    rel = object_generator.generate("sighting")

    if sighting_of:
        rel["sighting_of_ref"] = sighting_of
    if overlay_props:
        rel.update(overlay_props)

    return rel
import pytest
Exemplo n.º 5
0
def test_unrecognized_spec_error(object_generator):
    with pytest.raises(stix2generator.exceptions.SpecificationNotFoundError):
        object_generator.generate("foo")