Skip to content

Commit

Permalink
feat: add unit tests config and examples (UNICT-DMI#212)
Browse files Browse the repository at this point in the history
* feat: add unit tests config and examples

* chore: update github action conf

* chore: main -> master

* chore: update CI, run doc job only for master

* chore: separate workflow

* chore: update doc.yml

* chore: update requirements_dev.txt
  • Loading branch information
Helias authored May 20, 2022
1 parent 7fc84bc commit d26a8ba
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = tests/*
38 changes: 38 additions & 0 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: DMI_bot_deploy

on:
push:
branches: [master]
paths-ignore:
- "README.md"
- "docs/**"

jobs:
doc:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9.7
uses: actions/setup-python@v2
with:
python-version: 3.9.7
- name: Install dependencies for requirements and testing
run: |
python -m pip install --upgrade pip
pip install sphinx sphinx_rtd_theme sphinx_autodoc_typehints
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements_dev.txt ]; then pip install -r requirements_dev.txt; fi
- name: Setup enviroment
run: |
mv config/settings.yaml.dist config/settings.yaml
mv data/DMI_DB.db.dist data/DMI_DB.db
- name: Sphinx build
run: |
sphinx-build -b html docs/source docs/build/docs
echo "# Telegram DMI bot documentation" > docs/build/README.md
- name: Deploy to GitHub Pages
uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: docs/build
43 changes: 9 additions & 34 deletions .github/workflows/telegram-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ on:
paths-ignore:
- "README.md"
- "docs/**"
pull_request:
branches: [master]
paths-ignore:
- "README.md"
- "docs/**"

jobs:
test:
Expand Down Expand Up @@ -37,37 +42,7 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
doc:
needs: test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9.7
uses: actions/setup-python@v2
with:
python-version: 3.9.7
- name: Install dependencies for requirements and testing
run: |
python -m pip install --upgrade pip
pip install sphinx sphinx_rtd_theme sphinx_autodoc_typehints
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements_dev.txt ]; then pip install -r requirements_dev.txt; fi
- name: Setup enviroment
run: |
mv config/settings.yaml.dist config/settings.yaml
mv data/DMI_DB.db.dist data/DMI_DB.db
- name: Sphinx build
run: |
sphinx-build -b html docs/source docs/build/docs
echo "# Telegram DMI bot documentation" > docs/build/README.md
- name: Deploy to GitHub Pages
uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: docs/build
- name: Unit test
run: pytest tests/unit/
# - name: End-to-end test
# run: pytest tests/e2e/
38 changes: 26 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ pip3 install -r requirements.txt
### docker-compose(recommended)

```yaml
version: '2'
version: "2"
services:
dmibot:
image: unictdmi/dmibot
container_name: dmibot
volumes:
- </path/to/settings.yaml>:/dmibot/config/settings.yaml
- </path/to/DMI_DB.db>:/dmibot/data/DMI_DB.db
dmibot:
image: unictdmi/dmibot
container_name: dmibot
volumes:
- </path/to/settings.yaml>:/dmibot/config/settings.yaml
- </path/to/DMI_DB.db>:/dmibot/data/DMI_DB.db
```
### docker cli
Expand All @@ -68,10 +68,10 @@ docker run -v </path/to/settings.yaml>:/dmibot/config/settings.yaml -v </path/to

Container images are configured using parameters passed at runtime (such as those above). These parameters are separated by a colon and indicate \<external>:\<internal> respectively.

| Parameter | Function |
| :----: | --- |
| Parameter | Function |
| :-------------------------------: | ------------------- |
| `-v /dmibot/config/settings.yaml` | configurations file |
| `-v /dmibot/data/DMI_DB.db` | database |
| `-v /dmibot/data/DMI_DB.db` | database |

### Building locally

Expand Down Expand Up @@ -116,6 +116,20 @@ You can enable these commands setting **disable_drive = 0** and configuring the
pip3 install -r requirements_dev.txt
```

Start **unit tests**:

```bash
pytest tests/unit/
```

If you want to check also the code coverage report through an HTML format use:

```bash
pytest --cov . tests/unit/ --cov-report=html
```

To run the end-to-end tests read the following steps below.

Steps:

- Sign in your Telegram account with your phone number **[here](https://my.telegram.org/auth)**. Then choose β€œAPI development tools”
Expand Down Expand Up @@ -147,10 +161,10 @@ python3 conftest.py .

**Check [here](https://dev.to/blueset/how-to-write-integration-tests-for-a-telegram-bot-4c0e) if you want to have more information on the steps above**

Start tests:
Start **end-to-end tests**:

```bash
pytest
pytest tests/e2e/
```

## :books: Documentation
Expand Down
6 changes: 4 additions & 2 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pytest==6.2.5
pytest
Telethon==1.23.0
pytest-asyncio==0.16.0
pytest-asyncio==0.16.0
pytest-mock
pytest-cov
Empty file added tests/e2e/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added tests/unit/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions tests/unit/test_professor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from module.data.professor import Professor

def test_professor_table() -> None:
professor = Professor()
assert professor.table == "professors"

def test_professor_columns() -> None:
professor = Professor()
assert professor.columns == ("ID", "ruolo", "nome", "scheda_dmi", "fax", "telefono", "email", "ufficio", "sito")

0 comments on commit d26a8ba

Please sign in to comment.