Browse Source

added first tests

master
Holger Frey 7 years ago
parent
commit
4b41dad890
  1. 4
      tests/__init__.py
  2. 45
      tests/resources/__init__.py
  3. 3
      tests/test_ordr2.py
  4. 1
      tests/views/__init__.py
  5. 14
      tests/views/errors.py
  6. 10
      tests/views/public.py

4
tests/__init__.py

@ -1,3 +1 @@
# -*- coding: utf-8 -*- ''' Test package for ordr2. '''
''' Unit test package for ordr2. '''

45
tests/resources/__init__.py

@ -0,0 +1,45 @@
''' Test package for ordr2.resources '''
import pytest
def test_base_resource_init():
''' test __init__ function of base resource '''
from ordr2.resources import BaseResource, RootResource
root = RootResource('request object')
resource = BaseResource('resource name', root)
assert resource.__name__ == 'resource name'
assert resource.__parent__ == root
assert resource.request == 'request object'
@pytest.mark.parametrize(
'segment', [
'known',
pytest.mark.xfail('unknown', raises=KeyError)
]
)
def test_base_resource_getitem(segment):
''' test the __getitem__ function of base resource '''
from ordr2.resources import BaseResource, RootResource
root = RootResource('request object')
root.nodes = {'known': BaseResource}
resource = root[segment]
assert resource.__name__ == segment
assert resource.__parent__ == root
assert resource.request == 'request object'
def test_root_resource_init():
''' test __init__ function of root resource '''
from ordr2.resources import RootResource
resource = RootResource('request object')
assert resource.__name__ == None
assert resource.__parent__ == None
assert resource.request == 'request object'

3
tests/test_ordr2.py

@ -1,6 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
''' Tests for `ordr2` package. ''' ''' Tests for `ordr2` package. '''
import pytest import pytest

1
tests/views/__init__.py

@ -0,0 +1 @@
''' Test package for ordr2.views '''

14
tests/views/errors.py

@ -0,0 +1,14 @@
''' Tests for ordr2.views.error '''
def test_index_view():
''' test the not found view '''
from pyramid.testing import DummyRequest
from ordr2.views.errors import notfound_view
request = DummyRequest()
result = notfound_view(None, request)
assert result == {}
assert request.response.status == '404 Not Found'

10
tests/views/public.py

@ -0,0 +1,10 @@
''' Tests for ordr2.views.public '''
def test_index_view():
''' test the default view for a root resource '''
from ordr2.views.public import index
result = index(None, None)
assert result == {}