-
Notifications
You must be signed in to change notification settings - Fork 375
How to setup testcontainer in Django Rest Framwork + mongodb replica set #823
Unanswered
AnujChhikara
asked this question in
Q&A
-
We have a django rest framework project and we are using mongodb with replica set , I want to use testcontainer for integration test but I don't find any good doc regarding this also I am able to start the containers and when just using it for like this
from testcontainers.mongodb import MongoDbContainer
from pymongo import MongoClient
from django.test import TestCase
class MongoIntegrationTest(TestCase):
def test_mongodb_integration(self):
with MongoDbContainer("mongo:latest") as mongo:
client = MongoClient(mongo.get_connection_url())
db = client.testdb
collection = db.testcollection
collection.insert_one({"name": "test"})
result = collection.find_one({"name": "test"})
print(result)
self.assertEqual(result["name"], "test")
It is working fine but as soon i start integrating with my integration test I am facing issue mostly around replica set refuse to connect etc.
this is how we are setting replica in main prod db
command: >
sh -c "
mongod --replSet rs0 --bind_ip_all --logpath /var/log/mongodb.log --logappend &
sleep 5 &&
mongosh --eval 'try { rs.initiate() } catch(e) { print(e) }' &&
tail -f /var/log/mongodb.log
"
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment