Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to setup testcontainer in Django Rest Framwork + mongodb replica set #823

Unanswered
AnujChhikara asked this question in Q&A
Discussion options

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
 "
You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /