★ wanayoo — archive 1999 https://github.com/scanapi/scanapi/pull/328Nouvelle recherche | Portail wanayoo
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'vars' key to endpoint node #328

Merged
merged 1 commit into from Jul 2, 2021
Merged

Conversation

Copy link
Contributor

@gillianomenezes gillianomenezes commented Oct 27, 2020

Closes #302

@github-actions
Copy link

@github-actions github-actions bot commented Oct 27, 2020

@gillianomenezes your pull request is missing a changelog!

@camilamaia camilamaia mentioned this pull request May 4, 2021
@hebertjulio
Copy link
Member

@hebertjulio hebertjulio commented Jun 11, 2021

Hey @scanapi/core-team ,

Why this PR wasn't merged?

@camilamaia
Copy link
Member

@camilamaia camilamaia commented Jun 11, 2021

@hebertjulio because I did not have time to test it locally, to check if everything is working fine 😞
Do you wanna go ahead and test it? It would be awesome, I've been procrastinating this for a long time 😢

@hebertjulio
Copy link
Member

@hebertjulio hebertjulio commented Jun 12, 2021

Of course @camilamaia , I can go ahead, we are here for help. 😄

@hebertjulio hebertjulio self-assigned this Jun 14, 2021
CHANGELOG.md Outdated Show resolved Hide resolved
@hebertjulio hebertjulio force-pushed the enable-vars-keys-at-endpoint branch 2 times, most recently from 1514075 to 7d9e42d Compare Jun 16, 2021
@codecov-commenter
Copy link

@codecov-commenter codecov-commenter commented Jun 16, 2021

Codecov Report

Merging #328 (c97cf61) into master (3e09a66) will increase coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #328      +/-   ##
==========================================
+ Coverage   95.87%   95.95%   +0.08%     
==========================================
  Files          22       22              
  Lines         678      693      +15     
==========================================
+ Hits          650      665      +15     
  Misses         28       28              
Impacted Files Coverage Δ
scanapi/tree/endpoint_node.py 85.93% <ø> (ø)
scanapi/evaluators/spec_evaluator.py 96.42% <100.00%> (+0.97%) ⬆️
scanapi/tree/request_node.py 98.61% <100.00%> (+0.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3e09a66...c97cf61. Read the comment docs.

@hebertjulio
Copy link
Member

@hebertjulio hebertjulio commented Jun 16, 2021

Hey,

I created a PR at examples repository to endpoint vars test.

scanapi/examples#27

@camilamaia
Copy link
Member

@camilamaia camilamaia commented Jun 18, 2021

Hey,

I created a PR at examples repository to endpoint vars test.

scanapi/examples#27

@hebertjulio Awesome!! It is the best way to go! Only one detail: we need to first merge this PR, and then the examples one, right? Because we have github action checks that use the examples repo, and it would break if these changes are not there yet. https://github.com/scanapi/scanapi/blob/master/.github/workflows/run-examples.yml

We could try to: . If everything works we:

  • test this PR locally, using you example with vars in the endpoint
  • if everything works -> merge this PR
  • merge the example's pr

Does that make sense? What do you think?

@hebertjulio
Copy link
Member

@hebertjulio hebertjulio commented Jun 18, 2021

Yes @camilamaia , that make full sense for me. Locally I tested both PR, but is always good idea that other dev test them too.

@camilamaia
Copy link
Member

@camilamaia camilamaia commented Jun 18, 2021

@hebertjulio I am testing it locally here and it seems we have some problems. If we try to access custom vars or env vars, it is not working.

In this line https://github.com/scanapi/examples/pull/27/files#diff-0db9b47343ca8e1c3f4eb61cfabd9a0cdd11862492fb6c72f63a0d512c1e0476R4, try to change it for

vars:  
  greeting: ${USER}

It is not replacing the value:

image

With python code, it works fine:

vars:
  greeting: ${{ "hello" + "!" }}

image

Probably it is not working for custom vars either...

Also, i've started asking myself if the values are really being replaced in the vars at the response level too:

#  demo-api/snippets.yaml

name: snippets
path: snippets/
vars:
  greeting: ${{ "hello" + "!" }}
headers:
  Authorization: Token ${token}
requests:
- name: create
  method: post
  body:
    title: Hello World
    code: "print('${greeting} world')"
    style: "xcode"
    language: "python"
  vars:
    snippet_id: ${{response.json()["id"]}}
    my_var_1: aloha! # THIS IS NEW
    my_var_2: ${USER} # THIS IS NEW
  tests:
    - ...
- name: details
  path: ${snippet_id}
  vars:
    my_var_3: ${my_var_1} # THIS IS NEW
  tests:
    - ...

- name: update_with_patch
  path: ${snippet_id}/?${my_var_2}&${my_var_3} # THIS IS NEW
  method: patch
  body:
    code: "print('${greeting}, patch')"
  tests:
    - ...
...

And the result is that we already have a problem... custom vars are not being replaced:

image

Maybe we could have all these scenarion in our demo-api example.... And also, of course, in the unit tests 🤔

@hebertjulio hebertjulio force-pushed the enable-vars-keys-at-endpoint branch 4 times, most recently from c07a1be to 1be299e Compare Jun 18, 2021
@hebertjulio
Copy link
Member

@hebertjulio hebertjulio commented Jun 19, 2021

Hey @scanapi/core-team ,

I found two possible problem in request_node.py.

  1. The response from the previous request remains available before the new request is made. Maybe delete response in endpoint.vars before make new request be a good idea.

  2. When endpoint.vars with response value handling, like ${{response.json()['id']}} is loaded, an error is thrown late because the response doesn't exist yet or is it a response from the previous request, without id item in json. I thought about creating a filter to remove those vars that handle response, or something like that. I accepted suggestions.

self.endpoint.vars.update(
self.spec.get(VARS_KEY, {}), preevaluate=False,
)
session = session_with_retry(self.retry)
response = session.request(
method,
url,
headers=self.headers,
params=self.params,
json=self.body,
allow_redirects=False,
)
self.endpoint.vars.update(
self.spec.get(VARS_KEY, {}),
extras={"response": response},
preevaluate=True,
)

@camilamaia
Copy link
Member

@camilamaia camilamaia commented Jun 21, 2021

@hebertjulio great job! This is the core of the lib and you are getting familiar with it! It is amazing we have contributors who can discuss the core functions and how to solve this kind of problems 🤩 I love this stuff, I am super excited 🚀

For point 1, I like the idea of deleting the response every time, so the next flow would start clean. Maybe at the end of the RequestNode run method? Or did you think in another place?

About the point 2, in my opinion, the user should not be able to access response outside the request "level". Becaause, as you said, it is does not exist yet. We should raise a specific error saying that response does not exist outside the request.

What do you think?

@hebertjulio
Copy link
Member

@hebertjulio hebertjulio commented Jun 21, 2021

@hebertjulio great job! This is the core of the lib and you are getting familiar with it! It is amazing we have contributors who can discuss the core functions and how to solve this kind of problems star_struck I love this stuff, I am super excited rocket

For point 1, I like the idea of deleting the response every time, so the next flow would start clean. Maybe at the end of the RequestNode run method? Or did you think in another place?

About the point 2, in my opinion, the user should not be able to access response outside the request "level". Becaause, as you said, it is does not exist yet. We should raise a specific error saying that response does not exist outside the request.

What do you think?

Hey @camilamaia , thanks for the encouragement! 😄

About point 1, deleting the response at the end of the RequestNode run method sounds good to me. Now, about point 2, raise a specific error is a excellent idea, but I think not resolve the current problem, because error occurs when I load vars before make request e when I call self.body, self.headers and self.params, the evaluate method is called and code evaluate is executed.

@camilamaia
Copy link
Member

@camilamaia camilamaia commented Jun 22, 2021

@hebertjulio hmm I am not sure I got the problem 🤔 Do you wanna pair to try to solve this together?

@hebertjulio
Copy link
Member

@hebertjulio hebertjulio commented Jun 22, 2021

@hebertjulio hmm I am not sure I got the problem thinking Do you wanna pair to try to solve this together?

Yes, I wanna.

@camilamaia
Copy link
Member

@camilamaia camilamaia commented Jun 22, 2021

@hebertjulio awesome, let's do it via Discord!

@hebertjulio
Copy link
Member

@hebertjulio hebertjulio commented Jun 22, 2021

@hebertjulio awesome, let's do it via Discord!

Weekdays I get home at 20:30.

@hebertjulio hebertjulio force-pushed the enable-vars-keys-at-endpoint branch from 1be299e to 21960c9 Compare Jun 25, 2021
@hebertjulio hebertjulio force-pushed the enable-vars-keys-at-endpoint branch 2 times, most recently from cf20e4e to 6449a62 Compare Jun 25, 2021
@hebertjulio hebertjulio requested a review from leogregianin Jun 28, 2021
Copy link
Member

@camilamaia camilamaia left a comment

@hebertjulio, great effort so far! This PR is very tricky. Thanks for tackling it. I left some suggestions, let me know what you think.

Also, let me know if you need any help with the unit tests.

scanapi/evaluators/code_evaluator.py Outdated Show resolved Hide resolved
scanapi/evaluators/code_evaluator.py Outdated Show resolved Hide resolved
scanapi/evaluators/spec_evaluator.py Show resolved Hide resolved
scanapi/evaluators/spec_evaluator.py Show resolved Hide resolved
@hebertjulio hebertjulio force-pushed the enable-vars-keys-at-endpoint branch 3 times, most recently from c605f41 to 72fc17c Compare Jul 1, 2021
@hebertjulio
Copy link
Member

@hebertjulio hebertjulio commented Jul 1, 2021

Hey @camilamaia

Are Docstrings required in test functions? DeepSource is warning me about this.

@camilamaia
Copy link
Member

@camilamaia camilamaia commented Jul 1, 2021

Hey @camilamaia

Are Docstrings required in test functions? DeepSource is warning me about this.

No they aren't. Let me add a filter for it, 1 sec

@camilamaia
Copy link
Member

@camilamaia camilamaia commented Jul 1, 2021

@hebertjulio solved

@hebertjulio hebertjulio requested a review from camilamaia Jul 1, 2021
@hebertjulio hebertjulio force-pushed the enable-vars-keys-at-endpoint branch 2 times, most recently from 9b0a016 to ae6f1f6 Compare Jul 2, 2021
Copy link
Member

@camilamaia camilamaia left a comment

The solution is 💯 for me now! I left only some minor suggestions in the tests descriptions. But FINALLY this PR is almost ready to be merged 🙌 thanks!

scanapi/evaluators/spec_evaluator.py Show resolved Hide resolved
scanapi/evaluators/spec_evaluator.py Show resolved Hide resolved
tests/unit/evaluators/test_spec_evaluator.py Outdated Show resolved Hide resolved
tests/unit/evaluators/test_spec_evaluator.py Outdated Show resolved Hide resolved
@hebertjulio hebertjulio force-pushed the enable-vars-keys-at-endpoint branch from ae6f1f6 to c97cf61 Compare Jul 2, 2021
@hebertjulio hebertjulio requested a review from camilamaia Jul 2, 2021
Copy link
Member

@camilamaia camilamaia left a comment

👏👏👏

@camilamaia camilamaia merged commit f048deb into master Jul 2, 2021
9 checks passed
@camilamaia camilamaia deleted the enable-vars-keys-at-endpoint branch Jul 2, 2021
@camilamaia camilamaia mentioned this pull request Jul 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants