Ejemplo n.º 1
0
 def test_event_without_enough_fields_fails(self):
     """Check that events without data throw an error"""
     with self.assertRaises(ValueError):
         event = Event()
         stream = StringIO()
         event.write_to(stream)
     self.assertTrue(True)
Ejemplo n.º 2
0
 def test_event_without_enough_fields_fails(self):
     """Check that events without data throw an error"""
     with self.assertRaises(ValueError):
         event = Event()
         stream = StringIO()
         event.write_to(stream)
     self.assertTrue(True)
Ejemplo n.º 3
0
    def test_xml_of_event_with_minimal_configuration(self):
        """Generate XML from an event object with a small number of fields,
        and see if it matches what we expect."""
        stream = StringIO()

        event = Event(data="This is a test of the emergency broadcast system.",
                      stanza="fubar",
                      time="%.3f" % 1372187084.000)

        event.write_to(stream)

        constructed = ET.fromstring(stream.getvalue())
        expected = ET.parse(data_open("data/event_minimal.xml")).getroot()

        self.assertTrue(xml_compare(expected, constructed))
Ejemplo n.º 4
0
    def test_xml_of_event_with_minimal_configuration(self):
        """Generate XML from an event object with a small number of fields,
        and see if it matches what we expect."""
        stream = StringIO()

        event = Event(
            data="This is a test of the emergency broadcast system.", stanza="fubar", time="%.3f" % 1372187084.000
        )

        event.write_to(stream)

        constructed = ET.fromstring(stream.getvalue())
        expected = ET.parse(data_open("data/event_minimal.xml")).getroot()

        self.assertTrue(xml_compare(expected, constructed))
Ejemplo n.º 5
0
def test_xml_of_event_with_minimal_configuration(capsys):
    """Generate XML from an event object with a small number of fields,
    and see if it matches what we expect."""

    event = Event(data="This is a test of the emergency broadcast system.",
                  stanza="fubar",
                  time="%.3f" % 1372187084.000)

    event.write_to(sys.stdout)

    captured = capsys.readouterr()
    constructed = ET.fromstring(captured.out)
    with data_open("data/event_minimal.xml") as data:
        expected = ET.parse(data).getroot()

        assert xml_compare(expected, constructed)
Ejemplo n.º 6
0
    def test_xml_of_event_with_more_configuration(self):
        """Generate XML from an even object with all fields set, see if
        it matches what we expect"""
        stream = StringIO()

        event = Event(data="This is a test of the emergency broadcast system.",
                      stanza="fubar",
                      time="%.3f" % 1372274622.493,
                      host="localhost",
                      index="main",
                      source="hilda",
                      sourcetype="misc",
                      done=True,
                      unbroken=True)
        event.write_to(stream)

        constructed = ET.fromstring(stream.getvalue())
        expected = ET.parse(data_open("data/event_maximal.xml")).getroot()

        self.assertTrue(xml_compare(expected, constructed))
Ejemplo n.º 7
0
    def test_xml_of_event_with_more_configuration(self):
        """Generate XML from an even object with all fields set, see if
        it matches what we expect"""
        stream = StringIO()

        event = Event(
            data="This is a test of the emergency broadcast system.",
            stanza="fubar",
            time="%.3f" % 1372274622.493,
            host="localhost",
            index="main",
            source="hilda",
            sourcetype="misc",
            done=True,
            unbroken=True
        )
        event.write_to(stream)

        constructed = ET.fromstring(stream.getvalue())
        expected = ET.parse(data_open("data/event_maximal.xml")).getroot()

        self.assertTrue(xml_compare(expected, constructed))
Ejemplo n.º 8
0
def test_xml_of_event_with_more_configuration(capsys):
    """Generate XML from an even object with all fields set, see if
    it matches what we expect"""

    event = Event(data="This is a test of the emergency broadcast system.",
                  stanza="fubar",
                  time="%.3f" % 1372274622.493,
                  host="localhost",
                  index="main",
                  source="hilda",
                  sourcetype="misc",
                  done=True,
                  unbroken=True)
    event.write_to(sys.stdout)

    captured = capsys.readouterr()

    constructed = ET.fromstring(captured.out)
    with data_open("data/event_maximal.xml") as data:
        expected = ET.parse(data).getroot()

        assert xml_compare(expected, constructed)
Ejemplo n.º 9
0
def test_event_without_enough_fields_fails(capsys):
    """Check that events without data throw an error"""
    with pytest.raises(ValueError), capsys.disabled():
        event = Event()
        event.write_to(sys.stdout)