2016-07-18 18:28:12 +03:00
|
|
|
from py.test import raises
|
|
|
|
|
2016-07-23 06:18:23 +03:00
|
|
|
from ..types import SQLAlchemyObjectType
|
2016-07-18 18:28:12 +03:00
|
|
|
|
|
|
|
from .models import Reporter
|
2016-07-23 06:18:23 +03:00
|
|
|
from ..registry import Registry
|
2016-07-18 18:28:12 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_should_raise_if_no_model():
|
|
|
|
with raises(Exception) as excinfo:
|
|
|
|
class Character1(SQLAlchemyObjectType):
|
|
|
|
pass
|
2016-07-23 06:18:23 +03:00
|
|
|
assert 'valid SQLAlchemy Model' in str(excinfo.value)
|
2016-07-18 18:28:12 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_should_raise_if_model_is_invalid():
|
|
|
|
with raises(Exception) as excinfo:
|
|
|
|
class Character2(SQLAlchemyObjectType):
|
|
|
|
class Meta:
|
|
|
|
model = 1
|
2016-07-23 06:18:23 +03:00
|
|
|
assert 'valid SQLAlchemy Model' in str(excinfo.value)
|
2016-07-18 18:28:12 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_should_map_fields_correctly():
|
|
|
|
class ReporterType2(SQLAlchemyObjectType):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Reporter
|
2016-07-23 06:18:23 +03:00
|
|
|
registry = Registry()
|
|
|
|
|
|
|
|
assert ReporterType2._meta.get_fields().keys() == ['id', 'firstName', 'lastName', 'email']
|
2016-07-18 18:28:12 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_should_map_only_few_fields():
|
|
|
|
class Reporter2(SQLAlchemyObjectType):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Reporter
|
2016-07-23 06:18:23 +03:00
|
|
|
only = ('id', 'email')
|
|
|
|
assert Reporter2._meta.get_fields().keys() == ['id', 'email']
|