1 |
1 |
# -*- coding: utf-8 -*-
|
2 |
2 |
import pytest
|
3 |
3 |
|
4 |
|
from django.contrib.auth.models import User
|
5 |
4 |
from django.core.exceptions import ValidationError
|
6 |
5 |
from django.utils import timezone
|
7 |
6 |
|
... | ... | |
47 |
46 |
assert e.value.messages[0] == u'This slug is already used. It must be unique.'
|
48 |
47 |
|
49 |
48 |
|
|
49 |
def test_unique_title():
|
|
50 |
Combo.objects.create(
|
|
51 |
title='Combo test',
|
|
52 |
slug='bar',
|
|
53 |
last_operational_success_timestamp=timezone.now(),
|
|
54 |
last_operational_check_timestamp=timezone.now(),
|
|
55 |
secret_key='1nesüper5Cr!eteKAaY~',
|
|
56 |
base_url='http://example.com'
|
|
57 |
)
|
|
58 |
|
|
59 |
combo = Combo(
|
|
60 |
title='Combo test',
|
|
61 |
slug='foo',
|
|
62 |
last_operational_success_timestamp=timezone.now(),
|
|
63 |
last_operational_check_timestamp=timezone.now(),
|
|
64 |
secret_key='1nesüper5Cr!eteKAaY~',
|
|
65 |
base_url='http://example.com'
|
|
66 |
)
|
|
67 |
|
|
68 |
with pytest.raises(ValidationError) as e:
|
|
69 |
combo.clean()
|
|
70 |
|
|
71 |
assert e.value.messages[0] == u'This title is already used. It must be unique.'
|
|
72 |
|
|
73 |
|
50 |
74 |
def test_base_url_field_validator():
|
51 |
|
kwargs = {'title': 'Combo test',
|
52 |
|
'last_operational_success_timestamp': timezone.now(),
|
|
75 |
kwargs = {'last_operational_success_timestamp': timezone.now(),
|
53 |
76 |
'last_operational_check_timestamp': timezone.now(),
|
54 |
77 |
'secret_key': '1nesüper5Cr!eteKAaY~'}
|
55 |
78 |
cpt = 0 # slugs must be unique
|
... | ... | |
58 |
81 |
for url in ('https://example.com', 'http://example.com'):
|
59 |
82 |
cpt += 1
|
60 |
83 |
slug = 'wesh' + str(cpt)
|
61 |
|
combo = Combo(base_url=url, slug=slug ,**kwargs)
|
|
84 |
title = 'Combo test ' + str(cpt)
|
|
85 |
combo = Combo(base_url=url, slug=slug, title=title, **kwargs)
|
62 |
86 |
combo.full_clean()
|
63 |
87 |
combo.save()
|
64 |
88 |
assert True # no exception raised
|
... | ... | |
67 |
91 |
for url in ('example.com', 'http:/example.com', 'file:///home/me'):
|
68 |
92 |
cpt += 1
|
69 |
93 |
slug = 'wesh' + str(cpt)
|
|
94 |
title = 'Combo test ' + str(cpt)
|
70 |
95 |
with pytest.raises(ValidationError):
|
71 |
|
combo = Combo(base_url=url, slug='wesh_'+str(cpt), **kwargs)
|
|
96 |
combo = Combo(base_url=url, slug=slug, title=title, **kwargs)
|
72 |
97 |
combo.full_clean()
|
73 |
98 |
combo.save()
|
74 |
99 |
|
75 |
|
-
|