Skip to content

TestingNode#152

Merged
camilamaia merged 2 commits intomasterfrom
assert
Jun 2, 2020
Merged

TestingNode#152
camilamaia merged 2 commits intomasterfrom
assert

Conversation

@camilamaia
Copy link
Copy Markdown
Member

@camilamaia camilamaia commented May 24, 2020

Description

TestingNode:

api:
  endpoints:
    - name: scanapi-demo
      path: ${BASE_URL}
      requests:
        - name: health
          method: get
          path: /health/
          tests:
            - name: Response Status is 200
              assert: ${{ response.status_code == 200 }}
            - name: Response Body Equals OK
              assert: ${{ response.content == b"OK!" }}
        - name: languages
          method: get
          path: /languages/
          tests:
            - name: Response Status is 200
              assert: ${{ response.status_code == 200 }}
      endpoints:
        - name: devs
          path: /devs/
          requests:
            - name: list_all
              method: get
              vars:
                uuid: ${{response.json()[2]["uuid"]}}
              tests:
                - name: Response Status is 200
                  assert: ${{ response.status_code == 200 }}
            - name: looking_for_new_opportunities
              method: get
              params:
                newOpportunities: true
              tests:
                - name: Response Status is 200
                  assert: ${{ response.status_code == 200 }}
            - name: not_looking_for_new_opportunities
              method: get
              params:
                newOpportunities: false
              tests:
                - name: Response Status is 200
                  assert: ${{ response.status_code == 200 }}
            - name: new
              method: post
              headers:
                x-api-key: ${DEMO_KEY}
              tests:
                - name: Response Status is 201
                  assert: ${{ response.status_code == 201 }}
              body:
                uuid: ${{uuid.uuid4().hex}}
                name: Tarik
                yearsOfExperience: 2
                languages:
                  - ruby
                    go
                newOpportunities: false
            - name: details_not_found
              path: 129e8cb2-d19c-51ad-9921-cea329bed7fa
              method: get
              tests:
                - name: Response Status is 404
                  assert: ${{ response.status_code == 404 }}
          endpoints:
            - name: details
              path: ${uuid}
              requests:
                - name: get
                  method: get
                  tests:
                    - name: Response Status is 200
                      assert: ${{ response.status_code == 200 }}
                - name: delete
                  method: delete
                  headers:
                    x-api-key: ${DEMO_KEY}
                  tests:
                    - name: Response Status is 200
                      assert: ${{ response.status_code == 200 }}
                - name: languages
                  path: languages
                  method: get
                  tests:
                    - name: Response Status is 200
                      assert: ${{ response.status_code == 200 }}

When tests passed:

Loading file .scanapi.yaml
Loading file api.yaml
Writing documentation
Making request GET http://demo.scanapi.dev/api/health/
 [PASSED] scanapi-demo::health::Response Status is 200
 [PASSED] scanapi-demo::health::Response Body Equals OK
Making request GET http://demo.scanapi.dev/api/languages/
 [PASSED] scanapi-demo::languages::Response Status is 200
Making request GET http://demo.scanapi.dev/api/devs/
 [PASSED] scanapi-demo::devs::list_all::Response Status is 200
Making request GET http://demo.scanapi.dev/api/devs/
 [PASSED] scanapi-demo::devs::looking_for_new_opportunities::Response Status is 200
Making request GET http://demo.scanapi.dev/api/devs/
 [PASSED] scanapi-demo::devs::not_looking_for_new_opportunities::Response Status is 200
Making request POST http://demo.scanapi.dev/api/devs/
 [PASSED] scanapi-demo::devs::new::Response Status is 201
Making request GET http://demo.scanapi.dev/api/devs/129e8cb2-d19c-51ad-9921-cea329bed7fa
 [PASSED] scanapi-demo::devs::details_not_found::Response Status is 404
Making request GET http://demo.scanapi.dev/api/devs/129e8cb2-d19c-41ad-9921-cea329bed7f0
 [PASSED] scanapi-demo::devs::details::get::Response Status is 200
Making request DELETE http://demo.scanapi.dev/api/devs/129e8cb2-d19c-41ad-9921-cea329bed7f0
 [PASSED] scanapi-demo::devs::details::delete::Response Status is 200
Making request GET http://demo.scanapi.dev/api/devs/129e8cb2-d19c-41ad-9921-cea329bed7f0/languages
 [PASSED] scanapi-demo::devs::details::languages::Response Status is 200

The documentation was generated successfully.
It is available at scanapi-report.md

When a test fails:

Loading file .scanapi.yaml
Loading file api.yaml
Writing documentation
Making request GET http://demo.scanapi.dev/api/health/
 [PASSED] scanapi-demo::health::Response Status is 200
 [PASSED] scanapi-demo::health::Response Body Equals OK
Making request GET http://demo.scanapi.dev/api/languages/
 [PASSED] scanapi-demo::languages::Response Status is 200
Making request GET http://demo.scanapi.dev/api/devs/
 [PASSED] scanapi-demo::devs::list_all::Response Status is 200
Making request GET http://demo.scanapi.dev/api/devs/
 [PASSED] scanapi-demo::devs::looking_for_new_opportunities::Response Status is 200
Making request GET http://demo.scanapi.dev/api/devs/
 [PASSED] scanapi-demo::devs::not_looking_for_new_opportunities::Response Status is 200
Making request POST http://demo.scanapi.dev/api/devs/
 [PASSED] scanapi-demo::devs::new::Response Status is 201
Making request GET http://demo.scanapi.dev/api/devs/129e8cb2-d19c-51ad-9921-cea329bed7fa
 [PASSED] scanapi-demo::devs::details_not_found::Response Status is 404
Making request GET http://demo.scanapi.dev/api/devs/129e8cb2-d19c-41ad-9921-cea329bed7f0
 [FAILED] scanapi-demo::devs::details::get::Response Status is 200
	  response.status_code == 300 is false
Making request DELETE http://demo.scanapi.dev/api/devs/129e8cb2-d19c-41ad-9921-cea329bed7f0
 [PASSED] scanapi-demo::devs::details::delete::Response Status is 200
Making request GET http://demo.scanapi.dev/api/devs/129e8cb2-d19c-41ad-9921-cea329bed7f0/languages
 [PASSED] scanapi-demo::devs::details::languages::Response Status is 200

The documentation was generated successfully.
It is available at scanapi-report.md

Closes #11

Next Steps:

  • Save tests information in a session.
  • Exit the program with an error when a test fails
  • Move information about tests to console/markdown/html reports

@camilamaia camilamaia changed the base branch from master to validate-keys May 25, 2020 11:30
@camilamaia camilamaia self-assigned this May 25, 2020
@camilamaia camilamaia changed the title Assert Add TestingNode May 25, 2020
@camilamaia camilamaia changed the title Add TestingNode TestingNode May 25, 2020
@camilamaia camilamaia added the Feature New feature or request label May 25, 2020
Comment thread scanapi/tree/testing_node.py Outdated
)
passed = "PASSED" if passed else "FAILED"
print(
f"[{passed}] {self.request.endpoint.name}::{self.request.name}::{self.name}"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to iterate here to check if there are more parent endpoints

@camilamaia camilamaia force-pushed the validate-keys branch 2 times, most recently from 7b85f08 to b19b924 Compare May 27, 2020 22:19
Base automatically changed from validate-keys to master May 27, 2020 22:22
@github-actions
Copy link
Copy Markdown

@camilamaia your pull request is missing a changelog!

@camilamaia camilamaia force-pushed the assert branch 4 times, most recently from 94f8b71 to 8989cd5 Compare May 31, 2020 22:30
@camilamaia camilamaia marked this pull request as ready for review May 31, 2020 22:35
Comment thread pytest.ini
@@ -1,3 +1,2 @@
[pytest]
addopts=-svvl
bdd_features_base_dir = tests/functional/features/
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not using pytest-bdd anymore

@camilamaia
Copy link
Copy Markdown
Member Author

@camilamaia camilamaia requested review from winstonf88 and removed request for djalmaaraujo June 1, 2020 12:32
Comment thread scanapi/evaluators/code_evaluator.py Outdated
try:
assert eval(code)
return (True, None)
except AssertionError as ae:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
except AssertionError as ae:
except AssertionError:

Comment thread scanapi/tree/endpoint_node.py Outdated
if self.is_root or not self.parent.name:
return name

return "::".join((self.parent.name, name))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return "::".join((self.parent.name, name))
return f"{self.parent.name}::{name}"


@classmethod
def evaluate(cls, sequence, vars):
def evaluate(cls, sequence, vars, is_a_test_case=False):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is_a_test_case looks kind of scattered all over

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@winstonf88 Hmmm indeed... Any ideas of how to minimize it?

Copy link
Copy Markdown
Member Author

@camilamaia camilamaia Jun 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to isolate it a bit more in a separated evaluate_assertion method, but we can do better in the future for sure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really cool! it's much more isolated. Great job.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, man 💚

@camilamaia camilamaia force-pushed the assert branch 2 times, most recently from 5cd5201 to 6c716d5 Compare June 1, 2020 13:14
Copy link
Copy Markdown
Contributor

@gillianomenezes gillianomenezes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty cool feature!

@camilamaia camilamaia merged commit 124983c into master Jun 2, 2020
@camilamaia camilamaia deleted the assert branch June 2, 2020 14:31
@camilamaia camilamaia mentioned this pull request Jun 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create Expected Assertions for Requests

3 participants