Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ celerybeat-schedule
# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
Expand Down
10 changes: 10 additions & 0 deletions NextCloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def __init__(self, endpoint, user, password, js=False):
"Activity": Activity(requester),
"Notifications": Notifications(requester),
"UserLDAP": UserLDAP(requester),
"Capabilities": Capabilities(requester),
}
for name, location in PUBLIC_API_NAME_CLASS_MAP.items():
setattr(self, name, getattr(self.functionality[location], name))
Expand All @@ -112,6 +113,15 @@ def requester(self):
return self._requester


class Capabilities(WithRequester):
API_URL = "/ocs/v1.php/cloud/capabilities"

@nextcloud_method
def get_capabilities(self):
""" Obtain capabilities provided by the Nextcloud server and its apps """
return self.requester.get()


class GroupFolders(WithRequester):
API_URL = "/apps/groupfolders/folders"

Expand Down
4 changes: 3 additions & 1 deletion nextcloud/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM nextcloud:apache
ARG NEXTCLOUD_VERSION

FROM nextcloud:$NEXTCLOUD_VERSION-apache

RUN apt-get update && apt-get install wget && apt-get clean
RUN wget https://github.com/nextcloud/groupfolders/releases/download/v2.0.2/groupfolders-2.0.2.tar.gz -P /tmp \
Expand Down
11 changes: 11 additions & 0 deletions tests/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
POSTGRES_USER=postgres
POSTGRES_PASSWORD=secret
POSTGRES_DB=nextcloud
POSTGRES_HOST=db

NEXTCLOUD_VERSION=14
NEXTCLOUD_HOSTNAME=app
NEXTCLOUD_ADMIN_USER=admin
NEXTCLOUD_ADMIN_PASSWORD=admin

NEXTCLOUD_HOST=app
7 changes: 4 additions & 3 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

from NextCloud import NextCloud

NEXTCLOUD_URL = "http://{}:80".format(os.environ['NEXTCLOUD_HOST'])
NEXTCLOUD_USERNAME = os.environ.get('NEXTCLOUD_USERNAME')
NEXTCLOUD_PASSWORD = os.environ.get('NEXTCLOUD_PASSWORD')
NEXTCLOUD_VERSION = os.environ.get('NEXTCLOUD_VERSION')
NEXTCLOUD_URL = "http://{}:80".format(os.environ['NEXTCLOUD_HOSTNAME'])
NEXTCLOUD_USERNAME = os.environ.get('NEXTCLOUD_ADMIN_USER')
NEXTCLOUD_PASSWORD = os.environ.get('NEXTCLOUD_ADMIN_PASSWORD')


class BaseTestCase(TestCase):
Expand Down
39 changes: 10 additions & 29 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,31 @@
version: '3'

services:
db:
image: postgres:9.6-alpine
restart: always
networks:
- backend
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: secret

app:
build:
context: ../nextcloud
dockerfile: Dockerfile
restart: always
args:
NEXTCLOUD_VERSION: ${NEXTCLOUD_VERSION}
networks:
backend:
aliases:
- app
ports:
- 8080:80
environment:
POSTGRES_DB: 'nextcloud'
POSTGRES_USER: 'postgres'
POSTGRES_PASSWORD: 'secret'
POSTGRES_HOST: 'db'

NEXTCLOUD_TRUSTED_DOMAINS: "app"
NEXTCLOUD_ADMIN_USER: "admin"
NEXTCLOUD_ADMIN_PASSWORD: "admin"
depends_on:
- db
- SQLITE_DATABASE=nextcloud
- NEXTCLOUD_TRUSTED_DOMAINS=${NEXTCLOUD_HOSTNAME}
- NEXTCLOUD_ADMIN_USER
- NEXTCLOUD_ADMIN_PASSWORD

python-api:
build:
context: ../
dockerfile: Dockerfile
environment:
NEXTCLOUD_HOST: "app"
NEXTCLOUD_USERNAME: "admin"
NEXTCLOUD_PASSWORD: "admin"
- NEXTCLOUD_VERSION
- NEXTCLOUD_HOSTNAME
- NEXTCLOUD_ADMIN_USER
- NEXTCLOUD_ADMIN_PASSWORD
networks:
backend:
aliases:
- python-api
volumes:
- ../:/usr/src/app

Expand Down
9 changes: 9 additions & 0 deletions tests/test_capabilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .base import BaseTestCase, NEXTCLOUD_VERSION


class TestCapabilities(BaseTestCase):

def test_get_capabilities(self):
res = self.nxc.get_capabilities()
assert res['ocs']['meta']['statuscode'] == self.SUCCESS_CODE
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't test much, do you have any ideas how to change that? I understand that capabilities may vary on the test environment, but if we add e.g. env vars to it, we may squeeze something out of it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, one of the main nextcloud related params, which can be set in docker-compose and cannot be changed is nextcloud version, so added it to python-api service environment variable and specified it in nextcloud Dockerfile. Amended the change to check it in test

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, I propose one modification - don't check for the whole version, but go only for the major version (i.e. the X in v. X.Y.Z). Major versions don't change so often, they are part of the image name, and they test the capability query anyway. On recent-enough Docker setups, you can parametrize the FROM command using an argument that you can propagate to an environmental variable, so you don't have to repeat the literal nextcloud version on multiple places.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, moved nextcloud version to parameter and check only major version in test.

assert str(res['ocs']['data']['version']['major']) == NEXTCLOUD_VERSION
8 changes: 4 additions & 4 deletions tests/test_group_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_crud_group_folder(self):
# retrieve single folder
res = self.nxc.get_group_folder(group_folder_id)
assert res['ocs']['meta']['statuscode'] == self.SUCCESS_CODE
assert res['ocs']['data']['id'] == group_folder_id
assert str(res['ocs']['data']['id']) == str(group_folder_id)
assert res['ocs']['data']['mount_point'] == folder_mount_point

# rename group folder
Expand Down Expand Up @@ -67,7 +67,7 @@ def test_grant_revoke_access_to_group_folder(self):

# check that folder has this group
res = self.nxc.get_group_folder(group_folder_id)
assert res['ocs']['data']['groups'] == {group_id: Permission.ALL}
assert res['ocs']['data']['groups'] == {group_id: str(Permission.ALL.value)}

# revoke access
res = self.nxc.revoke_access_to_group_folder(group_folder_id, group_id)
Expand Down Expand Up @@ -97,7 +97,7 @@ def test_setting_folder_quotas(self):
assert res['ocs']['meta']['statuscode'] == self.SUCCESS_CODE and res['ocs']['data'] is True
# check if quota changed
res = self.nxc.get_group_folder(group_folder_id)
assert res['ocs']['data']['quota'] == QUOTA_ONE_GB
assert str(res['ocs']['data']['quota']) == str(QUOTA_ONE_GB)

# clear
self.clear(group_folder_ids=[group_folder_id])
Expand All @@ -124,7 +124,7 @@ def test_setting_folder_permissions(self):
assert res['ocs']['meta']['statuscode'] == self.SUCCESS_CODE and res['ocs']['data'] is True
# check if permissions changed
res = self.nxc.get_group_folder(group_folder_id)
assert res['ocs']['data']['groups'][group_id] == new_permission
assert str(res['ocs']['data']['groups'][group_id]) == str(new_permission)

# clear
self.clear(nxc=self.nxc, group_ids=[group_id], group_folder_ids=[group_folder_id])
Expand Down