Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ameliahsu committed Jan 3, 2025
1 parent d67aa9f commit 807821a
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def evaluate_value(job: WorkflowJob, comparison: Any) -> bool:
desired_value = str(desired_value).lower()

# NOTE: IS_SET condition differs btw tagged_event and event_attribute so not handled by match_values
# For event_attribute we need to check that the value of the attribute is not None
if match == MatchType.IS_SET:
return bool(attribute_values)
elif match == MatchType.NOT_SET:
Expand Down Expand Up @@ -144,9 +145,9 @@ def evaluate_value(job: WorkflowJob, comparison: Any) -> bool:
)

# NOTE: IS_SET condition differs btw tagged_event and event_attribute so not handled by match_values
# For tagged_event we need to check that the key exists in the list of all tag_keys
if match == MatchType.IS_SET:
return key in tag_keys

elif match == MatchType.NOT_SET:
return key not in tag_keys

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,20 @@ def test_does_not_error_with_none(self):
}
self.assert_passes(self.dc, self.job)

def test_is_set(self):
self.dc.comparison = {"match": MatchType.IS_SET, "attribute": "platform"}
self.assert_passes(self.dc, self.job)

self.dc.comparison = {"match": MatchType.IS_SET, "attribute": "missing"}
self.assert_does_not_pass(self.dc, self.job)

def test_not_set(self):
self.dc.comparison = {"match": MatchType.NOT_SET, "attribute": "platform"}
self.assert_does_not_pass(self.dc, self.job)

self.dc.comparison = {"match": MatchType.NOT_SET, "attribute": "missing"}
self.assert_passes(self.dc, self.job)

def test_attr_is_in(self):
self.dc.comparison = {
"match": MatchType.IS_IN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def setUp(self):
self.job = WorkflowJob(
{
"event": self.group_event,
"has_reappeared": True,
}
)
self.dc = self.create_data_condition(
Expand Down Expand Up @@ -72,149 +71,187 @@ def test_dual_write(self):
assert dc.condition_group == dcg

def test_equals(self):
self.dc.comparison = {"match": MatchType.EQUAL, "key": "LOGGER", "value": "sentry.example"}
self.dc.update(
comparison={"match": MatchType.EQUAL, "key": "LOGGER", "value": "sentry.example"}
)
self.assert_passes(self.dc, self.job)

self.dc.comparison = {
"match": MatchType.EQUAL,
"key": "logger",
"value": "sentry.other.example",
}
self.dc.update(
comparison={
"match": MatchType.EQUAL,
"key": "logger",
"value": "sentry.other.example",
}
)
self.assert_does_not_pass(self.dc, self.job)

def test_does_not_equal(self):
self.dc.comparison = {
"match": MatchType.NOT_EQUAL,
"key": "logger",
"value": "sentry.example",
}
self.dc.update(
comparison={
"match": MatchType.NOT_EQUAL,
"key": "logger",
"value": "sentry.example",
}
)
self.assert_does_not_pass(self.dc, self.job)

self.dc.comparison = {
"match": MatchType.NOT_EQUAL,
"key": "logger",
"value": "sentry.other.example",
}
self.dc.update(
comparison={
"match": MatchType.NOT_EQUAL,
"key": "logger",
"value": "sentry.other.example",
}
)
self.assert_passes(self.dc, self.job)

def test_starts_with(self):
self.dc.comparison = {
"match": MatchType.STARTS_WITH,
"key": "logger",
"value": "sentry.",
}
self.dc.update(
comparison={
"match": MatchType.STARTS_WITH,
"key": "logger",
"value": "sentry.",
}
)
self.assert_passes(self.dc, self.job)

self.dc.comparison = {"match": MatchType.STARTS_WITH, "key": "logger", "value": "bar."}
self.dc.update(
comparison={"match": MatchType.STARTS_WITH, "key": "logger", "value": "bar."}
)
self.assert_does_not_pass(self.dc, self.job)

def test_does_not_start_with(self):
self.dc.comparison = {
"match": MatchType.NOT_STARTS_WITH,
"key": "logger",
"value": "sentry.",
}
self.dc.update(
comparison={
"match": MatchType.NOT_STARTS_WITH,
"key": "logger",
"value": "sentry.",
}
)
self.assert_does_not_pass(self.dc, self.job)

self.dc.comparison = {
"match": MatchType.NOT_STARTS_WITH,
"key": "logger",
"value": "bar.",
}
self.dc.update(
comparison={
"match": MatchType.NOT_STARTS_WITH,
"key": "logger",
"value": "bar.",
}
)
self.assert_passes(self.dc, self.job)

def test_ends_with(self):
self.dc.comparison = {
"match": MatchType.ENDS_WITH,
"key": "logger",
"value": ".example",
}
self.dc.update(
comparison={
"match": MatchType.ENDS_WITH,
"key": "logger",
"value": ".example",
}
)
self.assert_passes(self.dc, self.job)

self.dc.comparison = {"match": MatchType.ENDS_WITH, "key": "logger", "value": ".foo"}
self.dc.update(comparison={"match": MatchType.ENDS_WITH, "key": "logger", "value": ".foo"})
self.assert_does_not_pass(self.dc, self.job)

def test_does_not_end_with(self):
self.dc.comparison = {
"match": MatchType.NOT_ENDS_WITH,
"key": "logger",
"value": ".example",
}
self.dc.update(
comparison={
"match": MatchType.NOT_ENDS_WITH,
"key": "logger",
"value": ".example",
}
)
self.assert_does_not_pass(self.dc, self.job)

self.dc.comparison = {
"match": MatchType.NOT_ENDS_WITH,
"key": "logger",
"value": ".foo",
}
self.dc.update(
comparison={
"match": MatchType.NOT_ENDS_WITH,
"key": "logger",
"value": ".foo",
}
)
self.assert_passes(self.dc, self.job)

def test_contains(self):
self.dc.comparison = {
"match": MatchType.CONTAINS,
"key": "logger",
"value": "sentry",
}
self.dc.update(
comparison={
"match": MatchType.CONTAINS,
"key": "logger",
"value": "sentry",
}
)
self.assert_passes(self.dc, self.job)

self.dc.comparison = {"match": MatchType.CONTAINS, "key": "logger", "value": "bar.foo"}
self.dc.update(
comparison={"match": MatchType.CONTAINS, "key": "logger", "value": "bar.foo"}
)
self.assert_does_not_pass(self.dc, self.job)

def test_does_not_contain(self):
self.dc.comparison = {
"match": MatchType.NOT_CONTAINS,
"key": "logger",
"value": "sentry",
}
self.dc.update(
comparison={
"match": MatchType.NOT_CONTAINS,
"key": "logger",
"value": "sentry",
}
)
self.assert_does_not_pass(self.dc, self.job)

self.dc.comparison = {
"match": MatchType.NOT_CONTAINS,
"key": "logger",
"value": "bar.foo",
}
self.dc.update(
comparison={
"match": MatchType.NOT_CONTAINS,
"key": "logger",
"value": "bar.foo",
}
)
self.assert_passes(self.dc, self.job)

def test_is_set(self):
self.dc.comparison = {"match": MatchType.IS_SET, "key": "logger"}
self.dc.update(comparison={"match": MatchType.IS_SET, "key": "logger"})
self.assert_passes(self.dc, self.job)

self.dc.comparison = {"match": MatchType.IS_SET, "key": "missing"}
self.dc.update(comparison={"match": MatchType.IS_SET, "key": "missing"})
self.assert_does_not_pass(self.dc, self.job)

def test_is_not_set(self):
self.dc.comparison = {"match": MatchType.NOT_SET, "key": "logger"}
self.dc.update(comparison={"match": MatchType.NOT_SET, "key": "logger"})
self.assert_does_not_pass(self.dc, self.job)

self.dc.comparison = {"match": MatchType.NOT_SET, "key": "missing"}
self.dc.update(comparison={"match": MatchType.NOT_SET, "key": "missing"})
self.assert_passes(self.dc, self.job)

def test_is_in(self):
self.dc.comparison = {
"match": MatchType.IS_IN,
"key": "logger",
"value": "bar.foo, wee, wow",
}
self.dc.update(
comparison={
"match": MatchType.IS_IN,
"key": "logger",
"value": "bar.foo, wee, wow",
}
)
self.assert_does_not_pass(self.dc, self.job)

self.dc.comparison = {
"match": MatchType.IS_IN,
"key": "logger",
"value": "foo.bar",
}
self.dc.update(
comparison={
"match": MatchType.IS_IN,
"key": "logger",
"value": "foo.bar",
}
)
self.assert_passes(self.dc, self.job)

def test_not_in(self):
self.dc.comparison = {
"match": MatchType.NOT_IN,
"key": "logger",
"value": "bar.foo, wee, wow",
}
self.dc.update(
comparison={
"match": MatchType.NOT_IN,
"key": "logger",
"value": "bar.foo, wee, wow",
}
)
self.assert_passes(self.dc, self.job)

self.dc.comparison = {
"match": MatchType.NOT_IN,
"key": "logger",
"value": "foo.bar",
}
self.dc.update(
comparison={
"match": MatchType.NOT_IN,
"key": "logger",
"value": "foo.bar",
}
)
self.assert_does_not_pass(self.dc, self.job)

0 comments on commit 807821a

Please sign in to comment.