def test_startstop_qualifier(): qual = stix2.StartStopQualifier(stix2.TimestampConstant('2016-06-01T00:00:00Z'), datetime.datetime(2017, 3, 12, 8, 30, 0)) assert str(qual) == "START t'2016-06-01T00:00:00Z' STOP t'2017-03-12T08:30:00Z'" qual2 = stix2.StartStopQualifier(datetime.date(2016, 6, 1), stix2.TimestampConstant('2016-07-01T00:00:00Z')) assert str(qual2) == "START t'2016-06-01T00:00:00Z' STOP t'2016-07-01T00:00:00Z'"
def test_invalid_startstop_qualifier(): with pytest.raises(ValueError) as excinfo: stix2.StartStopQualifier( 'foo', stix2.TimestampConstant('2016-06-01T00:00:00Z')) assert 'is not a valid argument for a Start/Stop Qualifier' in str(excinfo) with pytest.raises(ValueError) as excinfo: stix2.StartStopQualifier(datetime.date(2016, 6, 1), 'foo') assert 'is not a valid argument for a Start/Stop Qualifier' in str(excinfo)
def test_invalid_startstop_qualifier(): with pytest.raises(ValueError): stix2.StartStopQualifier( 'foo', stix2.TimestampConstant('2016-06-01T00:00:00Z'), ) with pytest.raises(ValueError): stix2.StartStopQualifier( datetime.date(2016, 6, 1), 'foo', )
def visitTerminal(self, node): if node.symbol.type == STIXPatternParser.IntLiteral: return stix2.IntegerConstant(node.getText()) elif node.symbol.type == STIXPatternParser.FloatLiteral: return stix2.FloatConstant(node.getText()) elif node.symbol.type == STIXPatternParser.HexLiteral: return stix2.HexConstant(node.getText()) elif node.symbol.type == STIXPatternParser.BinaryLiteral: return stix2.BinaryConstant(node.getText()) elif node.symbol.type == STIXPatternParser.StringLiteral: return stix2.StringConstant(node.getText().strip('\'')) elif node.symbol.type == STIXPatternParser.BoolLiteral: return stix2.BooleanConstant(node.getText()) elif node.symbol.type == STIXPatternParser.TimestampLiteral: return stix2.TimestampConstant(node.getText()) # TODO: timestamp else: return node
def test_timestamp(): ts = stix2.TimestampConstant('2014-01-13T07:03:17Z') assert str(ts) == "t'2014-01-13T07:03:17Z'"
def test_invalid_timestamp_constant(): with pytest.raises(ValueError): stix2.TimestampConstant('foo')
def test_invalid_timestamp_constant(): with pytest.raises(ValueError) as excinfo: stix2.TimestampConstant('foo') assert 'must be a datetime object or timestamp string' in str(excinfo)