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

A new keyword "Last REST Instance" is implemented #105

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

TeddyTeddy
Copy link

@TeddyTeddy TeddyTeddy commented Aug 26, 2020

This keyword allows the very last instance to be written to a file.
This becomes handy, when you just made a request and you want to get the instance for it.

A sample usage would be:

*** Keywords ***
Gather Instances While Creating Parameterized Resources
    [Arguments]     ${record list}         ${private token}
    FOR     ${record}    IN      @{record list}
        POST    /projects       body=${record}[json_resource]    headers=${private token}
        Last Rest Instance      file_path=${record}[on_create_instance]      sort_keys=True     # instance for the POST request
    END

@asimell
Copy link
Contributor

asimell commented Apr 30, 2021

@TeddyTeddy This functionality seems to exist already? You can give a file_path argument to Output keyword, which then writes your output into a file.

@TeddyTeddy
Copy link
Author

@asimell , as per your comment:

@TeddyTeddy This functionality seems to exist already? You can give a file_path argument to Output keyword, which then writes your output into a file.

Hi! Yes, output keyword does write the request & response schema to a file, but it does not write the whole instance. The instance is a larger entity, which is composed of:

  • request in JSON
  • response in JSON
  • the contract: the request schema + the response schema

If we want to have the instance as a record into a file, this utility keyword "Last REST Instance" would be helpful.

@asyrjasalo
Copy link
Owner

I think @asimell is correct. There is a way to achieve above without adding a new keyword.

request_properties["body"] = self._new_schema(request["body"])
request_properties["query"] = self._new_schema(request["query"])
response_properties["body"] = self._new_schema(response["body"])
self._form_sub_schema(request_properties, request)
Copy link
Author

Choose a reason for hiding this comment

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

@asyrjasalo @asimell Sure, you can opt out my "Last REST Instance" keyword; but one change here that you might need to take into consideration is that before my changes only request & response body were outputted, but with my changes every key/value pair in the request & response are now outputted via "Last REST Instance" keyword.

Also, the end user of the library would have to write & maintain a function containing at least 10 lines of code, while
the library itself has the instance data already ready to be written into a file. Imagine that tens of users does the same. Isn't that a wasteful effort from the end users' perspective?

I have nothing further to say. Thanks anyway bringing life back to this important library.

Copy link
Contributor

@asimell asimell May 3, 2021

Choose a reason for hiding this comment

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

only request & response body were outputted

Incorrect. If you call Output without any parameters it outputs the full request and response object. You can then redirect this output into a file with the file_path argument, e.g Output file_path=my_output.json

There's also Output Schema to output the schema only and you can give a file_path argument to that keyword as well.

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.

None yet

3 participants