3

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.

Community
  • 1
  • 1
Workonphp
  • 1,635
  • 1
  • 19
  • 21

1 Answers1

2

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.

Community
  • 1
  • 1
Raj
  • 1,479
  • 3
  • 15
  • 29
  • +1 Thanks! but I am not getting anything in pyramid.threadlocal.get_current_registry().settings(Returning as None). Please let me know if it is as expected or I am missing something. In case if it is 'None', then how to access the values defined in .ini file. – Workonphp May 16 '14 at 15:34
  • Have you indicated the settings file to use? You can take a look at line 15 of this Gist for an example: https://gist.github.com/sontek/1420255#file-gistfile1-py-L15 – Raj May 17 '14 at 02:37