Skip to content

Commit

Permalink
Remove certain human message assertions from test suites
Browse files Browse the repository at this point in the history
  • Loading branch information
khdesai committed Jul 9, 2019
1 parent ae35d2a commit b464a9c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 62 deletions.
9 changes: 3 additions & 6 deletions stix2/test/v20/test_datastore_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,13 @@ def rel_fs_store():


def test_filesystem_source_nonexistent_folder():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.FileSystemSource('nonexistent-folder')
assert "for STIX data does not exist" in str(excinfo)


def test_filesystem_sink_nonexistent_folder():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.FileSystemSink('nonexistent-folder')
assert "for STIX data does not exist" in str(excinfo)


def test_filesystem_source_bad_json_file(fs_source, bad_json_files):
Expand Down Expand Up @@ -441,9 +439,8 @@ def test_filesystem_attempt_stix_file_overwrite(fs_store):
)

# Now attempt to overwrite the existing file
with pytest.raises(DataSourceError) as excinfo:
with pytest.raises(DataSourceError):
fs_store.add(camp8)
assert "Attempted to overwrite file" in str(excinfo)

os.remove(filepath)

Expand Down
39 changes: 13 additions & 26 deletions stix2/test/v20/test_pattern_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def test_and_observable_expression():


def test_invalid_and_observable_expression():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.AndBooleanExpression([
stix2.EqualityComparisonExpression(
"user-account:display_name",
Expand All @@ -268,7 +268,6 @@ def test_invalid_and_observable_expression():
stix2.StringConstant("admin"),
),
])
assert "All operands to an 'AND' expression must have the same object type" in str(excinfo)


def test_hex():
Expand Down Expand Up @@ -352,30 +351,26 @@ def test_list2():


def test_invalid_constant_type():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.EqualityComparisonExpression(
"artifact:payload_bin",
{'foo': 'bar'},
)
assert 'Unable to create a constant' in str(excinfo)


def test_invalid_integer_constant():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.IntegerConstant('foo')
assert 'must be an integer' in str(excinfo)


def test_invalid_timestamp_constant():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.TimestampConstant('foo')
assert 'Must be a datetime object or timestamp string' in str(excinfo)


def test_invalid_float_constant():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.FloatConstant('foo')
assert 'must be a float' in str(excinfo)


@pytest.mark.parametrize(
Expand All @@ -400,9 +395,8 @@ def test_boolean_constant(data, result):


def test_invalid_boolean_constant():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.BooleanConstant('foo')
assert 'must be a boolean' in str(excinfo)


@pytest.mark.parametrize(
Expand All @@ -412,21 +406,18 @@ def test_invalid_boolean_constant():
],
)
def test_invalid_hash_constant(hashtype, data):
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.HashConstant(data, hashtype)
assert 'is not a valid {} hash'.format(hashtype) in str(excinfo)


def test_invalid_hex_constant():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.HexConstant('mm')
assert "must contain an even number of hexadecimal characters" in str(excinfo)


def test_invalid_binary_constant():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.BinaryConstant('foo')
assert 'must contain a base64' in str(excinfo)


def test_escape_quotes_and_backslashes():
Expand Down Expand Up @@ -459,15 +450,13 @@ def test_repeat_qualifier():


def test_invalid_repeat_qualifier():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.RepeatQualifier('foo')
assert 'is not a valid argument for a Repeat Qualifier' in str(excinfo)


def test_invalid_within_qualifier():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.WithinQualifier('foo')
assert 'is not a valid argument for a Within Qualifier' in str(excinfo)


def test_startstop_qualifier():
Expand All @@ -485,19 +474,17 @@ def test_startstop_qualifier():


def test_invalid_startstop_qualifier():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
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:
with pytest.raises(ValueError):
stix2.StartStopQualifier(
datetime.date(2016, 6, 1),
'foo',
)
assert 'is not a valid argument for a Start/Stop Qualifier' in str(excinfo)


def test_make_constant_already_a_constant():
Expand Down
6 changes: 2 additions & 4 deletions stix2/test/v21/test_datastore_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,13 @@ def rel_fs_store():


def test_filesystem_source_nonexistent_folder():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.FileSystemSource('nonexistent-folder')
assert "for STIX data does not exist" in str(excinfo)


def test_filesystem_sink_nonexistent_folder():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.FileSystemSink('nonexistent-folder')
assert "for STIX data does not exist" in str(excinfo)


def test_filesystem_source_bad_json_file(fs_source, bad_json_files):
Expand Down
39 changes: 13 additions & 26 deletions stix2/test/v21/test_pattern_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def test_and_observable_expression():


def test_invalid_and_observable_expression():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.AndBooleanExpression([
stix2.EqualityComparisonExpression(
"user-account:display_name",
Expand All @@ -268,7 +268,6 @@ def test_invalid_and_observable_expression():
stix2.StringConstant("admin"),
),
])
assert "All operands to an 'AND' expression must have the same object type" in str(excinfo)


def test_hex():
Expand Down Expand Up @@ -352,30 +351,26 @@ def test_list2():


def test_invalid_constant_type():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.EqualityComparisonExpression(
"artifact:payload_bin",
{'foo': 'bar'},
)
assert 'Unable to create a constant' in str(excinfo)


def test_invalid_integer_constant():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.IntegerConstant('foo')
assert 'must be an integer' in str(excinfo)


def test_invalid_timestamp_constant():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.TimestampConstant('foo')
assert 'Must be a datetime object or timestamp string' in str(excinfo)


def test_invalid_float_constant():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.FloatConstant('foo')
assert 'must be a float' in str(excinfo)


@pytest.mark.parametrize(
Expand All @@ -400,9 +395,8 @@ def test_boolean_constant(data, result):


def test_invalid_boolean_constant():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.BooleanConstant('foo')
assert 'must be a boolean' in str(excinfo)


@pytest.mark.parametrize(
Expand All @@ -412,21 +406,18 @@ def test_invalid_boolean_constant():
],
)
def test_invalid_hash_constant(hashtype, data):
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.HashConstant(data, hashtype)
assert 'is not a valid {} hash'.format(hashtype) in str(excinfo)


def test_invalid_hex_constant():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.HexConstant('mm')
assert "must contain an even number of hexadecimal characters" in str(excinfo)


def test_invalid_binary_constant():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.BinaryConstant('foo')
assert 'must contain a base64' in str(excinfo)


def test_escape_quotes_and_backslashes():
Expand Down Expand Up @@ -459,15 +450,13 @@ def test_repeat_qualifier():


def test_invalid_repeat_qualifier():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.RepeatQualifier('foo')
assert 'is not a valid argument for a Repeat Qualifier' in str(excinfo)


def test_invalid_within_qualifier():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
stix2.WithinQualifier('foo')
assert 'is not a valid argument for a Within Qualifier' in str(excinfo)


def test_startstop_qualifier():
Expand All @@ -485,19 +474,17 @@ def test_startstop_qualifier():


def test_invalid_startstop_qualifier():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError):
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:
with pytest.raises(ValueError):
stix2.StartStopQualifier(
datetime.date(2016, 6, 1),
'foo',
)
assert 'is not a valid argument for a Start/Stop Qualifier' in str(excinfo)


def test_make_constant_already_a_constant():
Expand Down

0 comments on commit b464a9c

Please sign in to comment.