I have a somewhat large Django project with many views/models. I recently migrated my project from sqlite3 to postgres locally, and plan to scale it out even further (put postgres on a separate machine, etc).
I followed these instructions when I migrated from sqlite to postgres, and it appears to have worked perfectly. (ie, my running app looks identical to when the db was sqlite)
My issue is this: When I run my previously-written unittests, the first unittest works and all proceeding unittests fail. Individually, the unittests work fine. I've seen some other posts on stackoverflow that addressed this issue, but the solutions were so unclear. How can I rework my setUp()
/ teardown()
methods for my unittests so that they will pass with my newly migrated postgres db? Do i need to completely rewrite all unittests?
I've seen the pytest-postgresql library, although I'm not entirely sure how to modify my unittests based off of this.
My testing suite is set up with different classes that test views. So for example,
class View1Tests(TestCase):
def setUp(self):
c1 = Category.objects.create(id=55555, leaf_node_name="Test Category 1")
c2 = Category.objects.create(id=12345, leaf_node_name="Test Category 2")
s1 = Search.objects.create(category=c1, username="testuser")
s2 = Search.objects.create(category=c2, username="testuser2")
def test_view1_success(self):
#blablabla
def test_view1_fail(self):
#blablabla
def test_view1_something(self):
#blablabla
I'm getting errors like this:
appname.models.DoesNotExist: Search matching query does not exist.
Again, all of these unittests run perfectly fine when sqlite3 was the db. I think its an issue with the postgres testing settings? But I'm at a loss as to where to even begin. Any help would be appreciated!!