Example #1
0
    def test_raise_when_resolving_non_existing_user(self, registry):
        from adhocracy_core.scripts import import_resources

        (self._tempfd, filename) = mkstemp()
        with open(filename, 'w') as f:
            f.write(json.dumps([
                {"path": "/principals/users/badge_assignments",
                 "content_type": "adhocracy_core.resources.badge.IBadgeAssignment",
                 "data": {"adhocracy_core.sheets.badge.IBadgeAssignment":
                          {"subject": "user_by_login:Malkovitch",
                           "badge": "/orga/badges/badge0",
                           "object": "/principals/users/0000000"
                          },
                          "adhocracy_core.sheets.name.IName": {"name": "assign0"}}
                }]))

        root = registry.content.create(IRootPool.__identifier__)
        appstructs = {'adhocracy_core.sheets.name.IName': {'name': 'orga'}}
        orga = registry.content.create(IOrganisation.__identifier__, root,
                                appstructs=appstructs, registry=registry)
        add_badges_service(orga, registry, {})
        badge_appstructs = {'adhocracy_core.sheets.name.IName': {'name': 'badge0'}}
        registry.content.create(IBadge.__identifier__,
                                orga['badges'],
                                appstructs=badge_appstructs,
                                registry=registry)
        with raises(ValueError):
            import_resources(root, registry, filename)
Example #2
0
    def test_raise_when_resolving_non_existing_user(self, registry):
        from adhocracy_core.scripts import import_resources
        from .import_users import _get_user_locator

        (self._tempfd, filename) = mkstemp()
        with open(filename, 'w') as f:
            f.write(json.dumps([
                {"path": "/principals/users/badge_assignments",
                 "content_type": "adhocracy_core.resources.badge.IBadgeAssignment",
                 "data": {"adhocracy_core.sheets.badge.IBadgeAssignment":
                          {"subject": "user_by_login:Malkovitch",
                           "badge": "/orga/badges/badge0",
                           "object": "/principals/users/0000000"
                          },
                          "adhocracy_core.sheets.name.IName": {"name": "assign0"}}
                }]))

        root = registry.content.create(IRootPool.__identifier__)
        appstructs = {'adhocracy_core.sheets.name.IName': {'name': 'orga'}}
        orga = registry.content.create(IOrganisation.__identifier__, root,
                                appstructs=appstructs, registry=registry)
        add_badges_service(orga, registry, {})
        badge_appstructs = {'adhocracy_core.sheets.name.IName': {'name': 'badge0'}}
        registry.content.create(IBadge.__identifier__,
                                orga['badges'],
                                appstructs=badge_appstructs,
                                registry=registry)
        with pytest.raises(ValueError):
            import_resources(root, registry, filename)
Example #3
0
    def test_username_is_resolved_to_his_path(self, registry):
        from adhocracy_core.scripts import import_resources
        from .import_users import _get_user_locator

        (self._tempfd, filename) = mkstemp()
        with open(filename, 'w') as f:
            f.write(json.dumps([
                {"path": "/principals/users/badge_assignments",
                 "content_type": "adhocracy_core.resources.badge.IBadgeAssignment",
                 "data": {"adhocracy_core.sheets.badge.IBadgeAssignment":
                          {"subject": "user_by_login:god",
                           "badge": "/orga/badges/badge0",
                           "object": "/principals/users/0000000"
                          },
                          "adhocracy_core.sheets.name.IName": {"name": "assign0"}}
                }]))

        root = registry.content.create(IRootPool.__identifier__)
        appstructs = {'adhocracy_core.sheets.name.IName': {'name': 'orga'}}
        orga = registry.content.create(IOrganisation.__identifier__, root,
                                appstructs=appstructs, registry=registry)
        add_badges_service(orga, registry, {})
        badge_appstructs = {'adhocracy_core.sheets.name.IName': {'name': 'badge0'}}
        registry.content.create(IBadge.__identifier__,
                                orga['badges'],
                                appstructs=badge_appstructs,
                                registry=registry)

        import_resources(root, registry, filename)
        assignments = find_resource(root, '/principals/users/badge_assignments/')
        assignment = list(assignments.values())[0]
        subject = get_sheet_field(assignment, IBadgeAssignment, 'subject')
        user_locator = _get_user_locator(root, registry)
        god = user_locator.get_user_by_login('god')
        assert subject == god
Example #4
0
def change_mercator_type_to_iprocess(root, registry):
    """Change mercator type from IBasicPoolWithAssets to IProcess."""
    from adhocracy_mercator.resources.mercator import IProcess
    from adhocracy_core.resources.asset import IPoolWithAssets
    from adhocracy_core.resources.badge import add_badges_service
    migrate_new_iresource(root, IPoolWithAssets, IProcess)
    mercator = root['mercator']
    if find_service(mercator, 'badges') is None:
        add_badges_service(mercator, registry, {})
Example #5
0
def change_mercator_type_to_iprocess(root, registry):
    """Change mercator type from IBasicPoolWithAssets to IProcess."""
    from adhocracy_mercator.resources.mercator import IProcess
    from adhocracy_core.resources.asset import IPoolWithAssets
    from adhocracy_core.resources.badge import add_badges_service
    migrate_new_iresource(root, IPoolWithAssets, IProcess)
    mercator = root['mercator']
    if find_service(mercator, 'badges') is None:
        add_badges_service(mercator, registry, {})
Example #6
0
def make_users_badgeable(root, registry):  # pragma: no cover
    """Add badge services and make user badgeable."""
    principals = find_service(root, 'principals')
    if not IHasBadgesPool.providedBy(principals):
        logger.info('Add badges service to {0}'.format(principals))
        add_badges_service(principals, registry, {})
        alsoProvides(principals, IHasBadgesPool)
    users = find_service(root, 'principals', 'users')
    assignments = find_service(users, 'badge_assignments')
    if assignments is None:
        logger.info('Add badge assignments service to {0}'.format(users))
        add_badge_assignments_service(users, registry, {})
    migrate_new_sheet(root, IUser, IBadgeable)
Example #7
0
def make_users_badgeable(root, registry):  # pragma: no cover
    """Add badge services and make user badgeable."""
    principals = find_service(root, 'principals')
    if not IHasBadgesPool.providedBy(principals):
        logger.info('Add badges service to {0}'.format(principals))
        add_badges_service(principals, registry, {})
        alsoProvides(principals, IHasBadgesPool)
    users = find_service(root, 'principals', 'users')
    assignments = find_service(users, 'badge_assignments')
    if assignments is None:
        logger.info('Add badge assignments service to {0}'.format(users))
        add_badge_assignments_service(users, registry, {})
    migrate_new_sheet(root, IUser, IBadgeable)
Example #8
0
def make_users_badgeable(root):  # pragma: no cover
    """Add badge services and make user badgeable."""
    registry = get_current_registry(root)
    principals = find_service(root, "principals")
    if not IHasBadgesPool.providedBy(principals):
        logger.info("Add badges service to {0}".format(principals))
        add_badges_service(principals, registry, {})
        alsoProvides(principals, IHasBadgesPool)
    users = find_service(root, "principals", "users")
    assignments = find_service(users, "badge_assignments")
    if assignments is None:
        logger.info("Add badge assignments service to {0}".format(users))
        add_badge_assignments_service(users, registry, {})
    migrate_new_sheet(root, IUser, IBadgeable)
Example #9
0
def make_proposals_badgeable(root, registry):  # pragma: no cover
    """Add badge services processes and make proposals badgeable."""
    catalogs = find_service(root, 'catalogs')
    proposals = _search_for_interfaces(catalogs, IProposal)
    for proposal in proposals:
        if not IBadgeable.providedBy(proposal):
            logger.info('add badgeable interface to {0}'.format(proposal))
            alsoProvides(proposal, IBadgeable)
        if 'badge_assignments' not in proposal:
            logger.info('add badge assignments to {0}'.format(proposal))
            add_badge_assignments_service(proposal, registry, {})
    processes = _search_for_interfaces(catalogs, IProcess)
    for process in processes:
        if not IHasBadgesPool.providedBy(process):
            logger.info('Add badges service to {0}'.format(process))
            add_badges_service(process, registry, {})
            alsoProvides(process, IHasBadgesPool)
Example #10
0
def make_proposals_badgeable(root, registry):  # pragma: no cover
    """Add badge services processes and make proposals badgeable."""
    catalogs = find_service(root, 'catalogs')
    proposals = _search_for_interfaces(catalogs, IProposal)
    for proposal in proposals:
        if not IBadgeable.providedBy(proposal):
            logger.info('add badgeable interface to {0}'.format(proposal))
            alsoProvides(proposal, IBadgeable)
        if 'badge_assignments' not in proposal:
            logger.info('add badge assignments to {0}'.format(proposal))
            add_badge_assignments_service(proposal, registry, {})
    processes = _search_for_interfaces(catalogs, IProcess)
    for process in processes:
        if not IHasBadgesPool.providedBy(process):
            logger.info('Add badges service to {0}'.format(process))
            add_badges_service(process, registry, {})
            alsoProvides(process, IHasBadgesPool)
Example #11
0
def make_mercator_proposals_badgeable(root, registry):
    """Add badge services processes and make mercator proposals badgeable."""
    from adhocracy_core.evolution import _search_for_interfaces
    from adhocracy_mercator.resources.mercator import IProcess
    catalogs = find_service(root, 'catalogs')
    proposals = _search_for_interfaces(catalogs, IMercatorProposal)
    for proposal in proposals:
        if not IBadgeable.providedBy(proposal):
            logger.info('add badgeable interface to {0}'.format(proposal))
            alsoProvides(proposal, IBadgeable)
        if 'badge_assignments' not in proposal:
            logger.info('add badge assignments to {0}'.format(proposal))
            add_badge_assignments_service(proposal, registry, {})
    processes = _search_for_interfaces(catalogs, IProcess)
    for process in processes:
        if not IHasBadgesPool.providedBy(process):
            logger.info('Add badges service to {0}'.format(process))
            add_badges_service(process, registry, {})
            alsoProvides(process, IHasBadgesPool)
Example #12
0
def make_mercator_proposals_badgeable(root, registry):
    """Add badge services processes and make mercator proposals badgeable."""
    from adhocracy_core.evolution import _search_for_interfaces
    from adhocracy_mercator.resources.mercator import IProcess
    catalogs = find_service(root, 'catalogs')
    proposals = _search_for_interfaces(catalogs, IMercatorProposal)
    for proposal in proposals:
        if not IBadgeable.providedBy(proposal):
            logger.info('add badgeable interface to {0}'.format(proposal))
            alsoProvides(proposal, IBadgeable)
        if 'badge_assignments' not in proposal:
            logger.info('add badge assignments to {0}'.format(proposal))
            add_badge_assignments_service(proposal, registry, {})
    processes = _search_for_interfaces(catalogs, IProcess)
    for process in processes:
        if not IHasBadgesPool.providedBy(process):
            logger.info('Add badges service to {0}'.format(process))
            add_badges_service(process, registry, {})
            alsoProvides(process, IHasBadgesPool)