1

My django application is having a handler for each functionality (e.g. Salesinvoice handler for create/save/retrieve the invoice models with validation). These handlers are used in the views to perform the action user wanted (e.g. Create invoice).

  1. To ensure reliability of application, Will it be sufficient to unittest only the handlers? My idea in the above design is that if i need i can create a commandline interface using the handler instead of webinterface. Is this design of the application good to ensure reliably unittest django app? User request --> Views --> Handler (Unit test only the handler) --> Model

  2. *Is there any python/django library to automate the testing of views? * My goal is to ensure reliability of application by doing automated testing as much as possible.

18bytes
  • 5,951
  • 7
  • 42
  • 69
  • If you don’t test the views, all your HTTP processing code (that extracts request parameters, converts formats, etc.) will not be covered. Whether or not this is bad, depends on how complex this code is. – Vasiliy Faronov Jun 27 '12 at 09:03

1 Answers1

1

I don't quite understand what you mean with a "handler". Is it a view? Or a separate function that accepts a request?

Regarding the testing tools, you could simply use a library like requests to create requests and verify the results. There's also a builtin test client when using Django's internal testing framework.

If you want to actually test the views in your browser, you can use Selenium or webdriver plus, which is a wrapper for Selenium that makes it easier to use.

Potentially helpful links:

Danilo Bargen
  • 18,626
  • 15
  • 91
  • 127
  • handler is not a view, handler just encapsulates the functionality in one class. In other words, a handler is composed of many related functions. e.g. Sales invoice handler will have functions to create, get, delete a invoice. – 18bytes Jun 27 '12 at 09:25
  • Maybe you could use the generic class based views for CRUD stuff? To create commandline interfaces, you could use custom management commands, then you have directly access to the ORM. – Danilo Bargen Jun 27 '12 at 09:35
  • Thanks for the links, and its useful. – 18bytes Jun 27 '12 at 10:17