Archive for July, 2008

Testing Django Applications

Tessie the Test Machine

So I’ve been here at Disqus for a month or so now. The biggest project on my plate had been testing. Because of the breadth of the Disqus software, my testing has to cover several different approaches to the platform.

The first two are fairly simple and well documented. The in-browser testing, less so.

The first two are easily supported in Django’s test framework. I can write python unittest classes that inherit from unittest.TestCase and Django test classes that inherit from django.test.TestCase and Django handles the rest. A quick python manage.py test is all it takes.

Selenium complicates things.

Since Selenium is scripting an actual browser, it needs a live web server to connect to and run tests against. I could run a webserver in a static location and point all Selenium tests at that server. This option, however, leaves us lacking in a couple of features that the Django test framework has left us accustomed to.

Django tests are run independently. A fresh database is created and optionally loaded from xml dumps between every method of tests in the test suite. As a result, one test has no effect on another. Simplifying cleanup and expected state.

If I run a static web server, I lose this benefit since the web server cannot use the test suite’s test database that gets recreated between every test.

This is a deal breaker. It makes Selenium tests much harder to write and maintain. As anyone who’s done testing knows, the harder tests are to write and maintain, the more likely they are to be ignored.

Enter Django Live Test Server Support

So I want to bring up a live server when starting every Selenium test. Turns out there was an existing Django ticket for this functionality posted two years ago.

So we here at Disqus decided this would a perfect opportunity to give something back to the Django community and help out anyone else setting out to do testing similar to ours. Along those lines, I’ve written a patch that adds the functionality to start and stop a test server in the Django TestCase class. Which we can use as follows:

class SampleLoginTest(TestCase):

    def setUp(self):
        self.start_test_server('0.0.0.0', 8000)
        self.selenium = selenium('localhost', 4444, '*pifirefox', 'http://127.0.0.1:8000')

    def tearDown(self):
        self.selenium.stop()
        self.stop_test_server()

    def test_login_fail(self):
        self.selenium.open('/')
        self.selenium.click('link=Login')
    ...

And so on.

We’re now using this patch on our internal copy of Django to manage our Selenium tests helping us keep a better eye on keeping everything working as expected.

We thought we’d share. If you’re setting out on writing tests for a Django application give the patch a try and let me know what you think. Questions and comments welcome at the usual place.

Happy testing!

Comments

Devin on July 21st 2008 in disqus

Message Flooding

One Disqus-enabled website was the recipient of an automated message flooding attack this morning. While malicious, it’s a bit different from what commercial spam is.

This attack put some stress on the Disqus service and a number of people may have had issues with accessing Disqus this morning. The entire incident, until all was completely smooth, lasted under 30 minutes. This was an isolated case and we’re implementing ways to address this moving forward.

Thanks,
Team Disqus

Comments

Daniel on July 15th 2008 in disqus

Claiming Your Unverified Profile and Comments

If you’ve posted a comment anonymously and now have a Disqus account, you can merge those old comments into your registered profile.

Head to the claim page to locate and claim your comments. Read on for a some information on how this works.

When a comment is posted, it can be one of two types:

  • a) Verified, posted by a registered member of Disqus
  • b) Unverified, posted “anonymously” by filling in some basic information (Name and email)

These comments are attached to a Disqus profile, which is also one of two types: either Verified or Unverified. To be verified, you must register an account so we know who you are.

A registered, verified account allows you more control and functionality: manage your past comments, receive email notifications, bypass most moderation, and rate other comments.

An unverified profile is indicated as this screenshot shows. If you come across your own unverified profile, click the “Claim” button to be taken to the Claim page.

That’s all, folks. Let us know if you run into any problems.

 

Comments

Daniel on July 7th 2008 in disqus