blob: 1074f09101620190068351c5dac709cf4959ec2d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import couchdb
import pytest
import random
import string
@pytest.fixture
def random_name():
return 'user-' + ''.join(
random.choice(
string.ascii_lowercase) for _ in range(10))
class RandomDatabase(object):
def __init__(self, couch_url, name):
self.couch_url = couch_url
self.name = name
self.server = couchdb.client.Server(couch_url)
self.database = self.server.create(name)
def teardown(self):
self.server.delete(self.name)
@pytest.fixture
def db(random_name, request):
couch_url = request.config.getoption('--couch-url')
db = RandomDatabase(couch_url, random_name)
request.addfinalizer(db.teardown)
return db
|