Friday 15 August 2014

python - Django Nose how to write this test? -


I am completely new in test in Django I nose And started installing selenium and now I want to test the following code (below) this sends an SMS message I

This is real Code:

views.py

  @login_required def process_all (request): "" "I use a single or bulk message (message) Process to send to a group or a single contact The ultimate request: "#" If we had a post get the request post value. If request.method == 'Post': batches = Batch.objects.for_user_pending (request.user) for batches in batches: ProcessRequests .delay (batch) batch.complete_update () returned HttpResponseRedirect ('/ report / message' ')   

So where do I start? I have done so far ...

1) created a folder named after a test and added init .py

2) has created a new Python file named test_views.py (I Assuming that this correct).

Now, how do I write this test? Itemprop = "text">

First of all, you do not need selenium for testing scenes. Selenium is a tool for high-level in-browser testing - when you imitate a real user, it is good and useful when writing a UI test.

The nose is a tool that makes easy to test by providing facilities like automatic testing, providing many helpful tasks and so on. The best way to integrate the nose with your project is to use the package. All you have to do is:

  1. To add django_nose to INSTALLED_APPS
  2. defined TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'

    Then, every time you run Python manage.py Testing & lt; PROJECT_NAME & gt; The nose will be used to run your test.


    So, talking about this special visual test, you should test:

    • Decorator work - In other words, the uncertified user redirected to the login page
    • If the request.method is not posted, no message has been sent, / reports / messages
    • Redirect to when the messaging method is used + / reports / messages

      The first two statements It is enough to test But to test the final statement you need to provide batch , ProcessRequests and more details on how it works, I mean, you probably tested Do not want to send real SMS messages - this is where help will actually help you fake (replace it with your own implementation on the fly) batch , ProcessRequests objects is required. Here's an example of what you should be in test_views.py :

        import from django.core.urlresolvers from django.contrib.auth.models User reverse Django Import .test.client import client django.test import testcase class from ProcessAllTestCase (testcase): Def setup (self): self.client = client () self.user = User.objects.create_user ('John', 'Lennon @ Beatles.com, 'johnpassword') def test_login_required (auto): response = self.client.get (reverse ('process_all')) self.assertRedirects (feedback, '/ login') Def test_get_method (self): self.client .login (Username = 'john', password = 'johnpassword')) Self.client.get (reverse ('process_all')) self.assertRedirects (response, '/ report / message') # no message sent DRE test_post_method itself): self.client.login (user name = 'john' , Password = 'JOI password') # Add pending message, sending fake SMS? Response = self.client.post (reverse ('process_all')) self.assertRedirects (feedback, '/ report / message') # indicates that the SMS message was sent   

      this also See: <

    • Hope that helps.

No comments:

Post a Comment