asyrjasalo / RESTinstance

Robot Framework library for RESTful JSON APIs
https://pypi.org/project/RESTinstance
GNU Lesser General Public License v3.0
205 stars 84 forks source link

Question: How to unset/clear state of "Set Headers"? #78

Closed Tset-Noitamotua closed 4 years ago

Tset-Noitamotua commented 5 years ago

As the Set Headers keyword always adds items to a request header it would be handy to have a keyword to either remove single items from header or completely unset the headers. I am aware of the headers= option of keywords like Get, Post, etc. but this overrides given header items only.

What if I want to remove/deactivate a single header item?

Example

What is the best way to clear headers completely? headers={} doesn't help?

DoanhPoPu commented 4 years ago

If it's separated test cases, you can change ROBOT_LIBRARY_SCOPE to TEST CASE. It will clear all each tests and you need to reset again.

asyrjasalo commented 4 years ago

@Tset-Noitamotua: Could you post a practical use case where you need to remove headers?

asyrjasalo commented 4 years ago

Yes, ROBOT_LIBRARY_SCOPE is Test Suite. Thus, you can reset headers, and get rid of what you don't need to use in further tests, by organising your test cases in test suites according to this.

Clever. That's right.

Tset-Noitamotua commented 4 years ago

@DoanhPoPu that's a really good idea. But as @asyrjasalo says RESTinstance uses TEST SUITE scope. And there is no way to change ROBOT_LIBRARY_SCOPE during import of REST library yet. That means one would have to patch RESTinstance library code to use this solution.

Here is related text in RF User Guide: Test library scope

Thus it would be really cool to have a possibility to change library scope during import. Like this:

*** Settings ***
Library    REST    scope=TEST CASE
# OR
Library    REST    library_scope=TEST CASE
Tset-Noitamotua commented 4 years ago

On the other hand such solution (while it is good) would be some what implicit while a keyword like Unset Headers or an option like Set Headers clear=True would be more explicit.

related issue: #82

asyrjasalo commented 4 years ago

Yeah, it's true what you say regarding having a separate keyword - but it's unneeded when as a bonus (with some more effort) you get your test cases organised well in addition.

This is what I want people to look forward into. As I see it's for their best.

testautomation commented 4 years ago

Hi Anssi (@asyrjasalo), may we reopen this one? I run into this issue once again. And even if I agree with you last comment I think sometimes it's good to have some additional option :-)

🙏