11
11
# License for the specific language governing permissions and limitations
12
12
# under the License.
13
13
import os
14
-
14
+ from pymongo import MongoClient
15
15
from testcontainers .core .generic import DbContainer
16
16
from testcontainers .core .waiting_utils import wait_container_is_ready
17
17
@@ -50,21 +50,18 @@ class MongoDbContainer(DbContainer):
50
50
MONGO_INITDB_ROOT_PASSWORD = os .environ .get ("MONGO_INITDB_ROOT_PASSWORD" , "test" )
51
51
MONGO_DB = os .environ .get ("MONGO_DB" , "test" )
52
52
53
- def __init__ (self ,
54
- image : str = "mongo:latest" ,
55
- port_to_expose : int = 27017 ,
56
- ** kwargs ):
53
+ def __init__ (self , image : str = "mongo:latest" , port_to_expose : int = 27017 , ** kwargs ) -> None :
57
54
super (MongoDbContainer , self ).__init__ (image = image , ** kwargs )
58
55
self .command = "mongo"
59
56
self .port_to_expose = port_to_expose
60
57
self .with_exposed_ports (self .port_to_expose )
61
58
62
- def _configure (self ):
59
+ def _configure (self ) -> None :
63
60
self .with_env ("MONGO_INITDB_ROOT_USERNAME" , self .MONGO_INITDB_ROOT_USERNAME )
64
61
self .with_env ("MONGO_INITDB_ROOT_PASSWORD" , self .MONGO_INITDB_ROOT_PASSWORD )
65
62
self .with_env ("MONGO_DB" , self .MONGO_DB )
66
63
67
- def get_connection_url (self ):
64
+ def get_connection_url (self ) -> str :
68
65
return self ._create_connection_url (
69
66
dialect = 'mongodb' ,
70
67
username = self .MONGO_INITDB_ROOT_USERNAME ,
@@ -73,9 +70,8 @@ def get_connection_url(self):
73
70
)
74
71
75
72
@wait_container_is_ready ()
76
- def _connect (self ):
77
- from pymongo import MongoClient
73
+ def _connect (self ) -> MongoClient :
78
74
return MongoClient (self .get_connection_url ())
79
75
80
- def get_connection_client (self ):
76
+ def get_connection_client (self ) -> MongoClient :
81
77
return self ._connect ()
0 commit comments