Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9237113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:27:40+00:00 2026-06-18T07:27:40+00:00

The tests that I have written for my Django application have been working perfectly

  • 0

The tests that I have written for my Django application have been working perfectly during initial development where I have been using SQLite. Now that I am getting ready to deploy I have setup a MySQL server (as that is what I’ll be deploying to) but now some of my tests are failing.

Lastly the tests that are failing don’t fail when I manually test the functionality.

What could be going on?

I’m not doing anything unusual, all of the views do some database shenanigans and return a response. There isn’t anything timing related (no threading or anything).

The tests all inherit from django.test.TestCase and I’m not using any fixtures.

Here is an example of a test that fails.

class BaseTest(TestCase):
    def setUp(self):
        super(BaseTest, self).setUp()

        self.userCreds = dict(username='test', password='a')

        # Create an admin user
        admin = models.User.objects.create_superuser(
            email='', username='admin', password='a')

        # Create a user and grant them a licence
        user = models.User.objects.create_user(
            email='some@address.com', first_name="Mister",
            last_name="Testy", **self.userCreds)

        profile = models.getProfileFor(user)
        node = profile.createNode(
            '12345', 'acomputer', 'auser',
            'user@email.com', '0456 987 123')

        self.node = node

class TestClientUIViews(BaseTest):
    def test_toggleActive(self):
        url = reverse('toggleActive') + '?nodeId=%s' % self.node.nodeId

        self.assertFalse(self.node.active)

        # This should fail because only authenticated users can toggle a node active
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 403)
        self.assertFalse(self.node.active)

        # Login and make sure visiting the url toggles the active state
        self.client.login(**self.userCreds)
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
        self.assertTrue(self.node.active)

        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
        self.assertFalse(self.node.active)

And here is what the model looks like:

class Node(models.Model):
    @property
    def active(self):
        '''
        Activation state gets explictly tracked in its own table but is
        exposed as a property for the sake of convenience
        '''
        activations = NodeActivation.objects \
            .filter(node=self) \
            .order_by('-datetime')

        try:
            return activations[0].active
        except IndexError:
            return False

    @active.setter
    def active(self, state):
        if self.active != state:
            NodeActivation.objects.create(node=self, active=state)

class NodeActivation(models.Model):
    node = models.ForeignKey("Node")
    datetime = models.DateTimeField(default=datetimeM.datetime.now)
    active = models.BooleanField(default=False)

My local MySQL is 5.5.19 (so its using InnoDB) but I get the same failures on the deployment server which is using 5.1.56. The tests fail regardless of the storage engine.

And as I mentioned at the beginning, if I switch back to use a SQLite database, all the tests go back to passing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:27:42+00:00Added an answer on June 18, 2026 at 7:27 am

    By changing the active property on the Node model class to this:

    @property
    def active(self):
        '''
        Activation state gets explictly tracked in its own table but is
        exposed as a property for the sake of convenience
        '''
        activations = NodeActivation.objects \
            .filter(node=self) \
            .order_by('-id')
    
        try:
            return activations[0].active
        except IndexError:
            return False
    

    the problem goes away.

    Note the change to the order_by call.

    The records were getting created so quickly that ordering by datetime wasn’t deterministic, hence the erratic behaviour. And I guess SQLite is just slower than MySQL which is why it wasn’t a problem when using it as the backing database.

    NOTE: Thanks to Austin Phillips for the tip (check out comments in his answer)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written an application that unit tests our hardware via a internet browser.
I have written unit tests under NUnit that use TestFixtures with different parameters. Now,
I'm writing unit tests for a project (written in PHP, using PHPUnit) that have
I have some unit tests that I'm writing for a WPF application, and as
I have written a java program that tests the speed of a couple of
i have written an application that needs to process outgoing calls. Everything works fine,
I have several session beans that I have written unit tests for. I have
I have been writing some a django project / app that initiates some test
I have written a bookmarklet that receives a Django form and inserts it into
I have a Django (v1.4, using Postgresql) project which I've written a bunch of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.