Révision e5b05b4d
Ajouté par Serghei Mihai (congés, retour 15/05) il y a presque 7 ans
tests/conftest.py | ||
---|---|---|
1 | 1 |
import pytest |
2 | 2 |
import django_webtest |
3 | 3 |
import copy |
4 |
import tempfile |
|
5 |
import os |
|
6 |
import json |
|
7 |
import shutil |
|
4 | 8 |
|
5 | 9 |
import django.core.mail.backends.locmem |
6 | 10 |
from django.core.mail.backends.locmem import EmailBackend as DjangoEmailBackend |
11 |
from django.utils.text import slugify |
|
12 |
|
|
13 |
from corbo.models import Category, Announce, Broadcast, Subscription |
|
14 |
|
|
15 |
CATEGORIES = ('Alerts', 'News') |
|
16 |
|
|
17 |
SUBSCRIBERS = [{'uuid': 'uuid1', 'email': 'foo@example.net', 'mobile': '0102030405'}, |
|
18 |
{'uuid': 'uuid2', 'email': 'bar@example.net', 'mobile': '0607080900'}, |
|
19 |
{'uuid': '', 'email': 'john@example.net', 'mobile': '0304050607'}, |
|
20 |
{'uuid': None, 'email': 'john2@example.net', 'mobile': '0405060708'}] |
|
21 |
|
|
7 | 22 |
|
8 | 23 |
|
9 | 24 |
class MockedEmailBackend(object): |
... | ... | |
42 | 57 |
wtm._patch_settings() |
43 | 58 |
request.addfinalizer(wtm._unpatch_settings) |
44 | 59 |
return django_webtest.DjangoTestApp() |
60 |
|
|
61 |
|
|
62 |
@pytest.fixture |
|
63 |
def categories(): |
|
64 |
categories = [] |
|
65 |
for category in CATEGORIES: |
|
66 |
c, created = Category.objects.get_or_create(name=category, slug=slugify(category)) |
|
67 |
categories.append(c) |
|
68 |
return categories |
|
69 |
|
|
70 |
|
|
71 |
@pytest.fixture |
|
72 |
def subscriptions(categories): |
|
73 |
subscriptions = [] |
|
74 |
for category in categories: |
|
75 |
for subscriber in SUBSCRIBERS: |
|
76 |
kwargs = {'category': category, 'identifier': 'mailto:%(email)s' % subscriber} |
|
77 |
uuid = subscriber['uuid'] |
|
78 |
if uuid is not None: |
|
79 |
kwargs['uuid'] = uuid |
|
80 |
subscriptions.append(Subscription.objects.create(**kwargs)) |
|
81 |
kwargs['identifier'] = 'sms:%(mobile)s' % subscriber |
|
82 |
subscriptions.append(Subscription.objects.create(**kwargs)) |
|
83 |
return subscriptions |
|
84 |
|
|
85 |
|
|
86 |
@pytest.fixture |
|
87 |
def tenant_base(request, settings): |
|
88 |
base = tempfile.mkdtemp('corbo-tenant-base') |
|
89 |
settings.TENANT_BASE = base |
|
90 |
|
|
91 |
def fin(): |
|
92 |
shutil.rmtree(base) |
|
93 |
request.addfinalizer(fin) |
|
94 |
return base |
|
95 |
|
|
96 |
|
|
97 |
@pytest.fixture(scope='function') |
|
98 |
def tenant(transactional_db, request, tenant_base): |
|
99 |
from hobo.multitenant.models import Tenant |
|
100 |
base = tenant_base |
|
101 |
|
|
102 |
@pytest.mark.django_db |
|
103 |
def make_tenant(name): |
|
104 |
tenant_dir = os.path.join(base, name) |
|
105 |
os.mkdir(tenant_dir) |
|
106 |
with open(os.path.join(tenant_dir, 'hobo.json'), 'w') as fd: |
|
107 |
json.dump({ |
|
108 |
'variables': { |
|
109 |
'hobo_test_variable': True, |
|
110 |
'other_variable': 'foo', |
|
111 |
}, |
|
112 |
'services': [ |
|
113 |
{'slug': 'test', |
|
114 |
'service-id': 'corbo', |
|
115 |
'title': 'Test', |
|
116 |
'this': True, |
|
117 |
'secret_key': '12345', |
|
118 |
'base_url': 'http://%s' % name, |
|
119 |
'saml-sp-metadata-url': 'http://%s/metadata/' % name, |
|
120 |
'variables': { |
|
121 |
'other_variable': 'bar', |
|
122 |
} |
|
123 |
}, |
|
124 |
{'slug': 'passerelle', |
|
125 |
'title': 'Webserivces', |
|
126 |
'service-id': 'passerelle', |
|
127 |
'secret_key': 'abcdef', |
|
128 |
'base_url': 'http://passerelle.example.net', |
|
129 |
'saml-sp-metadata-url': 'http://passerelle.example.net/metadata/' }, |
|
130 |
]}, fd) |
|
131 |
return Tenant(domain_url=name, |
|
132 |
schema_name=name.replace('-', '_').replace('.', '_')) |
|
133 |
return make_tenant('corbo.example.net') |
Formats disponibles : Unified diff
provisionning agent (#12910)