Created
May 8, 2013 00:13
-
-
Save reinaldons/5537246 to your computer and use it in GitHub Desktop.
MongoDB with no disk file persist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
from time import sleep | |
import os | |
import unittest | |
import tempfile | |
from subprocess import Popen, PIPE | |
from flask import url_for | |
import flaskr | |
def is_open(ip,port): | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
try: | |
s.connect((ip, int(port))) | |
s.shutdown(2) | |
return True | |
except: | |
return False | |
class FlaskrTestCase(unittest.TestCase): | |
@classmethod | |
def setUpClass(self): | |
try: | |
os.mkdir('test_db') | |
except Exception, e: | |
pass | |
self.mongod = Popen(['mongod', '--smallfiles', '--noprealloc', '--syncdelay', '0', '--nojournal', '--dbpath', 'test_db' ], stdout=PIPE) | |
while not is_open('localhost', 27017): | |
sleep(0.1) | |
@classmethod | |
def tearDownClass(self): | |
self.mongod.terminate() | |
while is_open('localhost', 27017): | |
sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment