Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/GitHub actions #2

Merged
merged 7 commits into from
Jan 4, 2021
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
10 changes: 7 additions & 3 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.5, 3.6, 3.7, 3.8, 3.9]
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- name: Checkout
Expand All @@ -18,11 +18,16 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: create environment
run: |
python -m venv venv
. venv/bin/activate

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements_test.txt ]; then pip install -r requirements_test.txt; fi

- name: Lint with flake8
run: |
Expand All @@ -33,7 +38,6 @@ jobs:

- name: Test with pytest
run: |
. venv/bin/activate
pytest \
--quiet \
--timeout=9 \
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Photos.network

[![License](https://img.shields.io/github/license/photos-network/core)](./LICENSE.md)
[![GitHub contributors](https://img.shields.io/github/contributors/photos-network/core)](https://github.com/photos.network/core/graphs/contributors)
[![GitHub contributors](https://img.shields.io/github/contributors/photos-network/core?color=success)](https://github.com/photos.network/core/graphs/contributors)
[![Discord](https://img.shields.io/discord/793235453871390720)](https://discord.gg/dGFDpmWp46)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/photos-network/core/check%20code%20quality)


[Photos.network](https://photos.network) is an open source project for self hosted photo management.
Its core features are:
Expand Down
5 changes: 3 additions & 2 deletions core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,14 @@ def async_enable_logging(self, verbose: bool = False) -> None:
logger.addHandler(err_handler)
logger.setLevel(logging.DEBUG if verbose else logging.WARNING)

def start(self) -> int:
async def start(self) -> int:
"""Start Photos Core.
Note: This function is only used for testing.
For regular use, use "await photos.run()".
"""
_LOGGER.debug("start core loop")
self.loop.run_forever()
await self.async_block_till_done()

return self.exit_code

async def async_run(self, *, attach_signals: bool = True) -> int:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
aiohttp==3.7.1
aiohttp>=3.7.0
aiohttp_cors==0.7.0
astral==1.10.1
async_timeout==3.0.1
Expand Down
1 change: 1 addition & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-r requirements.txt

pytest-asyncio>=0.14.0
pytest-aiohttp==0.3.0
pytest-cov==2.10.1
pytest-test-groups==1.0.3
Expand Down
27 changes: 11 additions & 16 deletions tests/addons/api/test_init.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
"""Test the default api implementation."""
import asyncio
import os
from pathlib import Path

import pytest

from core.addons.api import APIStatusView
from core.core import ApplicationCore, CoreState
from core.webserver import status


@pytest.fixture
def mock_api_client():
"""Start the HTTP component and return admin API client."""
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

@pytest.mark.asyncio
async def test_api_get_non_existing_state(aiohttp_client, loop):
"""Test if the debug interface allows us to get a state."""
core = ApplicationCore()
core.config.internal_url = ""
core.config.external_url = ""
core.config.data_dir = os.path.join(os.path.dirname(__file__), "resources", "data")
core.config.data_dir = os.path.join(Path.cwd(), "tests/resources", "data")
core.config.config_dir = os.path.join(Path.cwd(), "tests/resources", "config")
core.state = CoreState.running
core.start()

return loop.run_until_complete(core)
await core.start()


async def test_api_get_non_existing_state(mock_api_client):
"""Test if the debug interface allows us to get a state."""
resp = await mock_api_client.get("/api/states/does_not_exist")
assert resp.status == status.HTTP_NOT_FOUND
# client = await aiohttp_client(core.http.app)
# resp = await client.get('/')
# assert resp.status == status.HTTP_NOT_FOUND
28 changes: 28 additions & 0 deletions tests/resources/config/configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"internal_url": "192.168.0.1",
"external_url": "external.url.com",
"data_dir": "data",
"addons": [
{
"name": "api",
"config": {
"cors": false
}
},
{
"name": "sqlite",
"config": {
"database_file": "test.sqlite"
}
},
{
"name": "metadata"
},
{
"name": "nextcloud"
},
{
"name": "places365"
}
]
}