Skip to content

Commit

Permalink
global: clean test infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
utnapischtim authored and kpsherva committed Jun 8, 2022
1 parent a20cacf commit 5f46f45
Show file tree
Hide file tree
Showing 36 changed files with 99 additions and 27 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This file is part of Invenio.
# Copyright (C) 2016-2021 CERN.
# Copyright (C) 2022 Graz University of Technology.
#
# Invenio is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.
Expand Down Expand Up @@ -30,10 +31,10 @@ jobs:
matrix:
python-version: [3.7, 3.8, 3.9]
requirements-level: [pypi]
db-service: [postgresql12]
db-service: [postgresql13]
search-service: [elasticsearch7]
include:
- db-service: postgresql12
- db-service: postgresql13
DB_EXTRAS: "postgresql"
env:
DB: ${{ matrix.db-service }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Create featured communities table"""
"""Create featured communities table."""

import sqlalchemy as sa
from alembic import op
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Remove version table"""
"""Remove version table."""

import sqlalchemy as sa
import sqlalchemy_utils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Create member tables"""
"""Create member tables."""

import sqlalchemy as sa
from alembic import op
Expand Down
1 change: 1 addition & 0 deletions invenio_communities/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def demo():
@communities.command("rebuild-index")
@with_appcontext
def rebuild_index():
"""Rebuild index."""
click.secho("Reindexing communities...", fg="green")

communities_service = current_communities.service
Expand Down
2 changes: 1 addition & 1 deletion invenio_communities/communities/dumpers/featured.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# under the terms of the MIT License; see LICENSE file for more details.

"""Featured timestamp dumper.
Dumper used to dump/load the featured times of a record to/from an
ElasticSearch body.
"""
Expand All @@ -27,7 +28,6 @@ def __init__(self, key="featured"):

def dump(self, record, data):
"""Dump featured entries."""

now_ = datetime.utcnow()
future_entries = (
CommunityFeatured.query.filter(
Expand Down
2 changes: 2 additions & 0 deletions invenio_communities/communities/records/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Init."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2016-2021 CERN.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Init."""
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@


class PIDSlugFieldContext(SystemFieldContext):
"""PID Slug Field Context."""

def parse_pid(self, value):
"""Parse pid."""
if isinstance(value, UUID):
return value
try:
Expand Down
1 change: 1 addition & 0 deletions invenio_communities/communities/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def delete_logo(self):
@request_search_args
@response_handler(many=True)
def featured_communities_search(self):
"""Features communities search."""
hits = self.service.featured_search(
identity=g.identity,
params=resource_requestctx.args,
Expand Down
6 changes: 5 additions & 1 deletion invenio_communities/communities/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _not_blank(**kwargs):


def is_not_uuid(value):
"""Make sure value is not a UUID"""
"""Make sure value is not a UUID."""
try:
UUID(value)
raise ValidationError(
Expand All @@ -43,6 +43,7 @@ def is_not_uuid(value):


class CommunityAccessSchema(Schema):
"""Community Access Schema."""

visibility = fields.Str(
validate=validate.OneOf(
Expand Down Expand Up @@ -83,6 +84,7 @@ class VocabularySchema(Schema):
@pre_load
def clean(self, data, **kwargs):
"""Removes dump_only fields.
Why: We want to allow the output of a Schema dump, to be a valid input
to a Schema load without causing strange issues.
"""
Expand Down Expand Up @@ -137,5 +139,7 @@ def lowercase(self, in_data, **kwargs):


class CommunityFeaturedSchema(Schema):
"""Community Featured Schema."""

id = fields.Int(metadata={"read_only": True})
start_date = fields.DateTime(required=True)
6 changes: 5 additions & 1 deletion invenio_communities/communities/services/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Components."""

from flask_babelex import lazy_gettext as _
from invenio_access.permissions import system_identity, system_process
from invenio_db import db
Expand All @@ -24,6 +26,7 @@ class PIDComponent(ServiceComponent):
"""Service component for Community PIDs."""

def set_slug(self, record, slug):
"""Set slug."""
error = ValidationError(
_("A community with this identifier already exists."), field_name="slug"
)
Expand Down Expand Up @@ -107,6 +110,7 @@ class FeaturedCommunityComponent(ServiceComponent):
"""Service component for featured community integration."""

def featured_create(self, identity, data=None, record=None, **kwargs):
"""Featured create."""
if record.access.visibility != "public":
raise ValidationError(
_("The community is not public"), field_name="community_id"
Expand Down Expand Up @@ -183,7 +187,7 @@ def update(self, identity, data=None, record=None, **kwargs):
db.session.add(community_set)

def rename(self, identity, record=None, data=None, old_slug=None, **kwargs):
"""Delete old set and create new set on ID change"""
"""Delete old set and create new set on ID change."""
if record.access.visibility != "public":
return

Expand Down
4 changes: 2 additions & 2 deletions invenio_communities/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
# Invenio-Communities is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.

from flask_babelex import gettext as _

"""Community base error."""

from flask_babelex import gettext as _


class CommunityError(Exception):
"""Base exception for community errors."""
Expand Down
8 changes: 8 additions & 0 deletions invenio_communities/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def roles(self, **kwargs):
raise NotImplementedError

def communities(self, identity):
"""Communities."""
raise NotImplementedError

def needs(self, record=None, community_id=None, **kwargs):
Expand All @@ -175,30 +176,35 @@ class CommunityMembers(CommunityRoles):
"""Roles representing all members of a community."""

def roles(self, **kwargs):
"""Roles."""
return [r.name for r in current_roles]

def communities(self, identity):
"""Communities."""
return [n.value for n in identity.provides if n.method == "community"]


class CommunityCurators(CommunityRoles):
"""Roles representing all curators of a community."""

def roles(self, **kwargs):
"""Roles."""
return [r.name for r in current_roles.can("curate")]


class CommunityManagers(CommunityRoles):
"""Roles representing all managers of a community."""

def roles(self, **kwargs):
"""Roles."""
return [r.name for r in current_roles.can("manage")]


class CommunityManagersForRole(CommunityRoles):
"""Roles representing all managers of a community for a role update."""

def roles(self, role=None, member=None, **kwargs):
"""Roles."""
allowed_roles = []
if role is not None and member is not None:
# Update from an old role to a new role. The most restrictive set
Expand All @@ -223,9 +229,11 @@ class CommunityOwners(CommunityRoles):
"""Roles representing the owners of a community."""

def roles(self, **kwargs):
"""Roles."""
return [current_roles.owner_role.name]

def communities(self, identity):
"""Communities."""
return [
n.value
for n in identity.provides
Expand Down
2 changes: 1 addition & 1 deletion invenio_communities/members/records/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Invenio-Communities is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.

"Members data layer API."
"""Members data layer API."""

from invenio_accounts.models import Role
from invenio_db import db
Expand Down
4 changes: 4 additions & 0 deletions invenio_communities/members/services/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@


class PublicSearchOptions(SearchOptions):
"""Public Search Options."""

sort_default = "bestmatch"
sort_default_no_query = "name"
sort_options = {
Expand Down Expand Up @@ -62,6 +64,8 @@ class PublicSearchOptions(SearchOptions):


class InvitationsSearchOptions(SearchOptions):
"""Invitations Search Options."""

# TODO: should restrict fields that's being searched on.
# query_parser_cls = QueryParser
sort_default = "bestmatch"
Expand Down
1 change: 1 addition & 0 deletions invenio_communities/members/services/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@


def service():
"""Service."""
return current_communities.service.members


Expand Down
17 changes: 11 additions & 6 deletions invenio_communities/members/services/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class MemberEntitySchema(Schema):


class MembersSchema(Schema):
"""Members Schema."""

members = fields.List(
fields.Nested(MemberEntitySchema),
# max is on purpose to limit the max number of additions/changes/
Expand All @@ -46,6 +48,8 @@ class MembersSchema(Schema):


class RequestSchema(Schema):
"""Request Schema."""

id = fields.String()
status = fields.String()
is_open = fields.Boolean()
Expand Down Expand Up @@ -94,19 +98,20 @@ class DeleteBulkSchema(MembersSchema):


class PublicDumpSchema(Schema):
"""Public Dump Schema."""

id = fields.String(required=True)
member = fields.Method("get_member")

def get_member(self, obj):
"""Get a member"""
"""Get a member."""
if obj.user_id:
return self.get_user_member(obj["user"])
elif obj.group_id:
return self.get_group_member(obj["group"])

def get_user_member(self, user):
"""Get a user member."""

profile = user.get("profile", {})
name = profile.get("full_name") or user.get("username") or _("Untitled")
description = profile.get("affiliations") or ""
Expand Down Expand Up @@ -147,7 +152,7 @@ class MemberDumpSchema(PublicDumpSchema):
revision_id = fields.Integer()

def is_self(self, obj):
"""Get permission"""
"""Get permission."""
if "is_self" not in self.context:
current_identity = self.context["identity"]
self.context["is_self"] = (
Expand All @@ -158,11 +163,11 @@ def is_self(self, obj):
return self.context["is_self"]

def get_current_user(self, obj):
"""Get permission"""
"""Get permission."""
return self.is_self(obj)

def get_permissions(self, obj):
"""Get permission"""
"""Get permission."""
permission_check = self.context["field_permission_check"]

# Does not take CommunitySelfMember into account because no "member" is
Expand Down Expand Up @@ -191,7 +196,7 @@ class InvitationDumpSchema(MemberDumpSchema):
permissions = fields.Method("get_permissions")

def get_permissions(self, obj):
"""Get permission"""
"""Get permission."""
# Only owners and managers can list invitations, and thus only the
# request status is necessary to determine if the identity can cancel.
is_open = obj["request"]["status"] == "submitted"
Expand Down
1 change: 1 addition & 0 deletions invenio_communities/members/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def _invite_factory(self, identity, community, role, visible, member, message, u
)

def search(self, identity, community_id, params=None, es_preference=None, **kwargs):
"""Search."""
return self._members_search(
identity,
community_id,
Expand Down
2 changes: 2 additions & 0 deletions invenio_communities/records/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
# Invenio-Communities is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""Init."""
2 changes: 2 additions & 0 deletions invenio_communities/records/records/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
# Invenio-Communities is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""Init."""
2 changes: 2 additions & 0 deletions invenio_communities/records/records/systemfields/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""Init."""

from .communities.field import CommunitiesField

__all__ = ("CommunitiesField",)
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
# Invenio-Communities is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""Init."""
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class CommunitiesField(SystemField):
def __init__(
self, m2m_model_cls, key="communities", context_cls=None, manager_cls=None
):
"""Constructor."""
self._m2m_model_cls = m2m_model_cls
self._context_cls = context_cls or CommunitiesFieldContext
self._manager_cls = manager_cls or CommunitiesRelationManager
Expand Down
Loading

0 comments on commit 5f46f45

Please sign in to comment.