Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the real request in unit tests in Pyramid

I'm using Pyramid framework for my application. I'm writing unit tests (tests.py file), where I want to:

  1. get the actual request instead of dummyRequest and

  2. also want to get the values of variables defined in config (development.ini) file.

I have gone through How to get an actual Pyramid request when unit testing question as well, but didn't get much from it.

Let me know how above can be achieved.

like image 356
Workonphp Avatar asked Dec 05 '25 20:12

Workonphp


1 Answers

For your first "want", you can see this well-written SO post: How to get an actual Pyramid request when unit testing

It suggests to utilize the DummyRequest. "The thing to realize whenever you are unit testing (which is different from functional tests) is that you are testing a small 'unit'. This unit does not require a 'real' request, nor does it require a fully working system."


For your second "want", you can refer to the (1) Pyramid docs and (2) an SO post:

  1. http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html#adding-a-custom-setting
  2. how can i get the ini data in pyramid?

Essentially, in your view function, you can use request.registry.settings or pyramid.threadlocal.get_current_registry().settings, it behaves like a dictionary.

like image 112
Raj Avatar answered Dec 08 '25 09:12

Raj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!