61 lines
2.1 KiB
Python
61 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
import pytest
|
|
|
|
from django.core.exceptions import ValidationError
|
|
from django.utils import timezone
|
|
from hobo.environment.models import AVAILABLE_SERVICES, Combo, Passerelle
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
def test_service_id():
|
|
for service in AVAILABLE_SERVICES:
|
|
assert service.Extra.service_id
|
|
|
|
|
|
def test_unique_slug():
|
|
combo = Combo(title='Combo test',
|
|
slug='wesh',
|
|
last_operational_success_timestamp=timezone.now(),
|
|
last_operational_check_timestamp=timezone.now(),
|
|
secret_key='1nesüper5Cr!eteKAaY~',
|
|
base_url='http://example.com')
|
|
combo.save()
|
|
|
|
passerelle = Passerelle(title='Passerelle test',
|
|
slug='wesh',
|
|
last_operational_success_timestamp=timezone.now(),
|
|
last_operational_check_timestamp=timezone.now(),
|
|
secret_key='1nesüper5Cr!eteKAaY~',
|
|
base_url='http://example.com')
|
|
|
|
with pytest.raises(ValidationError) as e:
|
|
passerelle.clean()
|
|
|
|
assert e.value.messages[0] == u'This slug is already used. It must be unique.'
|
|
|
|
|
|
def test_base_url_field_validator():
|
|
kwargs = {'title': 'Combo test',
|
|
'last_operational_success_timestamp': timezone.now(),
|
|
'last_operational_check_timestamp': timezone.now(),
|
|
'secret_key': '1nesüper5Cr!eteKAaY~'}
|
|
cpt = 0 # slugs must be unique
|
|
|
|
# accept well formated url
|
|
for url in ('https://example.com', 'http://example.com'):
|
|
cpt += 1
|
|
slug = 'wesh' + str(cpt)
|
|
combo = Combo(base_url=url, slug=slug ,**kwargs)
|
|
combo.full_clean()
|
|
combo.save()
|
|
assert True # no exception raised
|
|
|
|
# reject baddly formated url
|
|
for url in ('example.com', 'http:/example.com', 'file:///home/me'):
|
|
cpt += 1
|
|
slug = 'wesh' + str(cpt)
|
|
with pytest.raises(ValidationError):
|
|
combo = Combo(base_url=url, slug='wesh_'+str(cpt), **kwargs)
|
|
combo.full_clean()
|
|
combo.save()
|