|
| 1 | +from behave import * |
| 2 | + |
| 3 | +from neo4j.v1 import ResultSummary, STATEMENT_TYPE_READ_ONLY, STATEMENT_TYPE_READ_WRITE, STATEMENT_TYPE_WRITE_ONLY, \ |
| 4 | + STATEMENT_TYPE_SCHEMA_WRITE |
| 5 | + |
| 6 | +from test.tck.resultparser import parse_values |
| 7 | + |
| 8 | +use_step_matcher("re") |
| 9 | + |
| 10 | + |
| 11 | +@step("the `Result Cursor` is summarized") |
| 12 | +def step_impl(context): |
| 13 | + context.summaries = [] |
| 14 | + for rc in context.rcs: |
| 15 | + context.summaries.append(rc.summarize()) |
| 16 | + |
| 17 | + |
| 18 | +@then("the `Result Cursor` is fully consumed") |
| 19 | +def step_impl(context): |
| 20 | + for rc in context.rcs: |
| 21 | + assert rc.at_end() |
| 22 | + assert rc.record() is None |
| 23 | + |
| 24 | + |
| 25 | +@then("a `Result Summary` is returned") |
| 26 | +def step_impl(context): |
| 27 | + for summary in context.summaries: |
| 28 | + assert isinstance(summary, ResultSummary) |
| 29 | + |
| 30 | + |
| 31 | +@step("I request a `statement` from the `Result Summary`") |
| 32 | +def step_impl(context): |
| 33 | + context.statements = [] |
| 34 | + for summary in context.summaries: |
| 35 | + context.statements.append(summary.statement) |
| 36 | + |
| 37 | + |
| 38 | +@then("requesting the `Statement` as text should give: (?P<expected>.+)") |
| 39 | +def step_impl(context, expected): |
| 40 | + for statement in context.statements: |
| 41 | + assert statement == expected |
| 42 | + |
| 43 | + |
| 44 | +@step("requesting the `Statement` parameter should give: (?P<expected>.+)") |
| 45 | +def step_impl(context, expected): |
| 46 | + for summary in context.summaries: |
| 47 | + assert summary.parameters == parse_values(expected) |
| 48 | + |
| 49 | + |
| 50 | +@step("requesting `update statistics` from it should give") |
| 51 | +def step_impl(context): |
| 52 | + for summary in context.summaries: |
| 53 | + for row in context.table: |
| 54 | + assert getattr(summary.statistics, row[0].replace(" ","_")) == parse_values(row[1]) |
| 55 | + |
| 56 | + |
| 57 | +@step("requesting the `Statement Type` should give (?P<expected>.+)") |
| 58 | +def step_impl(context, expected): |
| 59 | + for summary in context.summaries: |
| 60 | + if expected == "read only": |
| 61 | + statement_type = STATEMENT_TYPE_READ_ONLY |
| 62 | + elif expected == "read write": |
| 63 | + statement_type = STATEMENT_TYPE_READ_WRITE |
| 64 | + elif expected == "write only": |
| 65 | + statement_type = STATEMENT_TYPE_WRITE_ONLY |
| 66 | + elif expected == "schema write": |
| 67 | + statement_type = STATEMENT_TYPE_SCHEMA_WRITE |
| 68 | + else: |
| 69 | + raise ValueError("Not recognisable statement type: %s" % expected) |
| 70 | + assert summary.statement_type == statement_type |
| 71 | + |
| 72 | + |
| 73 | +@step("the summary has a `plan`") |
| 74 | +def step_impl(context): |
| 75 | + for summary in context.summaries: |
| 76 | + assert summary.plan is not None |
| 77 | + |
| 78 | + |
| 79 | +@step("the summary has a `profile`") |
| 80 | +def step_impl(context): |
| 81 | + for summary in context.summaries: |
| 82 | + assert summary.profile is not None |
| 83 | + |
| 84 | + |
| 85 | +@step("the summary does not have a `plan`") |
| 86 | +def step_impl(context): |
| 87 | + for summary in context.summaries: |
| 88 | + assert summary.plan is None |
| 89 | + |
| 90 | + |
| 91 | +@step("the summary does not have a `profile`") |
| 92 | +def step_impl(context): |
| 93 | + for summary in context.summaries: |
| 94 | + assert summary.profile is None |
| 95 | + |
| 96 | + |
| 97 | +@step("requesting the `(?P<plan_type>.+)` it contains") |
| 98 | +def step_impl(context, plan_type): |
| 99 | + for summary in context.summaries: |
| 100 | + if plan_type == "plan": |
| 101 | + plan = summary.plan |
| 102 | + elif plan_type == "profile": |
| 103 | + plan = summary.profile |
| 104 | + else: |
| 105 | + raise ValueError("Expected 'plan' or 'profile'. Got: %s" % plan_type) |
| 106 | + for row in context.table: |
| 107 | + assert getattr(plan, row[0].replace(" ", "_")) == parse_values(row[1]) |
| 108 | + |
| 109 | + |
| 110 | +@step("the `(?P<plan_type>.+)` also contains method calls for") |
| 111 | +def step_impl(context, plan_type): |
| 112 | + for summary in context.summaries: |
| 113 | + if plan_type == "plan": |
| 114 | + plan = summary.plan |
| 115 | + elif plan_type == "profile": |
| 116 | + plan = summary.profile |
| 117 | + else: |
| 118 | + raise ValueError("Expected 'plan' or 'profile'. Got: %s" % plan_type) |
| 119 | + for row in context.table: |
| 120 | + assert getattr(plan, row[0].replace(" ", "_")) is not None |
| 121 | + |
| 122 | + |
| 123 | +@step("the summaries collection of `notifications` is empty") |
| 124 | +def step_impl(context): |
| 125 | + for summary in context.summaries: |
| 126 | + assert len(summary.notifications) == 0 |
| 127 | + |
| 128 | + |
| 129 | +@step("the summaries collection of `notifications` is not empty") |
| 130 | +def step_impl(context): |
| 131 | + for summary in context.summaries: |
| 132 | + print(summary.notifications) |
| 133 | + assert len(summary.notifications) != 0 |
0 commit comments