-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow variables to be used globally
- Loading branch information
1 parent
204e73a
commit 26511c2
Showing
8 changed files
with
146 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from pytest import mark | ||
|
||
from scanapi.tree import EndpointNode | ||
|
||
|
||
@mark.describe("endpoint node") | ||
@mark.describe("get_all_vars") | ||
class TestGetAllVars: | ||
@mark.it("should return spec_var values from the node and all parents") | ||
def test_get_all_vars(self): | ||
grandparent = EndpointNode({"name": "grandparent"}) | ||
grandparent_key = "grandparent_key" | ||
grandparent_value = "grandparent_value" | ||
grandparent.spec_vars.registry[grandparent_key] = grandparent_value | ||
parent = EndpointNode({"name": "parent"}, grandparent) | ||
parent_key = "parent_key" | ||
parent_value = "parent_value" | ||
parent.spec_vars.registry[parent_key] = parent_value | ||
node = EndpointNode({"name": "node"}, parent) | ||
node_key = "node_key" | ||
node_value = "node_value" | ||
node.spec_vars.registry[node_key] = node_value | ||
|
||
spec_vars = node.get_all_vars() | ||
|
||
assert spec_vars == { | ||
grandparent_key: grandparent_value, | ||
parent_key: parent_value, | ||
node_key: node_value, | ||
} | ||
|
||
@mark.it("should alter the content of spec_vars") | ||
def test_do_not_alter_spec_var(self): | ||
parent = EndpointNode({"name": "parent"}) | ||
parent_key = "parent_key" | ||
parent_value = "parent_value" | ||
parent.spec_vars.registry[parent_key] = parent_value | ||
node = EndpointNode({"name": "node"}, parent) | ||
node_key = "node_key" | ||
node_value = "node_value" | ||
node.spec_vars.registry[node_key] = node_value | ||
|
||
node.get_all_vars() | ||
|
||
assert parent.spec_vars.registry == {parent_key: parent_value} | ||
assert node.spec_vars.registry == {node_key: node_value} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from pytest import mark | ||
|
||
from scanapi.tree import EndpointNode | ||
|
||
|
||
@mark.describe("endpoint node") | ||
@mark.describe("propagate_spec_vars") | ||
class TestPropagateSpecVars: | ||
test_data = [ | ||
({"spec_var": "value"}, None, {"spec_var": "value"}), | ||
( | ||
{"spec_var": "${{ response }}"}, | ||
{"response": "value"}, | ||
{"spec_var": "value"}, | ||
), | ||
] | ||
|
||
@mark.it("should update spec_vars of node and all parent nodes") | ||
@mark.parametrize("new_spec_vars, extra, expected_result", test_data) | ||
def test_propagate_spec_vars(self, new_spec_vars, extra, expected_result): | ||
grandparent = EndpointNode({"name": "grandparent"}) | ||
parent = EndpointNode({"name": "parent"}, grandparent) | ||
node = EndpointNode({"name": "node"}, parent) | ||
|
||
node.propagate_spec_vars(new_spec_vars, extra) | ||
|
||
assert node.spec_vars.registry == expected_result | ||
assert parent.spec_vars.registry == expected_result | ||
assert grandparent.spec_vars.registry == expected_result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters