Ejemplo n.º 1
0
 def test_equal(self):
     foo0 = FooEntity(id=0)
     mb0 = FooMember.create_from_entity(foo0)
     foo1 = FooEntity(id=1)
     mb1 = FooMember.create_from_entity(foo1)
     self.assert_true(mb0 == mb0)
     self.assert_true(mb0 != mb1)
Ejemplo n.º 2
0
 def test_member_delete(self):
     coll = get_root_collection(IFoo)
     foo = FooEntity(id=0)
     mb = coll.create_member(foo)
     self.assert_true(mb in coll)
     coll.remove(mb)
     self.assert_false(mb in coll)
Ejemplo n.º 3
0
    def test_custom_repository(self, simple_config):
        class MyMemoryAggregate(Aggregate):
            pass

        reg = simple_config.registry
        config = Configurator(registry=reg)
        config.add_memory_repository('test', aggregate_class=MyMemoryAggregate)
        repo_mgr = config.get_registered_utility(IRepositoryManager)
        repo = repo_mgr.get('test')
        config.add_resource(IFoo,
                            FooMember,
                            FooEntity,
                            collection_root_name="foos",
                            repository='test')
        with pytest.raises(RuntimeError):
            repo.get_collection(IFoo)
        with pytest.raises(RuntimeError):
            repo.get_aggregate(IFoo)
        repo.initialize()
        coll = repo.get_collection(IFoo)
        agg = coll.get_aggregate()
        assert isinstance(agg, MyMemoryAggregate)
        entity = FooEntity(id=1)
        agg.add(entity)
        assert agg.count() == 1
        assert list(agg.iterator())[0].id == entity.id
        assert agg.get_by_id(1).id == entity.id
        assert agg.get_by_slug('1').slug == entity.slug
        agg.remove(entity)
        assert agg.count() == 0
Ejemplo n.º 4
0
 def test_member_name(self):
     coll = get_root_collection(IFoo)
     foo = FooEntity(id=0)
     mb = coll.create_member(foo)
     self.assert_equal(mb.__name__, '0')
     mb.__name__ = 'foo'
     self.assert_equal(mb.__name__, 'foo')
Ejemplo n.º 5
0
 def test_configure_with_full_zcml(self):
     reg = self._registry
     # Check adapters.
     ent = FooEntity()
     member = object.__new__(FooMember)
     coll = object.__new__(FooCollection)
     # Make sure no adapters are in the registry.
     self.assert_is_none(
         reg.queryAdapter(coll, IMemberResource, name='member-class'))
     self.assert_is_none(
         reg.queryAdapter(member,
                          ICollectionResource,
                          name='collection-class'))
     self.assert_is_none(
         reg.queryAdapter(member, IEntity, name='entity-class'))
     self.assert_is_none(reg.queryAdapter(ent, IMemberResource))
     self.assert_is_none(
         reg.queryAdapter(coll, IRepresenter,
                          name=CsvMime.mime_type_string))
     # Load the configuration.
     config = Configurator(registry=reg, package=package)
     config.load_zcml('everest.tests.simple_app:configure.zcml')
     self.__check(reg, member, ent, coll)
     rpr = as_representer(coll, CsvMime)
     self.assert_true(isinstance(rpr, Representer))
Ejemplo n.º 6
0
    def test_custom_repository(self):
        class MyMemoryAggregate(Aggregate):
            pass

        reg = self._registry
        config = Configurator(registry=reg)
        config.add_memory_repository('test', aggregate_class=MyMemoryAggregate)
        repo_mgr = config.get_registered_utility(IRepositoryManager)
        repo = repo_mgr.get('test')
        config.add_resource(IFoo,
                            FooMember,
                            FooEntity,
                            collection_root_name="foos",
                            repository='test')
        self.assert_raises(RuntimeError, repo.get_collection, IFoo)
        self.assert_raises(RuntimeError, repo.get_aggregate, IFoo)
        repo.initialize()
        coll = repo.get_collection(IFoo)
        agg = coll.get_aggregate()
        self.assert_true(isinstance(agg, MyMemoryAggregate))
        entity = FooEntity(id=1)
        agg.add(entity)
        self.assert_true(agg.count() == 1)
        self.assert_equal(list(agg.iterator())[0].id, entity.id)
        self.assert_equal(agg.get_by_id(1).id, entity.id)
        self.assert_equal(agg.get_by_slug('1').slug, entity.slug)
        agg.remove(entity)
        self.assert_true(agg.count() == 0)
Ejemplo n.º 7
0
 def test_put_member_warning_exception(self, wrn_vw_app_creator):
     root = get_service()
     # Need to start the service manually - no request root has been set
     # yet.
     root.start()
     coll = root['foos']
     mb = FooMember(FooEntity(id=0))
     coll.add(mb)
     transaction.commit()
     path = '/'.join((self.path, '0'))
     # First PUT - get back a 307.
     res1 = wrn_vw_app_creator.put(path, params='foo name', status=307)
     assert res1.body.startswith(b'307 Temporary Redirect')
     # Second PUT to redirection location - get back a 200.
     resubmit_location1 = res1.headers['Location']
     res2 = wrn_vw_app_creator.put(resubmit_location1,
                                   params='foo name',
                                   status=200)
     assert not res2 is None
Ejemplo n.º 8
0
 def test_configure_with_simple_zcml(self):
     # Load the configuration.
     self._config.load_zcml(
         'everest.tests.simple_app:configure_simple.zcml')
     reg = self._registry
     # Check adapters.
     ent = FooEntity()
     member = object.__new__(FooMember)
     coll_cls = reg.queryUtility(IFoo, name='collection-class')
     self.assert_is_not_none(coll_cls)
     self.assert_is_not_none(coll_cls.root_name)
     self.assert_is_not_none(coll_cls.title)
     coll = object.__new__(coll_cls)
     self.__check(reg, member, ent, coll)
     # Check service.
     srvc = reg.queryUtility(IService)
     self.assert_is_not_none(srvc)
     srvc.start()
     self.assert_true(isinstance(srvc.get('foos'), Collection))
     self.assert_is_none(srvc.get(coll_cls))
     self.assert_is_none(srvc.get(IBar))
Ejemplo n.º 9
0
 def test__getitem__with_invalid_key_raises_error(self):
     foo = FooEntity(id=0)
     mb = FooMember.create_from_entity(foo)
     self.assert_raises(KeyError, mb.__getitem__, 'x')
Ejemplo n.º 10
0
 def test_no_relation_raises_error(self):
     foo = FooEntity()
     self.assert_raises(ValueError, MemberWithoutRelation, foo)
Ejemplo n.º 11
0
 def _extract_request_data(self):
     foo = FooEntity(name=self.request.body)
     return FooMember(foo)
Ejemplo n.º 12
0
def trv_view_member(app_creator):  #pylint:disable=W0613
    foo_ent = FooEntity(id=0)
    coll = get_root_collection(IFoo)
    mb = coll.create_member(foo_ent)
    transaction.commit()
    return mb
Ejemplo n.º 13
0
 def set_up(self):
     FunctionalTestCase.set_up(self)
     self.config.load_zcml(self.views_config_file_name)
     coll = get_root_collection(IFoo)
     coll.create_member(FooEntity(id=0))
     transaction.commit()
Ejemplo n.º 14
0
 def test_basics(self):
     foo = FooEntity()
     foo_mb = FooMember.create_from_entity(foo)
     self.coll.add(foo_mb)
     self.assert_true(self.session.iterator(FooEntity).next() is foo)
     self.assert_equal(len(list(self.session.iterator(FooEntity))), 1)