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

Fix and run unittests #62

Merged
merged 10 commits into from
Dec 29, 2020
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
ANKI_SERVER_NAME ?= "Anki Sync Server"
ANKI_SERVER_VERSION ?= "v0.1.0"
ANKI_SERVER_DESCRIPTION ?= "Self-hosted Anki Sync Server."
ENV ?= local

ENV ?= local
-include config/.env.${ENV}
export

Expand All @@ -17,10 +17,18 @@ help:
docs: print-env
@${MKDOCS} ${MKDOCS_OPTION} -f docs/mkdocs.yml

.PHONY: tests #: Run unit tests.
tests:
@${UNITTEST} discover -s tests

.PHONY: notebooks #: Run jupyter notebooks.
notebooks:
@${JUPYTER} ${JUPYTER_OPTION}

%:
@test -f scripts/${*}.sh
@${SHELL} scripts/${*}.sh
@${SHELL} scripts/${*}.sh

.PHONY: init #: Download Python dependencies.
init:
@${POETRY} install
37 changes: 34 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ It supports Python 3 and Anki 2.1.
- [Installing](#installing)
- [Installing (Docker)](#installing-docker)
- [Setting up Anki](#setting-up-anki)
- [Anki 2.1](#anki-21)
- [Anki 2.0](#anki-20)
- [AnkiDroid](#ankidroid)
- [Anki 2.1](#anki-21)
- [Anki 2.0](#anki-20)
- [AnkiDroid](#ankidroid)
- [Development](#development)
- [Testing](#testing)
- [ENVVAR configuration overrides](#envvar-configuration-overrides)
- [Support for other database backends](#support-for-other-database-backends)
</details>
Expand Down Expand Up @@ -142,6 +144,35 @@ Even though the AnkiDroid interface will request an email address, this is not
required; it will simply be the username you configured with `ankisyncctl.py
adduser`.

Development
-----------

### Testing

0. Prerequites

This project uses [GNU Make](https://www.gnu.org/software/make/) to simplify the development commands. It also uses [Poetry](https://python-poetry.org/) to manage the Python dependencies. Ensure they are installed.

1. Create a config for your local environment.

```bash
$ cp config/.env.example config/.env.local
```

See [ENVVAR configuration overrides](#envvar-configuration-overrides) for more information.

2. Download Python dependencies.

```bash
$ make init
```

3. Run unit tests.

```bash
$ make tests
```

ENVVAR configuration overrides
------------------------------

Expand Down
16 changes: 9 additions & 7 deletions config/.env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# .env.example (anki-sync-server)

## Make
MKDOCS=mkdocs
JUPYTER=jupyter
POETRY=poetry
MKDOCS=poetry run mkdocs
JUPYTER=poetry run jupyter
UNITTEST=poetry run python -m unittest

## Ankisyncd
ANKISYNCD_HOST=0.0.0.0
Expand All @@ -13,10 +15,10 @@ ANKISYNCD_BASE_MEDIA_URL=/msync/
ANKISYNCD_AUTH_DB_PATH=./auth.db
ANKISYNCD_SESSION_DB_PATH=./session.db

ANKISYNCD_FULL_SYNC_MANAGER
ANKISYNCD_SESSION_MANAGER
ANKISYNCD_USER_MANAGER
ANKISYNCD_COLLECTION_WRAPPER
# ANKISYNCD_FULL_SYNC_MANAGER
# ANKISYNCD_SESSION_MANAGER
# ANKISYNCD_USER_MANAGER
# ANKISYNCD_COLLECTION_WRAPPER

## Mkdocs
MKDOCS_OPTION=serve
Expand All @@ -25,4 +27,4 @@ MKDOCS_OPTION=serve
JUPYTER_OPTION=lab

## Path
PATH:=.venv/bin/path:${PATH}
PATH:=.venv/bin:${PATH}
51 changes: 45 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name = "anki-sync-server"
version = "2.2.0"
description = "Self-hosted Anki Sync Server."
authors = ["Vikash Kothary <[email protected]>"]
packages = [
{ include = "ankisyncd", from = "src" }
]

[tool.poetry.dependencies]
python = "^3.8"
Expand All @@ -21,6 +24,7 @@ webob = "^1.8.6"
mkdocs = "^1.1.2"
jupyter = "^1.0.0"
jupyterlab = "^2.2.2"
webtest = "^2.0.35"

[build-system]
requires = ["poetry>=0.12"]
Expand Down
4 changes: 3 additions & 1 deletion src/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ nbconvert==6.0.7; python_version >= "3.6"
nbformat==5.0.8; python_version >= "3.6"
nest-asyncio==1.4.3; python_version >= "3.6"
nltk==3.5; python_version >= "3.5"
notebook==6.1.5; python_version >= "3.5"
notebook==6.1.6; python_version >= "3.5"
orjson==3.4.6; python_version >= "3.8"
packaging==20.8; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6"
pandocfilters==1.4.3; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.4.0" and python_version >= "3.6"
Expand Down Expand Up @@ -84,8 +84,10 @@ tornado==6.1; python_version >= "3.6"
tqdm==4.54.1; python_version >= "3.5" and python_full_version < "3.0.0" or python_version >= "3.5" and python_full_version >= "3.4.0"
traitlets==5.0.5; python_version >= "3.7"
urllib3==1.26.2; python_version >= "3.8" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version < "4" and python_version >= "3.8"
waitress==1.4.4; python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0"
wcwidth==0.2.5; python_full_version >= "3.6.1" and python_version >= "3.6"
webencodings==0.5.1; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6"
webob==1.8.6; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.3.0")
webtest==2.0.35
widgetsnbextension==3.5.1
-e src/.