Beispiel #1
0
    def test_import_byname(self, import_item):
        from ringo.model.user import User
        from ringo.lib.imexport import JSONImporter
        from ringo.lib.sql import DBSession

        imported_items = JSONImporter(User).perform(json.dumps(import_item),
                                                    load_key="login")
        DBSession.flush()

        assert len(imported_items) == 1
        assert imported_items[0][1] == "CREATE"
        assert imported_items[0][0].login == import_item["login"]
Beispiel #2
0
    def test_import(self, import_item):
        from ringo.model.user import User
        from ringo.lib.imexport import JSONImporter
        from ringo.lib.sql import DBSession
        from ringo.model.base import BaseFactory

        imported_items = JSONImporter(User).perform(json.dumps(import_item))
        DBSession.flush()

        assert len(imported_items) == 1
        assert imported_items[0][1] == "CREATE"
        assert (imported_items[0][0] is BaseFactory(User).load(
            imported_items[0][0].id))
Beispiel #3
0
    def test_update_import_byid(self, import_item):
        from ringo.model.user import User
        from ringo.lib.imexport import JSONImporter
        from ringo.lib.sql import DBSession
        from ringo.model.base import BaseFactory

        imported_items = JSONImporter(User).perform(json.dumps(import_item),
                                                    load_key="id")
        DBSession.flush()

        assert len(imported_items) == 1
        assert imported_items[0][1] == "UPDATE"
        assert (BaseFactory(User).load(
            import_item["id"]).login == import_item["login"])
Beispiel #4
0
    def test_recursive_import_multiple(self, nested_import_items):
        from ringo.model.user import User, Usergroup, Role
        from ringo.lib.imexport import JSONImporter
        from ringo.lib.sql import DBSession

        group_count = DBSession.query(Usergroup).count()
        role_count = DBSession.query(Role).count()
        imported_items = JSONImporter(User).perform(
            json.dumps(nested_import_items))
        DBSession.flush()

        assert len(imported_items) == 2
        assert all(i[1] == "CREATE" for i in imported_items)
        # plus automatically created and one imported (not updated) groups:
        assert (DBSession.query(Usergroup).count() == group_count +
                len(nested_import_items) + 1)
        # plus imported (not updated) groups:
        assert (DBSession.query(Role).count() == role_count +
                len(nested_import_items[0]["roles"]))
Beispiel #5
0
    def test_recursive_import(self, nested_import_item):
        from ringo.model.user import User
        from ringo.lib.imexport import JSONImporter
        from ringo.lib.sql import DBSession

        imported_items = JSONImporter(User).perform(
            json.dumps(nested_import_item))
        DBSession.flush()

        assert len(imported_items) == 1
        assert imported_items[0][1] == "CREATE"
        assert (imported_items[0][0].usergroup.name ==
                nested_import_item["usergroup"]["name"])
        assert (imported_items[0][0].profile[0].first_name ==
                nested_import_item["profile"][0]["first_name"])
        assert (len(imported_items[0][0].roles) == len(
            nested_import_item["roles"]))
        assert (imported_items[0][0].roles[0].name ==
                nested_import_item["roles"][0]["name"])