def test_it(): from hidoi.testing import testConfigSlakky from hidoi.displayobject import DisplayObject from hidoi.tests.models import ( Item, Bag ) with testConfigSlakky() as config: # configuration phase config.add_display(Item) config.add_display(Bag) config.commit() # runtime phase request = config item0 = Item(name="portion", value="heal damage") bag0 = Bag(name="1stBag", items=[item0]) dbag = _callFUT(request, bag0) assert isinstance(dbag, DisplayObject) assert dbag.name.required is True for i in dbag.items.value: di = _callFUT(request, i) assert isinstance(di, DisplayObject) assert di.created_at.required is False # get from class (using this on create form) ditem = _callFUT(request, Item) assert isinstance(ditem, DisplayObject) assert print(ditem.name.value) is None
def test_prepare(): from hidoi.testing import testConfigSlakky import sqlalchemy.types as t with testConfigSlakky() as config: config.commit() result = _callFUT(config, t.DateTime) assert "widget" not in result assert result["format"] == "date-time" # added by default hook
def test_it(): from hidoi.testing import testConfigSlakky import sqlalchemy.types as t with testConfigSlakky() as config: config.include("hidoi.custom.html5") config.commit() result = _callFUT(config, t.DateTime) assert result["widget"] == "datetime" assert result["format"] == "date-time" # added by default hook
def test_it__swapping_normalize(): from hidoi.testing import testConfigSlakky from hidoi.schema import DefaultRegistry with testConfigSlakky() as config: # configuration phase config.add_schema_convertion("date-time", normalize=normalize_invalid_call, jsonify=None) config.commit() # runtime phase request = config result = _callFUT(request) assert result.normalize[("string", "date-time")] == normalize_invalid_call assert result.jsonify[("string", "date-time")] == DefaultRegistry.jsonify[("string", "date-time")]
def test_it_swapping_to_schema(): import sqlalchemy.types as t from hidoi.testing import testConfigSlakky from hidoi.schema import DefaultRegistry with testConfigSlakky() as config: # configuration phase config.add_sqla_column_convertion(t.Integer, to_schema="*secret*") config.commit() # runtime phase request = config result = _callFUT(request) assert result.column_to_schema[t.Integer] == "*secret*" assert result.restriction[t.DateTime] == DefaultRegistry.restriction[t.DateTime]
def test_it_swapping_to_schema(): import sqlalchemy.types as t from hidoi.testing import testConfigSlakky from hidoi.schema import DefaultRegistry with testConfigSlakky() as config: # configuration phase config.add_sqla_column_convertion(t.Integer, to_schema="*secret*") config.commit() # runtime phase request = config result = _callFUT(request) assert result.column_to_schema[t.Integer] == "*secret*" assert result.restriction[t.DateTime] == DefaultRegistry.restriction[ t.DateTime]
def test_it__call_with_another_name__missing(): from hidoi.testing import testConfigSlakky with testConfigSlakky() as config: # configuration phase config.add_validation(Data, increment_validation, name="create") config.commit() # runtime phase request = config wrapper = None data = Data(0) assert data.value == 0 result = _callFUT(request, data) result(wrapper, data) assert data.value == 0
def test_it_swapping_restriction(): import sqlalchemy.types as t from hidoi.testing import testConfigSlakky import pytest with testConfigSlakky() as config: # configuration phase config.add_sqla_column_convertion(t.DateTime, restriction=restriction_invalid_call) config.commit() # runtime phase request = config result = _callFUT(request) with pytest.raises(Exception): for fn in result.restriction[t.DateTime]: fn(None, None)
def test_it__swapping_jsonify(): from hidoi.testing import testConfigSlakky from hidoi.schema import DefaultRegistry with testConfigSlakky() as config: # configuration phase config.add_schema_convertion("date-time", jsonify=jsonify_invalid_call, normalize=None) config.commit() # runtime phase request = config result = _callFUT(request) assert result.jsonify[("string", "date-time")] == jsonify_invalid_call assert result.normalize[( "string", "date-time")] == DefaultRegistry.normalize[("string", "date-time")]
def test_schema_validation_invalid_type__error(): import pytest from hidoi.formwrapper import ValidationError from hidoi.testing import testConfigSlakky from . import models with testConfigSlakky() as config: config.set_default_model_module(models) config.add_display(models.Bag) config.commit() request = _makeRequest(config) target = _makeOne(request, models.Bag) data = {"name": "foo", "id": "foo"} with pytest.raises(ValidationError): target.validate(data)
def test_child__without_child__min_of_items_is_1__found(): from hidoi.testing import testConfigSlakky from hidoi.tests.models import ( Item, Bag ) with testConfigSlakky() as config: # configuration phase config.add_display(Item) config.add_display(Bag) config.commit() # runtime phase request = config item0 = Item(name="portion", value="heal damage") ditem = _callFUT(request, item0) dbag = ditem.child(ditem.bag, min_of_items=1) assert list(sorted(dbag._fieldnames)) == ['id', 'items', 'name']
def test_it(): from hidoi.testing import testConfigSlakky from hidoi.displayobject import DisplayObject from hidoi.tests.models import Item with testConfigSlakky() as config: # configuration phase config.scan("hidoi.tests.all_fields_are_optional") config.commit() # runtime phase request = config item0 = Item(name="portion", value="heal damage") ditem = _callFUT(request, item0) assert isinstance(ditem, DisplayObject) assert ditem.name.required is False assert ditem.value.required is False assert ditem.id.required is False
def test_child__without_child__min_of_items_is_0_None(): from hidoi.testing import testConfigSlakky from hidoi.tests.models import ( Item, Bag ) with testConfigSlakky() as config: # configuration phase config.add_display(Item) config.add_display(Bag) config.commit() # runtime phase request = config item0 = Item(name="portion", value="heal damage") ditem = _callFUT(request, item0) dbag = ditem.child(ditem.bag, min_of_items=0) assert dbag is None
def test_children__without_objects__min_of_items_is_1__found(): from hidoi.testing import testConfigSlakky from hidoi.tests.models import ( Item, Bag ) with testConfigSlakky() as config: # configuration phase config.add_display(Item) config.add_display(Bag) config.commit() # runtime phase request = config bag0 = Bag(name="1stBag", items=[]) dbag = _callFUT(request, bag0) items = dbag.children(dbag.items, min_of_items=1) assert len(items) == 1 assert list(sorted(items[0]._fieldnames)) == ['bag', 'created_at', 'id', 'name', 'value']
def test_children__without_objects__min_of_items_is_0__empty(): from hidoi.testing import testConfigSlakky from hidoi.tests.models import ( Item, Bag ) with testConfigSlakky() as config: # configuration phase config.add_display(Item) config.add_display(Bag) config.commit() # runtime phase request = config bag0 = Bag(name="1stBag", items=[]) dbag = _callFUT(request, bag0) items = dbag.children(dbag.items, min_of_items=0) assert len(items) == 0 assert items == []
def test_children__with_objects__normally_found(): from hidoi.testing import testConfigSlakky from hidoi.tests.models import ( Item, Bag ) with testConfigSlakky() as config: # configuration phase config.add_display(Item) config.add_display(Bag) config.commit() # runtime phase request = config item0 = Item(name="portion", value="heal damage") item1 = Item(name="magic portion", value="heal stress damage") bag0 = Bag(name="1stBag", items=[item0, item1]) dbag = _callFUT(request, bag0) items = dbag.children(dbag.items, min_of_items=1) assert len(items) == 2 assert list(sorted(items[0]._fieldnames)) == ['bag', 'created_at', 'id', 'name', 'value']
def test_it0(): from hidoi.testing import testConfigSlakky from hidoi.schema import DefaultRegistry with testConfigSlakky() as config: # configuration phase config.commit() # runtime phase request = config result = _callFUT(request) # value is eaual assert result.jsonify == DefaultRegistry.jsonify assert result.normalize == DefaultRegistry.normalize assert result.restriction == DefaultRegistry.restriction assert result.column_to_schema == DefaultRegistry.column_to_schema # but id is not same assert id(result.jsonify) != id(DefaultRegistry.jsonify) assert id(result.normalize) != id(DefaultRegistry.normalize) assert id(result.restriction) != id(DefaultRegistry.restriction) assert id(result.column_to_schema) != id(DefaultRegistry.column_to_schema)
def test_it0(): from hidoi.testing import testConfigSlakky from hidoi.schema import DefaultRegistry with testConfigSlakky() as config: # configuration phase config.commit() # runtime phase request = config result = _callFUT(request) # value is eaual assert result.jsonify == DefaultRegistry.jsonify assert result.normalize == DefaultRegistry.normalize assert result.restriction == DefaultRegistry.restriction assert result.column_to_schema == DefaultRegistry.column_to_schema # but id is not same assert id(result.jsonify) != id(DefaultRegistry.jsonify) assert id(result.normalize) != id(DefaultRegistry.normalize) assert id(result.restriction) != id(DefaultRegistry.restriction) assert id(result.column_to_schema) != id( DefaultRegistry.column_to_schema)