How to use get_filter method in yandex-tank

Best Python code snippet using yandex-tank

test_filter.py

Source:test_filter.py Github

copy

Full Screen

...72 for u in users:73 self.__setattr__(u, ["equals", ["user.email", f"{u}@example.com"]])74 self.__setattr__(f"o{u}", ["user.email", "=", f"{u}@example.com"])75 def test_simple(self):76 result = get_filter("user.email:foo@example.com OR user.email:bar@example.com")77 assert result.conditions == [[_or(self.foo, self.bar), "=", 1]]78 result = get_filter("user.email:foo@example.com AND user.email:bar@example.com")79 assert result.conditions == [self.ofoo, self.obar]80 def test_words_with_boolean_substrings(self):81 result = get_filter("ORder")82 assert result.conditions == [_om("ORder")]83 result = get_filter("ANDroid")84 assert result.conditions == [_om("ANDroid")]85 def test_single_term(self):86 result = get_filter("user.email:foo@example.com")87 assert result.conditions == [self.ofoo]88 def test_wildcard_array_field(self):89 _filter = get_filter("error.value:Deadlock* OR !stack.filename:*.py")90 assert _filter.conditions == [91 [92 _or(93 ["like", ["error.value", "Deadlock%"]],94 ["notLike", ["stack.filename", "%.py"]],95 ),96 "=",97 1,98 ]99 ]100 assert _filter.filter_keys == {}101 def test_order_of_operations(self):102 result = get_filter(103 "user.email:foo@example.com OR user.email:bar@example.com AND user.email:foobar@example.com"104 )105 assert result.conditions == [[_or(self.foo, _and(self.bar, self.foobar)), "=", 1]]106 result = get_filter(107 "user.email:foo@example.com AND user.email:bar@example.com OR user.email:foobar@example.com"108 )109 assert result.conditions == [[_or(_and(self.foo, self.bar), self.foobar), "=", 1]]110 def test_multiple_statements(self):111 result = get_filter(112 "user.email:foo@example.com OR user.email:bar@example.com OR user.email:foobar@example.com"113 )114 assert result.conditions == [[_or(self.foo, _or(self.bar, self.foobar)), "=", 1]]115 result = get_filter(116 "user.email:foo@example.com AND user.email:bar@example.com AND user.email:foobar@example.com"117 )118 assert result.conditions == [self.ofoo, self.obar, self.ofoobar]119 # longer even number of terms120 result = get_filter(121 "user.email:foo@example.com AND user.email:bar@example.com OR user.email:foobar@example.com AND user.email:hello@example.com"122 )123 assert result.conditions == [124 [_or(_and(self.foo, self.bar), _and(self.foobar, self.hello)), "=", 1]125 ]126 # longer odd number of terms127 result = get_filter(128 "user.email:foo@example.com AND user.email:bar@example.com OR user.email:foobar@example.com AND user.email:hello@example.com AND user.email:hi@example.com"129 )130 assert result.conditions == [131 [132 _or(133 _and(self.foo, self.bar),134 _and(self.foobar, _and(self.hello, self.hi)),135 ),136 "=",137 1,138 ]139 ]140 # absurdly long141 result = get_filter(142 "user.email:foo@example.com AND user.email:bar@example.com OR user.email:foobar@example.com AND user.email:hello@example.com AND user.email:hi@example.com OR user.email:foo@example.com AND user.email:bar@example.com OR user.email:foobar@example.com AND user.email:hello@example.com AND user.email:hi@example.com"143 )144 assert result.conditions == [145 [146 _or(147 _and(self.foo, self.bar),148 _or(149 _and(self.foobar, _and(self.hello, self.hi)),150 _or(151 _and(self.foo, self.bar),152 _and(self.foobar, _and(self.hello, self.hi)),153 ),154 ),155 ),156 "=",157 1,158 ]159 ]160 def test_grouping_boolean_filter(self):161 result = get_filter("(event.type:error) AND (stack.in_app:true)")162 assert result.conditions == [["event.type", "=", "error"], ["stack.in_app", "=", 1]]163 def test_grouping_simple(self):164 result = get_filter("(user.email:foo@example.com OR user.email:bar@example.com)")165 assert result.conditions == [[_or(self.foo, self.bar), "=", 1]]166 result = get_filter(167 "(user.email:foo@example.com OR user.email:bar@example.com) AND user.email:foobar@example.com"168 )169 assert result.conditions == [[_or(self.foo, self.bar), "=", 1], self.ofoobar]170 result = get_filter(171 "user.email:foo@example.com AND (user.email:bar@example.com OR user.email:foobar@example.com)"172 )173 assert result.conditions == [self.ofoo, [_or(self.bar, self.foobar), "=", 1]]174 def test_nested_grouping(self):175 result = get_filter(176 "(user.email:foo@example.com OR (user.email:bar@example.com OR user.email:foobar@example.com))"177 )178 assert result.conditions == [[_or(self.foo, _or(self.bar, self.foobar)), "=", 1]]179 result = get_filter(180 "(user.email:foo@example.com OR (user.email:bar@example.com OR (user.email:foobar@example.com AND user.email:hello@example.com OR user.email:hi@example.com)))"181 )182 assert result.conditions == [183 [184 _or(185 self.foo,186 _or(self.bar, _or(_and(self.foobar, self.hello), self.hi)),187 ),188 "=",189 1,190 ]191 ]192 result = get_filter("test (item1 OR item2)")193 assert result.conditions == [194 _om("test"),195 [196 _or(197 _m("item1"),198 _m("item2"),199 ),200 "=",201 1,202 ],203 ]204 def test_grouping_edge_cases(self):205 result = get_filter("()")206 assert result.conditions == [207 _om("()"),208 ]209 result = get_filter("(test)")210 assert result.conditions == [211 _om("test"),212 ]213 def test_grouping_within_free_text(self):214 result = get_filter("undefined is not an object (evaluating 'function.name')")215 assert result.conditions == [216 _om("undefined is not an object (evaluating 'function.name')"),217 ]218 result = get_filter("combined (free text) AND (grouped)")219 assert result.conditions == [220 _om("combined (free text)"),221 _om("grouped"),222 ]223 def test_malformed_groups(self):224 with pytest.raises(InvalidSearchQuery) as error:225 get_filter("(user.email:foo@example.com OR user.email:bar@example.com")226 assert (227 str(error.value)228 == "Parse error at '(user.' (column 1). This is commonly caused by unmatched parentheses. Enclose any text in double quotes."229 )230 with pytest.raises(InvalidSearchQuery) as error:231 get_filter(232 "((user.email:foo@example.com OR user.email:bar@example.com AND user.email:bar@example.com)"233 )234 assert (235 str(error.value)236 == "Parse error at '((user' (column 1). This is commonly caused by unmatched parentheses. Enclose any text in double quotes."237 )238 with pytest.raises(InvalidSearchQuery) as error:239 get_filter("user.email:foo@example.com OR user.email:bar@example.com)")240 assert (241 str(error.value)242 == "Parse error at '.com)' (column 57). This is commonly caused by unmatched parentheses. Enclose any text in double quotes."243 )244 with pytest.raises(InvalidSearchQuery) as error:245 get_filter(246 "(user.email:foo@example.com OR user.email:bar@example.com AND user.email:bar@example.com))"247 )248 assert (249 str(error.value)250 == "Parse error at 'com))' (column 91). This is commonly caused by unmatched parentheses. Enclose any text in double quotes."251 )252 def test_combining_normal_terms_with_boolean(self):253 tests = [254 (255 "foo bar baz OR fizz buzz bizz",256 [[_or(_m("foo bar baz"), _m("fizz buzz bizz")), "=", 1]],257 ),258 (259 "a:b (c:d OR e:f) g:h i:j OR k:l",260 [261 [262 _or(263 _and(264 _eq("ab"),265 _and(266 _or(_eq("cd"), _eq("ef")),267 _and(_eq("gh"), _eq("ij")),268 ),269 ),270 _eq("kl"),271 ),272 "=",273 1,274 ]275 ],276 ),277 (278 "a:b OR c:d e:f g:h (i:j OR k:l)",279 [280 [281 _or(282 _eq("ab"),283 _and(284 _eq("cd"),285 _and(_eq("ef"), _and(_eq("gh"), _or(_eq("ij"), _eq("kl")))),286 ),287 ),288 "=",289 1,290 ]291 ],292 ),293 ("(a:b OR c:d) e:f", [[_or(_eq("ab"), _eq("cd")), "=", 1], _oeq("ef")]),294 (295 "a:b OR c:d e:f g:h i:j OR k:l",296 [297 [298 _or(299 _eq("ab"),300 _or(301 _and(302 _eq("cd"),303 _and(_eq("ef"), _and(_eq("gh"), _eq("ij"))),304 ),305 _eq("kl"),306 ),307 ),308 "=",309 1,310 ]311 ],312 ),313 (314 "(a:b OR c:d) e:f g:h OR i:j k:l",315 [316 [317 _or(318 _and(319 _or(_eq("ab"), _eq("cd")),320 _and(_eq("ef"), _eq("gh")),321 ),322 _and(_eq("ij"), _eq("kl")),323 ),324 "=",325 1,326 ]327 ],328 ),329 (330 "a:b c:d e:f OR g:h i:j",331 [332 [333 _or(334 _and(_eq("ab"), _and(_eq("cd"), _eq("ef"))),335 _and(_eq("gh"), _eq("ij")),336 ),337 "=",338 1,339 ]340 ],341 ),342 (343 "a:b c:d (e:f OR g:h) i:j",344 [_oeq("ab"), _oeq("cd"), [_or(_eq("ef"), _eq("gh")), "=", 1], _oeq("ij")],345 ),346 (347 "!a:b c:d (e:f OR g:h) i:j",348 [_noeq("ab"), _oeq("cd"), [_or(_eq("ef"), _eq("gh")), "=", 1], _oeq("ij")],349 ),350 ]351 for test in tests:352 result = get_filter(test[0])353 assert test[1] == result.conditions, test[0]354 def test_nesting_using_parentheses(self):355 tests = [356 (357 "(a:b OR (c:d AND (e:f OR (g:h AND e:f))))",358 [359 [360 _or(361 _eq("ab"),362 _and(_eq("cd"), _or(_eq("ef"), _and(_eq("gh"), _eq("ef")))),363 ),364 "=",365 1,366 ]367 ],368 ),369 (370 "(a:b OR c:d) AND (e:f g:h)",371 [[_or(_eq("ab"), _eq("cd")), "=", 1], _oeq("ef"), _oeq("gh")],372 ),373 ]374 for test in tests:375 result = get_filter(test[0])376 assert test[1] == result.conditions, test[0]377 def test_aggregate_filter_in_conditions(self):378 tests = [379 ("count():>1 AND count():<=3", [_oc(">", 1), _oc("<=", 3)]),380 ("count():>1 OR count():<=3", [[_or(_c(">", 1), _c("<=", 3)), "=", 1]]),381 (382 "count():>1 OR count():>5 AND count():<=3",383 [[_or(_c(">", 1), _and(_c(">", 5), _c("<=", 3))), "=", 1]],384 ),385 (386 "count():>1 AND count():<=3 OR count():>5",387 [[_or(_and(_c(">", 1), _c("<=", 3)), _c(">", 5)), "=", 1]],388 ),389 (390 "(count():>1 OR count():>2) AND count():<=3",391 [[_or(_c(">", 1), _c(">", 2)), "=", 1], _oc("<=", 3)],392 ),393 (394 "(count():>1 AND count():>5) OR count():<=3",395 [[_or(_and(_c(">", 1), _c(">", 5)), _c("<=", 3)), "=", 1]],396 ),397 ]398 for test in tests:399 result = get_filter(test[0])400 assert test[1] == result.having, test[0]401 def test_aggregate_filter_and_normal_filter_in_condition(self):402 tests = [403 ("count():>1 AND a:b", [_oeq("ab")], [_oc(">", 1)]),404 ("count():>1 AND a:b c:d", [_oeq("ab"), _oeq("cd")], [_oc(">", 1)]),405 ("(a:b OR c:d) count():>1", [[_or(_eq("ab"), _eq("cd")), "=", 1]], [_oc(">", 1)]),406 (407 "(count():<3 OR count():>10) a:b c:d",408 [_oeq("ab"), _oeq("cd")],409 [[_or(_c("<", 3), _c(">", 10)), "=", 1]],410 ),411 ]412 for test in tests:413 result = get_filter(test[0])414 assert test[1] == result.conditions, "cond: " + test[0]415 assert test[2] == result.having, "having: " + test[0]416 def test_aggregate_filter_and_normal_filter_in_condition_with_or(self):417 with pytest.raises(InvalidSearchQuery) as error:418 get_filter("count():>1 OR a:b")419 assert (420 str(error.value)421 == "Having an OR between aggregate filters and normal filters is invalid."422 )423 with pytest.raises(InvalidSearchQuery) as error:424 get_filter("(count():>1 AND a:b) OR a:b")425 assert (426 str(error.value)427 == "Having an OR between aggregate filters and normal filters is invalid."428 )429 with pytest.raises(InvalidSearchQuery) as error:430 get_filter("(count():>1 AND a:b) OR (a:b AND count():>2)")431 assert (432 str(error.value)433 == "Having an OR between aggregate filters and normal filters is invalid."434 )435 with pytest.raises(InvalidSearchQuery) as error:436 get_filter("a:b OR (c:d AND (e:f AND count():>1))")437 assert (438 str(error.value)439 == "Having an OR between aggregate filters and normal filters is invalid."440 )441 def test_project_in_condition_filters(self):442 project1 = self.create_project()443 project2 = self.create_project()444 tests = [445 (446 f"project:{project1.slug} OR project:{project2.slug}",447 [448 [449 _or(450 ["equals", ["project_id", project1.id]],451 ["equals", ["project_id", project2.id]],452 ),453 "=",454 1,455 ]456 ],457 [project1.id, project2.id],458 ),459 (460 f"(project:{project1.slug} OR project:{project2.slug}) AND a:b",461 [462 [463 _or(464 ["equals", ["project_id", project1.id]],465 ["equals", ["project_id", project2.id]],466 ),467 "=",468 1,469 ],470 _oeq("ab"),471 ],472 [project1.id, project2.id],473 ),474 (475 f"(project:{project1.slug} AND a:b) OR (project:{project1.slug} AND c:d)",476 [477 [478 _or(479 _and(["equals", ["project_id", project1.id]], _eq("ab")),480 _and(["equals", ["project_id", project1.id]], _eq("cd")),481 ),482 "=",483 1,484 ]485 ],486 [project1.id],487 ),488 ]489 for test in tests:490 result = get_filter(491 test[0],492 params={493 "organization_id": self.organization.id,494 "project_id": [project1.id, project2.id],495 },496 )497 assert test[1] == result.conditions, test[0]498 assert set(test[2]) == set(result.project_ids), test[0]499 def test_project_in_condition_filters_not_in_project_filter(self):500 project1 = self.create_project()501 project2 = self.create_project()502 project3 = self.create_project()503 with self.assertRaisesRegex(504 InvalidSearchQuery,505 re.escape(506 f"Invalid query. Project(s) {str(project3.slug)} do not exist or are not actively selected."507 ),508 ):509 get_filter(510 f"project:{project1.slug} OR project:{project3.slug}",511 params={512 "organization_id": self.organization.id,513 "project_id": [project1.id, project2.id],514 },515 )516 def test_issue_id_alias_in_condition_filters(self):517 def _eq(xy):518 return ["equals", [["ifNull", [xy[0], "''"]], xy[1]]]519 group1 = self.create_group(project=self.project)520 group2 = self.create_group(project=self.project)521 group3 = self.create_group(project=self.project)522 tests = [523 (524 f"issue.id:{group1.id} OR issue.id:{group2.id}",525 [],526 [group1.id, group2.id],527 ),528 (f"issue.id:{group1.id} AND issue.id:{group1.id}", [], [group1.id]),529 (530 f"(issue.id:{group1.id} AND issue.id:{group2.id}) OR issue.id:{group3.id}",531 [],532 [group1.id, group2.id, group3.id],533 ),534 (f"issue.id:{group1.id} AND a:b", [_oeq("ab")], [group1.id]),535 # TODO: Using OR with issue.id is broken. These return incorrect results.536 (f"issue.id:{group1.id} OR a:b", [_oeq("ab")], [group1.id]),537 (538 f"(issue.id:{group1.id} AND a:b) OR issue.id:{group2.id}",539 [_oeq("ab")],540 [group1.id, group2.id],541 ),542 (543 f"(issue.id:{group1.id} AND a:b) OR c:d",544 [[_or(_eq("ab"), _eq("cd")), "=", 1]],545 [group1.id],546 ),547 ]548 for test in tests:549 result = get_filter(550 test[0],551 params={"organization_id": self.organization.id, "project_id": [self.project.id]},552 )553 assert test[1] == result.conditions, test[0]554 assert test[2] == result.group_ids, test[0]555 def test_invalid_conditional_filters(self):556 with self.assertRaisesRegex(557 InvalidSearchQuery, "Condition is missing on the left side of 'OR' operator"558 ):559 get_filter("OR a:b")560 with self.assertRaisesRegex(561 InvalidSearchQuery, "Missing condition in between two condition operators: 'OR AND'"562 ):563 get_filter("a:b Or And c:d")564 with self.assertRaisesRegex(565 InvalidSearchQuery, "Condition is missing on the right side of 'AND' operator"566 ):567 get_filter("a:b AND c:d AND")568 with self.assertRaisesRegex(569 InvalidSearchQuery, "Condition is missing on the left side of 'OR' operator"570 ):571 get_filter("(OR a:b) AND c:d")572 def test_empty_parens_in_message_not_boolean_search(self):573 result = get_filter(574 "failure_rate():>0.003&& users:>10 event.type:transaction",575 params={"organization_id": self.organization.id, "project_id": [self.project.id]},576 )577 assert result.conditions == [578 _om("failure_rate():>0.003&&"),579 [["ifNull", ["users", "''"]], "=", ">10"],580 ["event.type", "=", "transaction"],581 ]582 def test_parens_around_message(self):583 result = get_filter(584 "TypeError Anonymous function(app/javascript/utils/transform-object-keys)",585 params={"organization_id": self.organization.id, "project_id": [self.project.id]},586 )587 assert result.conditions == [588 _om("TypeError Anonymous function(app/javascript/utils/transform-object-keys)"),589 ]590 def test_or_does_not_match_organization(self):591 result = get_filter(592 f"organization.slug:{self.organization.slug}",593 params={"organization_id": self.organization.id, "project_id": [self.project.id]},594 )595 assert result.conditions == [596 [["ifNull", ["organization.slug", "''"]], "=", f"{self.organization.slug}"]597 ]598 def test_boolean_with_in_search(self):599 result = get_filter(600 'url:["a", "b"] AND release:test',601 params={"organization_id": self.organization.id, "project_id": [self.project.id]},602 )603 assert result.conditions == [604 [["ifNull", ["url", "''"]], "IN", ["a", "b"]],605 ["release", "=", "test"],606 ]607 result = get_filter(608 'url:["a", "b"] OR release:test',609 params={"organization_id": self.organization.id, "project_id": [self.project.id]},610 )611 assert result.conditions == [612 [613 [614 "or",615 [616 [["ifNull", ["url", "''"]], "IN", ["a", "b"]],617 ["equals", ["release", "test"]],618 ],619 ],620 "=",621 1,622 ]623 ]624 result = get_filter(625 'url:["a", "b"] AND url:["c", "d"] OR url:["e", "f"]',626 params={"organization_id": self.organization.id, "project_id": [self.project.id]},627 )628 assert result.conditions == [629 [630 [631 "or",632 [633 [634 "and",635 [636 [["ifNull", ["url", "''"]], "IN", ["a", "b"]],637 [["ifNull", ["url", "''"]], "IN", ["c", "d"]],638 ],639 ],640 [["ifNull", ["url", "''"]], "IN", ["e", "f"]],641 ],642 ],643 "=",644 1,645 ]646 ]647class GetSnubaQueryArgsTest(TestCase):648 def test_simple(self):649 _filter = get_filter(650 "user.email:foo@example.com release:1.2.1 fruit:apple hello",651 {652 "project_id": [1, 2, 3],653 "organization_id": 1,654 "start": datetime.datetime(2015, 5, 18, 10, 15, 1, tzinfo=timezone.utc),655 "end": datetime.datetime(2015, 5, 19, 10, 15, 1, tzinfo=timezone.utc),656 },657 )658 assert _filter.conditions == [659 ["user.email", "=", "foo@example.com"],660 ["release", "=", "1.2.1"],661 [["ifNull", ["fruit", "''"]], "=", "apple"],662 [["positionCaseInsensitive", ["message", "'hello'"]], "!=", 0],663 ]664 assert _filter.start == datetime.datetime(2015, 5, 18, 10, 15, 1, tzinfo=timezone.utc)665 assert _filter.end == datetime.datetime(2015, 5, 19, 10, 15, 1, tzinfo=timezone.utc)666 assert _filter.filter_keys == {"project_id": [1, 2, 3]}667 assert _filter.project_ids == [1, 2, 3]668 assert not _filter.group_ids669 assert not _filter.event_ids670 def test_negation(self):671 _filter = get_filter("!user.email:foo@example.com")672 assert _filter.conditions == [673 [[["isNull", ["user.email"]], "=", 1], ["user.email", "!=", "foo@example.com"]]674 ]675 assert _filter.filter_keys == {}676 def test_implicit_and_explicit_tags(self):677 assert get_filter("tags[fruit]:apple").conditions == [678 [["ifNull", ["tags[fruit]", "''"]], "=", "apple"]679 ]680 assert get_filter("fruit:apple").conditions == [[["ifNull", ["fruit", "''"]], "=", "apple"]]681 assert get_filter("tags[project_id]:123").conditions == [682 [["ifNull", ["tags[project_id]", "''"]], "=", "123"]683 ]684 def test_in_syntax(self):685 project_2 = self.create_project()686 group = self.create_group(project=self.project, short_id=self.project.next_short_id())687 group_2 = self.create_group(project=project_2, short_id=self.project.next_short_id())688 assert (689 get_filter(690 f"project.name:[{self.project.slug}, {project_2.slug}]",691 params={"project_id": [self.project.id, project_2.id]},692 ).conditions693 == [["project_id", "IN", [project_2.id, self.project.id]]]694 )695 assert (696 get_filter(697 f"issue:[{group.qualified_short_id}, {group_2.qualified_short_id}]",698 params={"organization_id": self.project.organization_id},699 ).conditions700 == [["issue.id", "IN", [group.id, group_2.id]]]701 )702 assert (703 get_filter(704 f"issue:[{group.qualified_short_id}, unknown]",705 params={"organization_id": self.project.organization_id},706 ).conditions707 == [[["coalesce", ["issue.id", 0]], "IN", [0, group.id]]]708 )709 assert get_filter("environment:[prod, dev]").conditions == [710 [["environment", "IN", {"prod", "dev"}]]711 ]712 assert get_filter("random_tag:[what, hi]").conditions == [713 [["ifNull", ["random_tag", "''"]], "IN", ["what", "hi"]]714 ]715 def test_no_search(self):716 _filter = get_filter(717 params={718 "project_id": [1, 2, 3],719 "start": datetime.datetime(2015, 5, 18, 10, 15, 1, tzinfo=timezone.utc),720 "end": datetime.datetime(2015, 5, 19, 10, 15, 1, tzinfo=timezone.utc),721 }722 )723 assert not _filter.conditions724 assert _filter.filter_keys == {"project_id": [1, 2, 3]}725 assert _filter.start == datetime.datetime(2015, 5, 18, 10, 15, 1, tzinfo=timezone.utc)726 assert _filter.end == datetime.datetime(2015, 5, 19, 10, 15, 1, tzinfo=timezone.utc)727 def test_wildcard(self):728 _filter = get_filter("release:3.1.* user.email:*@example.com")729 assert _filter.conditions == [730 [["match", ["release", "'(?i)^3\\.1\\..*$'"]], "=", 1],731 [["match", ["user.email", "'(?i)^.*@example\\.com$'"]], "=", 1],732 ]733 assert _filter.filter_keys == {}734 def test_wildcard_with_unicode(self):735 _filter = get_filter(736 "message:*\u716e\u6211\u66f4\u591a\u7684\u98df\u7269\uff0c\u6211\u9913\u4e86."737 )738 assert _filter.conditions == [739 [740 [741 "match",742 [743 "message",744 "'(?i).*\u716e\u6211\u66f4\u591a\u7684\u98df\u7269\uff0c\u6211\u9913\u4e86\\.'",745 ],746 ],747 "=",748 1,749 ]750 ]751 assert _filter.filter_keys == {}752 def test_wildcard_event_id(self):753 with self.assertRaises(InvalidSearchQuery):754 get_filter("id:deadbeef*")755 def test_event_id_validation(self):756 event_id = "a" * 32757 results = get_filter(f"id:{event_id}")758 assert results.conditions == [["id", "=", event_id]]759 event_id = "a" * 16 + "-" * 16 + "b" * 16760 results = get_filter(f"id:{event_id}")761 assert results.conditions == [["id", "=", event_id]]762 with self.assertRaises(InvalidSearchQuery):763 get_filter("id:deadbeef")764 with self.assertRaises(InvalidSearchQuery):765 get_filter(f"id:{'g' * 32}")766 def test_trace_id_validation(self):767 trace_id = "a" * 32768 results = get_filter(f"trace:{trace_id}")769 assert results.conditions == [["trace", "=", trace_id]]770 trace_id = "a" * 16 + "-" * 16 + "b" * 16771 results = get_filter(f"trace:{trace_id}")772 assert results.conditions == [["trace", "=", trace_id]]773 with self.assertRaises(InvalidSearchQuery):774 get_filter("trace:deadbeef")775 with self.assertRaises(InvalidSearchQuery):776 get_filter(f"trace:{'g' * 32}")777 def test_negated_wildcard(self):778 _filter = get_filter("!release:3.1.* user.email:*@example.com")779 assert _filter.conditions == [780 [781 [["isNull", ["release"]], "=", 1],782 [["match", ["release", "'(?i)^3\\.1\\..*$'"]], "!=", 1],783 ],784 [["match", ["user.email", "'(?i)^.*@example\\.com$'"]], "=", 1],785 ]786 assert _filter.filter_keys == {}787 def test_escaped_wildcard(self):788 assert get_filter("release:3.1.\\* user.email:\\*@example.com").conditions == [789 ["release", "=", "3.1.*"],790 ["user.email", "=", "*@example.com"],791 ]792 assert get_filter("release:\\\\\\*").conditions == [["release", "=", "\\\\*"]]793 assert get_filter("release:\\\\*").conditions == [794 [["match", ["release", "'(?i)^\\\\.*$'"]], "=", 1]795 ]796 assert get_filter("message:.*?").conditions == [797 [["match", ["message", r"'(?i)\..*\?'"]], "=", 1]798 ]799 def test_wildcard_array_field(self):800 _filter = get_filter(801 "error.value:Deadlock* stack.filename:*.py stack.abs_path:%APP_DIR%/th_ing*"802 )803 assert _filter.conditions == [804 ["error.value", "LIKE", "Deadlock%"],805 ["stack.filename", "LIKE", "%.py"],806 ["stack.abs_path", "LIKE", "\\%APP\\_DIR\\%/th\\_ing%"],807 ]808 assert _filter.filter_keys == {}809 def test_wildcard_array_field_with_backslash(self):810 test_cases = [811 (r"stack.filename:\k*", ["stack.filename", "LIKE", "\\\\k%"]), # prefixed by \k812 (r"stack.filename:\\*", ["stack.filename", "LIKE", "\\\\\\\\%"]), # prefixed by \\813 (814 r"stack.filename:\**",815 ["stack.filename", "LIKE", "\\\\%%"],816 ), # prefixed by \% since the search filter replaces both * with %817 (r"stack.filename:\"k*", ["stack.filename", "LIKE", '"k%']), # prefixed by "k818 (r'stack.filename:\\"k*', ["stack.filename", "LIKE", '\\\\"k%']), # prefixed by \"k819 ]820 for filter, conditions in test_cases:821 _filter = get_filter(filter)822 assert _filter.conditions == [823 conditions,824 ]825 assert _filter.filter_keys == {}826 def test_existence_array_field(self):827 _filter = get_filter('has:stack.filename !has:stack.lineno error.value:""')828 assert _filter.conditions == [829 [["notEmpty", ["stack.filename"]], "=", 1],830 [["notEmpty", ["stack.lineno"]], "=", 0],831 [["notEmpty", ["error.value"]], "=", 0],832 ]833 def test_wildcard_with_trailing_backslash(self):834 results = get_filter("title:*misgegaan\\")835 assert results.conditions == [[["match", ["title", "'(?i)^.*misgegaan\\\\$'"]], "=", 1]]836 def test_has(self):837 assert get_filter("has:release").conditions == [[["isNull", ["release"]], "!=", 1]]838 def test_not_has(self):839 assert get_filter("!has:release").conditions == [[["isNull", ["release"]], "=", 1]]840 def test_has_issue(self):841 has_issue_filter = get_filter("has:issue")842 assert has_issue_filter.group_ids == []843 assert has_issue_filter.conditions == [[["coalesce", ["issue.id", 0]], "!=", 0]]844 def test_not_has_issue(self):845 has_issue_filter = get_filter("!has:issue")846 assert has_issue_filter.group_ids == []847 assert has_issue_filter.conditions == [[["coalesce", ["issue.id", 0]], "=", 0]]848 def test_has_issue_id(self):849 has_issue_filter = get_filter("has:issue.id")850 assert has_issue_filter.group_ids == []851 assert has_issue_filter.conditions == [[["coalesce", ["issue.id", 0]], "!=", 0]]852 def test_not_has_issue_id(self):853 has_issue_filter = get_filter("!has:issue.id")854 assert has_issue_filter.group_ids == []855 assert has_issue_filter.conditions == [[["coalesce", ["issue.id", 0]], "=", 0]]856 def test_message_empty(self):857 assert get_filter("has:message").conditions == [[["equals", ["message", ""]], "!=", 1]]858 assert get_filter("!has:message").conditions == [[["equals", ["message", ""]], "=", 1]]859 assert get_filter('message:""').conditions == [[["equals", ["message", ""]], "=", 1]]860 assert get_filter('!message:""').conditions == [[["equals", ["message", ""]], "!=", 1]]861 def test_message_negative(self):862 assert get_filter('!message:"post_process.process_error HTTPError 403"').conditions == [863 [864 [865 "positionCaseInsensitive",866 ["message", "'post_process.process_error HTTPError 403'"],867 ],868 "=",869 0,870 ]871 ]872 def test_message_with_newlines(self):873 assert get_filter('message:"nice \n a newline\n"').conditions == [874 [["positionCaseInsensitive", ["message", "'nice \n a newline\n'"]], "!=", 0]875 ]876 def test_malformed_groups(self):877 with pytest.raises(InvalidSearchQuery):878 get_filter("(user.email:foo@example.com OR user.email:bar@example.com")879 def test_issue_id_filter(self):880 _filter = get_filter("issue.id:1")881 assert not _filter.conditions882 assert _filter.filter_keys == {"group_id": [1]}883 assert _filter.group_ids == [1]884 _filter = get_filter("issue.id:1 issue.id:2 issue.id:3")885 assert not _filter.conditions886 assert _filter.filter_keys == {"group_id": [1, 2, 3]}887 assert _filter.group_ids == [1, 2, 3]888 _filter = get_filter("issue.id:1 user.email:foo@example.com")889 assert _filter.conditions == [["user.email", "=", "foo@example.com"]]890 assert _filter.filter_keys == {"group_id": [1]}891 assert _filter.group_ids == [1]892 def test_issue_filter_invalid(self):893 with pytest.raises(InvalidSearchQuery) as err:894 get_filter("issue:1", {"organization_id": 1})895 assert "Invalid value '" in str(err)896 assert "' for 'issue:' filter" in str(err)897 def test_issue_filter(self):898 group = self.create_group(project=self.project)899 _filter = get_filter(900 f"issue:{group.qualified_short_id}", {"organization_id": self.organization.id}901 )902 assert _filter.conditions == [["issue.id", "=", group.id]]903 assert _filter.filter_keys == {}904 assert _filter.group_ids == []905 def test_negated_issue_filter(self):906 group = self.create_group(project=self.project)907 _filter = get_filter(908 f"!issue:{group.qualified_short_id}", {"organization_id": self.organization.id}909 )910 assert _filter.conditions == [["issue.id", "!=", group.id]]911 assert _filter.filter_keys == {}912 assert _filter.group_ids == []913 def test_unknown_issue_filter(self):914 _filter = get_filter("issue:unknown", {"organization_id": self.organization.id})915 assert _filter.conditions == [[["coalesce", ["issue.id", 0]], "=", 0]]916 assert _filter.filter_keys == {}917 assert _filter.group_ids == []918 _filter = get_filter("!issue:unknown", {"organization_id": self.organization.id})919 assert _filter.conditions == [[["coalesce", ["issue.id", 0]], "!=", 0]]920 assert _filter.filter_keys == {}921 assert _filter.group_ids == []922 def test_user_display_filter(self):923 _filter = get_filter(924 "user.display:bill@example.com", {"organization_id": self.organization.id}925 )926 assert _filter.conditions == [927 [928 ["coalesce", ["user.email", "user.username", "user.id", "user.ip"]],929 "=",930 "bill@example.com",931 ]932 ]933 assert _filter.filter_keys == {}934 assert _filter.group_ids == []935 def test_user_display_wildcard(self):936 _filter = get_filter("user.display:jill*", {"organization_id": self.organization.id})937 assert _filter.conditions == [938 [939 [940 "match",941 [942 ["coalesce", ["user.email", "user.username", "user.id", "user.ip"]],943 "'(?i)^jill.*$'",944 ],945 ],946 "=",947 1,948 ]949 ]950 assert _filter.filter_keys == {}951 assert _filter.group_ids == []952 def test_has_user_display(self):953 _filter = get_filter("has:user.display", {"organization_id": self.organization.id})954 assert _filter.conditions == [955 [956 ["isNull", [["coalesce", ["user.email", "user.username", "user.id", "user.ip"]]]],957 "!=",958 1,959 ]960 ]961 assert _filter.filter_keys == {}962 assert _filter.group_ids == []963 def test_not_has_user_display(self):964 _filter = get_filter("!has:user.display", {"organization_id": self.organization.id})965 assert _filter.conditions == [966 [967 ["isNull", [["coalesce", ["user.email", "user.username", "user.id", "user.ip"]]]],968 "=",969 1,970 ]971 ]972 assert _filter.filter_keys == {}973 assert _filter.group_ids == []974 def test_environment_param(self):975 params = {"environment": ["", "prod"]}976 _filter = get_filter("", params)977 # Should generate OR conditions978 assert _filter.conditions == [979 [["environment", "IS NULL", None], ["environment", "=", "prod"]]980 ]981 assert _filter.filter_keys == {}982 assert _filter.group_ids == []983 params = {"environment": ["dev", "prod"]}984 _filter = get_filter("", params)985 assert _filter.conditions == [[["environment", "IN", {"dev", "prod"}]]]986 assert _filter.filter_keys == {}987 assert _filter.group_ids == []988 def test_environment_condition_string(self):989 _filter = get_filter("environment:dev")990 assert _filter.conditions == [[["environment", "=", "dev"]]]991 assert _filter.filter_keys == {}992 assert _filter.group_ids == []993 _filter = get_filter("!environment:dev")994 assert _filter.conditions == [[["environment", "!=", "dev"]]]995 assert _filter.filter_keys == {}996 assert _filter.group_ids == []997 _filter = get_filter("environment:dev environment:prod")998 # Will generate conditions that will never find anything999 assert _filter.conditions == [[["environment", "=", "dev"]], [["environment", "=", "prod"]]]1000 assert _filter.filter_keys == {}1001 assert _filter.group_ids == []1002 _filter = get_filter('environment:""')1003 # The '' environment is Null in snuba1004 assert _filter.conditions == [[["environment", "IS NULL", None]]]1005 assert _filter.filter_keys == {}1006 assert _filter.group_ids == []1007 def test_project_name(self):1008 p1 = self.create_project(organization=self.organization)1009 p2 = self.create_project(organization=self.organization)1010 params = {"project_id": [p1.id, p2.id]}1011 _filter = get_filter(f"project.name:{p1.slug}", params)1012 assert _filter.conditions == [["project_id", "=", p1.id]]1013 assert _filter.filter_keys == {"project_id": [p1.id]}1014 assert _filter.project_ids == [p1.id]1015 params = {"project_id": [p1.id, p2.id]}1016 _filter = get_filter(f"!project.name:{p1.slug}", params)1017 assert _filter.conditions == [1018 [[["isNull", ["project_id"]], "=", 1], ["project_id", "!=", p1.id]]1019 ]1020 assert _filter.filter_keys == {"project_id": [p1.id, p2.id]}1021 assert _filter.project_ids == [p1.id, p2.id]1022 with pytest.raises(InvalidSearchQuery) as exc_info:1023 params = {"project_id": []}1024 get_filter(f"project.name:{p1.slug}", params)1025 exc = exc_info.value1026 exc_str = f"{exc}"1027 assert (1028 f"Invalid query. Project(s) {p1.slug} do not exist or are not actively selected."1029 in exc_str1030 )1031 def test_not_has_project(self):1032 with pytest.raises(InvalidSearchQuery) as err:1033 get_filter("!has:project")1034 assert "Invalid query for 'has' search: 'project' cannot be empty." in str(err)1035 with pytest.raises(InvalidSearchQuery) as err:1036 get_filter("!has:project.name")1037 assert "Invalid query for 'has' search: 'project' cannot be empty." in str(err)1038 def test_transaction_status(self):1039 for (key, val) in SPAN_STATUS_CODE_TO_NAME.items():1040 result = get_filter(f"transaction.status:{val}")1041 assert result.conditions == [["transaction.status", "=", key]]1042 def test_transaction_status_no_wildcard(self):1043 with pytest.raises(InvalidSearchQuery) as exc_info:1044 get_filter("transaction.status:o*")1045 exc = exc_info.value1046 exc_str = f"{exc}"1047 assert "Invalid value" in exc_str1048 assert "cancelled," in exc_str1049 def test_transaction_status_invalid(self):1050 with pytest.raises(InvalidSearchQuery) as exc_info:1051 get_filter("transaction.status:lol")1052 exc = exc_info.value1053 exc_str = f"{exc}"1054 assert "Invalid value" in exc_str1055 assert "cancelled," in exc_str1056 def test_error_handled(self):1057 result = get_filter("error.handled:true")1058 assert result.conditions == [[["isHandled", []], "=", 1]]1059 result = get_filter("error.handled:false")1060 assert result.conditions == [[["notHandled", []], "=", 1]]1061 result = get_filter("has:error.handled")1062 assert result.conditions == [[["isHandled", []], "=", 1]]1063 result = get_filter("!has:error.handled")1064 assert result.conditions == [[["isHandled", []], "=", 0]]1065 result = get_filter("!error.handled:true")1066 assert result.conditions == [[["notHandled", []], "=", 1]]1067 result = get_filter("!error.handled:false")1068 assert result.conditions == [[["isHandled", []], "=", 1]]1069 result = get_filter("!error.handled:0")1070 assert result.conditions == [[["isHandled", []], "=", 1]]1071 with pytest.raises(InvalidSearchQuery):1072 get_filter("error.handled:99")1073 with pytest.raises(InvalidSearchQuery):1074 get_filter("error.handled:nope")1075 def test_error_unhandled(self):1076 result = get_filter("error.unhandled:true")1077 assert result.conditions == [[["notHandled", []], "=", 1]]1078 result = get_filter("error.unhandled:false")1079 assert result.conditions == [[["isHandled", []], "=", 1]]1080 result = get_filter("has:error.unhandled")1081 assert result.conditions == [[["isHandled", []], "=", 0]]1082 result = get_filter("!has:error.unhandled")1083 assert result.conditions == [[["isHandled", []], "=", 1]]1084 result = get_filter("!error.unhandled:true")1085 assert result.conditions == [[["isHandled", []], "=", 1]]1086 result = get_filter("!error.unhandled:false")1087 assert result.conditions == [[["notHandled", []], "=", 1]]1088 result = get_filter("!error.unhandled:0")1089 assert result.conditions == [[["notHandled", []], "=", 1]]1090 with pytest.raises(InvalidSearchQuery):1091 get_filter("error.unhandled:99")1092 with pytest.raises(InvalidSearchQuery):1093 get_filter("error.unhandled:nope")1094 def test_function_negation(self):1095 result = get_filter("!p95():5s")1096 assert result.having == [["p95", "!=", 5000.0]]1097 result = get_filter("!p95():>5s")1098 assert result.having == [["p95", "<=", 5000.0]]1099 result = get_filter("!p95():>=5s")1100 assert result.having == [["p95", "<", 5000.0]]1101 result = get_filter("!p95():<5s")1102 assert result.having == [["p95", ">=", 5000.0]]1103 result = get_filter("!p95():<=5s")1104 assert result.having == [["p95", ">", 5000.0]]1105 def test_function_with_default_arguments(self):1106 result = get_filter("epm():>100", {"start": before_now(minutes=5), "end": before_now()})1107 assert result.having == [["epm", ">", 100]]1108 def test_function_with_alias(self):1109 result = get_filter("percentile(transaction.duration, 0.95):>100")1110 assert result.having == [["percentile_transaction_duration_0_95", ">", 100]]1111 def test_function_arguments(self):1112 result = get_filter("percentile(transaction.duration, 0.75):>100")1113 assert result.having == [["percentile_transaction_duration_0_75", ">", 100]]1114 def test_function_arguments_with_spaces(self):1115 result = get_filter("percentile( transaction.duration, 0.75 ):>100")1116 assert result.having == [["percentile_transaction_duration_0_75", ">", 100]]1117 result = get_filter("percentile (transaction.duration, 0.75):>100")1118 assert result.conditions == [1119 _om("percentile (transaction.duration, 0.75):>100"),1120 ]1121 assert result.having == []1122 result = get_filter(1123 "epm( ):>100", {"start": before_now(minutes=5), "end": before_now()}1124 )1125 assert result.having == [["epm", ">", 100]]1126 def test_function_with_float_arguments(self):1127 result = get_filter("apdex(300):>0.5")1128 assert result.having == [["apdex_300", ">", 0.5]]1129 def test_function_with_negative_arguments(self):1130 result = get_filter("apdex(300):>-0.5")1131 assert result.having == [["apdex_300", ">", -0.5]]1132 def test_function_with_bad_arguments(self):1133 result = get_filter("percentile(transaction.duration 0.75):>100")1134 assert result.having == []1135 assert result.conditions == [_om("percentile(transaction.duration 0.75):>100")]1136 def test_function_with_date_arguments(self):1137 result = get_filter("last_seen():2020-04-01T19:34:52+00:00")1138 assert result.having == [["last_seen", "=", 1585769692]]1139 def test_function_with_date_negation(self):1140 result = get_filter("!last_seen():2020-04-01T19:34:52+00:00")1141 assert result.having == [["last_seen", "!=", 1585769692]]1142 result = get_filter("!last_seen():>2020-04-01T19:34:52+00:00")1143 assert result.having == [["last_seen", "<=", 1585769692]]1144 result = get_filter("!last_seen():>=2020-04-01T19:34:52+00:00")1145 assert result.having == [["last_seen", "<", 1585769692]]1146 result = get_filter("!last_seen():<2020-04-01T19:34:52+00:00")1147 assert result.having == [["last_seen", ">=", 1585769692]]1148 result = get_filter("!last_seen():<=2020-04-01T19:34:52+00:00")1149 assert result.having == [["last_seen", ">", 1585769692]]1150 def test_release_latest(self):1151 result = get_filter(1152 "release:latest",1153 params={"organization_id": self.organization.id, "project_id": [self.project.id]},1154 )1155 assert result.conditions == [["release", "IN", [""]]]1156 # When organization id isn't included, project_id should unfortunately be an object1157 result = get_filter("release:latest", params={"project_id": [self.project]})1158 assert result.conditions == [["release", "IN", [""]]]1159 release_2 = self.create_release(self.project)1160 result = get_filter("release:[latest]", params={"project_id": [self.project]})1161 assert result.conditions == [["release", "IN", [release_2.version]]]1162 result = get_filter("release:[latest,1]", params={"project_id": [self.project]})1163 assert result.conditions == [["release", "IN", [release_2.version, "1"]]]1164 @pytest.mark.xfail(reason="this breaks issue search so needs to be redone")1165 def test_trace_id(self):1166 result = get_filter("trace:a0fa8803753e40fd8124b21eeb2986b5")1167 assert result.conditions == [["trace", "=", "a0fa8803-753e-40fd-8124-b21eeb2986b5"]]1168 def test_group_id_query(self):1169 # If a user queries on group_id, make sure it gets turned into a tag not the actual group_id field1170 assert get_filter("group_id:not-a-group-id-but-a-string").conditions == [1171 [["ifNull", ["tags[group_id]", "''"]], "=", "not-a-group-id-but-a-string"]1172 ]1173 assert get_filter("group_id:wildcard-string*").conditions == [1174 [1175 ["match", [["ifNull", ["tags[group_id]", "''"]], "'(?i)^wildcard\\-string.*$'"]],1176 "=",1177 1,1178 ]1179 ]1180 def test_shorthand_overflow(self):1181 with self.assertRaises(InvalidSearchQuery):1182 get_filter(f"transaction.duration:<{'9'*13}m")1183 with self.assertRaises(InvalidSearchQuery):1184 get_filter(f"transaction.duration:<{'9'*11}h")1185 with self.assertRaises(InvalidSearchQuery):1186 get_filter(f"transaction.duration:<{'9'*10}d")1187 def test_semver(self):1188 release = self.create_release(version="test@1.2.3")1189 release_2 = self.create_release(version="test@1.2.4")1190 _filter = get_filter(f"{SEMVER_ALIAS}:>=1.2.3", {"organization_id": self.organization.id})1191 assert _filter.conditions == [["release", "IN", [release.version, release_2.version]]]1192 assert _filter.filter_keys == {}1193 _filter = get_filter(f"{SEMVER_ALIAS}:>1.2.4-hi", {"organization_id": self.organization.id})1194 assert _filter.conditions == [["release", "IN", [release_2.version]]]1195 assert _filter.filter_keys == {}1196 def test_release_stage(self):1197 replaced_release = self.create_release(1198 version="replaced_release",1199 environments=[self.environment],1200 adopted=timezone.now(),1201 unadopted=timezone.now(),1202 )1203 self.create_release(1204 version="adopted_release",1205 environments=[self.environment],1206 adopted=timezone.now(),1207 )1208 not_adopted_release = self.create_release(1209 version="not_adopted_release", environments=[self.environment]1210 )1211 _filter = get_filter(1212 f"{RELEASE_STAGE_ALIAS}:adopted",1213 {"organization_id": self.organization.id, "environment": [self.environment.name]},1214 )1215 assert _filter.conditions == [1216 ["release", "IN", ["adopted_release"]],1217 [["environment", "=", "development"]],1218 ]1219 assert _filter.filter_keys == {}1220 _filter = get_filter(1221 f"{RELEASE_STAGE_ALIAS}:[{ReleaseStages.REPLACED}, {ReleaseStages.LOW_ADOPTION}]",1222 {"organization_id": self.organization.id, "environment": [self.environment.name]},1223 )1224 assert _filter.conditions == [1225 ["release", "IN", [replaced_release.version, not_adopted_release.version]],1226 [["environment", "=", "development"]],1227 ]1228 assert _filter.filter_keys == {}1229 _filter = get_filter(1230 f"!{RELEASE_STAGE_ALIAS}:[{ReleaseStages.ADOPTED}, {ReleaseStages.LOW_ADOPTION}]",1231 {"organization_id": self.organization.id, "environment": [self.environment.name]},1232 )1233 assert _filter.conditions == [1234 ["release", "IN", [replaced_release.version]],1235 [["environment", "=", "development"]],1236 ]1237 assert _filter.filter_keys == {}1238 with self.assertRaises(InvalidSearchQuery):1239 _filter = get_filter(1240 f"!{RELEASE_STAGE_ALIAS}:invalid", {"organization_id": self.organization.id}1241 )1242 with self.assertRaises(InvalidSearchQuery):1243 _filter = get_filter(1244 f"{RELEASE_STAGE_ALIAS}:[{ReleaseStages.REPLACED}, {ReleaseStages.LOW_ADOPTION}]",1245 {"organization_id": self.organization.id},1246 )1247def with_type(type, argument):1248 argument.get_type = lambda *_: type1249 return argument1250class DiscoverFunctionTest(unittest.TestCase):1251 def setUp(self):1252 self.fn_wo_optionals = DiscoverFunction(1253 "wo_optionals",1254 required_args=[FunctionArg("arg1"), FunctionArg("arg2")],1255 transform="",1256 )1257 self.fn_w_optionals = DiscoverFunction(...

Full Screen

Full Screen

test_profile.py

Source:test_profile.py Github

copy

Full Screen

...34 ]35 self.assertEqual(expected, prof.service_keys)36 def test_default_versions(self):37 prof = profile.Profile()38 self.assertEqual('v1', prof.get_filter('baremetal').version)39 self.assertEqual('v1', prof.get_filter('clustering').version)40 self.assertEqual('v2', prof.get_filter('compute').version)41 self.assertEqual('v1', prof.get_filter('database').version)42 self.assertEqual('v3', prof.get_filter('identity').version)43 self.assertEqual('v2', prof.get_filter('image').version)44 self.assertEqual('v2', prof.get_filter('network').version)45 self.assertEqual('v1', prof.get_filter('object-store').version)46 self.assertEqual('v1', prof.get_filter('orchestration').version)47 self.assertEqual('v1', prof.get_filter('key-manager').version)48 self.assertEqual('v2', prof.get_filter('metering').version)49 self.assertEqual('v2', prof.get_filter('volume').version)50 self.assertEqual('v1', prof.get_filter('messaging').version)51 def test_set(self):52 prof = profile.Profile()53 prof.set_version('alarming', 'v2')54 self.assertEqual('v2', prof.get_filter('alarming').version)55 prof.set_version('baremetal', 'v1')56 self.assertEqual('v1', prof.get_filter('baremetal').version)57 prof.set_version('clustering', 'v1')58 self.assertEqual('v1', prof.get_filter('clustering').version)59 prof.set_version('compute', 'v2')60 self.assertEqual('v2', prof.get_filter('compute').version)61 prof.set_version('database', 'v3')62 self.assertEqual('v3', prof.get_filter('database').version)63 prof.set_version('identity', 'v4')64 self.assertEqual('v4', prof.get_filter('identity').version)65 prof.set_version('image', 'v5')66 self.assertEqual('v5', prof.get_filter('image').version)67 prof.set_version('metering', 'v6')68 self.assertEqual('v6', prof.get_filter('metering').version)69 prof.set_version('network', 'v7')70 self.assertEqual('v7', prof.get_filter('network').version)71 prof.set_version('object-store', 'v8')72 self.assertEqual('v8', prof.get_filter('object-store').version)73 prof.set_version('orchestration', 'v9')74 self.assertEqual('v9', prof.get_filter('orchestration').version)75 def test_set_version_bad_service(self):76 prof = profile.Profile()77 self.assertRaises(exceptions.SDKException, prof.set_version, 'bogus',78 'v2')79 def test_set_api_version(self):80 # This tests that api_version is effective after explicit setting, or81 # else it defaults to None.82 prof = profile.Profile()83 prof.set_api_version('clustering', '1.2')84 svc = prof.get_filter('clustering')85 self.assertEqual('1.2', svc.api_version)86 svc = prof.get_filter('compute')87 self.assertIsNone(svc.api_version)88 def test_set_all(self):89 prof = profile.Profile()90 prof.set_name(prof.ALL, 'fee')91 prof.set_region(prof.ALL, 'fie')92 prof.set_interface(prof.ALL, 'public')93 for service in prof.service_keys:94 self.assertEqual('fee', prof.get_filter(service).service_name)95 self.assertEqual('fie', prof.get_filter(service).region)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run yandex-tank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful