Skip to content

Commit 1baa755

Browse files
committedMar 26, 2024·
Applied suggestions
1 parent cb1b930 commit 1baa755

15 files changed

+74
-57
lines changed
 

‎.github/workflows/backport.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ jobs:
4343
with:
4444
target-branch: 0.12.x
4545
pull-request: ${{ github.event.pull_request.url }}
46-
no-squash: ${{ env.NO_SQUASH_OPTION }}
46+
no-squash: ${{ env.NO_SQUASH_OPTION }}

‎.github/workflows/check-openapi-change.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515

1616
jobs:
1717
check-openapi-change:
18-
# TODO: find a way to set name including the branch we are checking
18+
name: check-openapi-change-${{ github.event.client_payload.branch }}
1919
runs-on: ubuntu-latest
2020
env:
2121
FORCE_COLOR: "1"

‎.github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This workflow will run the full CI for the Horreum python library including the build and the tests execution
2-
# This is going to be triggered on every pull request as well as on main branch.
2+
# This is going to be triggered on every pull request as well as on all stable branches (e.g., main and 0.12.x).
33
name: Python client ci
44

55
on:

‎.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ bin/
1212
**/.kiota.log
1313

1414
# Openapi
15-
openapi/openapi.yaml
15+
openapi/openapi.yaml
16+
17+
# Generate code
18+
src/horreum/raw_client/**

‎Makefile

+6-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ KIOTA_VERSION ?= "v1.12.0"
2929
HORREUM_BRANCH ?= "master"
3030
HORREUM_OPENAPI_PATH ?= "https://raw.githubusercontent.com/Hyperfoil/Horreum/${HORREUM_BRANCH}/docs/site/content/en/openapi/openapi.yaml"
3131
GENERATED_CLIENT_PATH = "${PROJECT_PATH}/src/horreum/raw_client"
32+
OPENAPI_PATH = "${PROJECT_PATH}/openapi"
3233

3334
.PHONY: help
3435
help: ## Display this help.
@@ -41,8 +42,8 @@ clean-bin: ## Clean external tools
4142
@rm -rf ${PROJECT_BIN}
4243

4344
.PHONY: clean
44-
clean: ## Clean external tools and output dirs
45-
@rm -rf ${PROJECT_DIST} ${GENERATED_CLIENT_PATH}/api ${GENERATED_CLIENT_PATH}/models ${GENERATED_CLIENT_PATH}/horreum_raw_client.py ${GENERATED_CLIENT_PATH}/kiota-lock.json
45+
clean: ## Clean output directories
46+
@rm -rf ${PROJECT_DIST} ${GENERATED_CLIENT_PATH} ${OPENAPI_PATH}
4647

4748
.PHONY: kiota
4849
kiota: ${PROJECT_BIN}/kiota ## Install kiota tool under ${PROJECT_PATH}/bin
@@ -66,6 +67,7 @@ tools: kiota ## Install external tools.
6667
generate: tools ## Generate the Horreum client
6768
@{\
6869
set -e ;\
69-
curl -sSfL -o ${PROJECT_PATH}/openapi/openapi.yaml ${HORREUM_OPENAPI_PATH} ;\
70-
${PROJECT_BIN}/kiota generate -l python -c HorreumRawClient -n raw_client -d ${PROJECT_PATH}/openapi/openapi.yaml -o ${GENERATED_CLIENT_PATH} ;\
70+
mkdir -p ${OPENAPI_PATH} ;\
71+
curl -sSfL -o ${OPENAPI_PATH}/openapi.yaml ${HORREUM_OPENAPI_PATH} ;\
72+
${PROJECT_BIN}/kiota generate -l python -c HorreumRawClient -n raw_client -d ${OPENAPI_PATH}/openapi.yaml -o ${GENERATED_CLIENT_PATH} ;\
7173
}

‎README.md

+22-4
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ Contributions to `horreum-client-python` Please check our [CONTRIBUTING.md](./CO
4242

4343
### Development
4444

45-
Install all dev dependencies (consider using Python virtual environments):
45+
Install poetry dependency (consider using Python virtual environments):
4646
```bash
47-
pip install -r dev-constraints.txt
47+
pip install --constraint=./dev-constraints.txt poetry
48+
poetry --version
4849
```
4950

5051
Generate source files
@@ -58,15 +59,32 @@ poetry build
5859
```
5960

6061
#### Tests
62+
Tests can be executed using [nox](https://nox.thea.codes/en/stable/) sessions.
6163

62-
Right now tests are not automated, therefore you need to start up the Horreum server manually,
64+
To install it in your local environment, please run:
65+
```bash
66+
pip install --constraint=./dev-constraints.txt nox nox-poetry
67+
nox --version
68+
```
69+
70+
To check available sessions, run:
71+
```bash
72+
nox -l
73+
```
74+
75+
And execute them by running:
76+
```bash
77+
nox -s [session]
78+
```
79+
80+
Right now integrations tests are not fully automated, therefore you need to start up the Horreum server manually,
6381
you can check more details in [Horreum README](https://github.com/Hyperfoil/Horreum/blob/master/README.md#getting-started-with-development-server).
6482

6583
> **_NOTE_**: The database should be empty to get all tests working
6684
6785
Once the Horreum server is up and running on `localhost:8080`, you can trigger integration tests by running:
6886
```bash
69-
pytest test/
87+
nox -s its
7088
```
7189

7290
### If you have any idea or doubt 👇

‎docs/GET_STARTED.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,23 @@ In this document you can find all information to get started using the Horreum p
1212
---
1313
## Prerequisites
1414

15-
* Python environment, e.g., `pyenv` or `miniconda` with all development dependencies installed:
15+
* Python environment, e.g., `pyenv` or `miniconda` with `poetry` dependency installed:
1616
```bash
17-
pip install -r dev-constraints.txt
17+
pip install --constraint=./dev-constraints.txt poetry
18+
poetry --version
1819
```
1920

2021
## Installation
2122

22-
Once all dependencies are installed simply build the `whl` by running:
23+
Once all [prerequisites](#prerequisites) are satisfied, run the following commands.
24+
25+
First of all, generate the Horreum client:
2326

2427
```bash
2528
make generate
2629
```
2730

28-
to generate source files and
31+
Then, simply build the _wheel_ by running:
2932

3033
```bash
3134
poetry build

‎docs/RELEASE.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ versioning scheme to keep coherence among all Horreum-related projects versions.
99

1010
### Tag a new version
1111

12-
Checkout to your branch, either a `stable` (e.g., `0.12.x`) or the `main` one.
12+
Checkout to your branch, either a "stable" (e.g., `0.12.x`) or the `main` one.
1313

1414
```bash
1515
git checkout origin/main
@@ -25,7 +25,7 @@ This will bump your version, from `0.12-dev` to `0.12`.
2525

2626
To double-check the version, run:
2727
```bash
28-
poetry version [15:55:39]
28+
poetry version
2929
# horreum 0.12
3030
```
3131

@@ -49,14 +49,12 @@ from _stable_ rather than from `main`.
4949

5050
### Create stable branch
5151

52-
> **NOTE**: If the _stable_ branch is already existing simply skip this step at all as this means
53-
> you already did the following steps.
52+
> **NOTE**: If the _stable_ branch already exists, simply skip this step, as this means the following steps have already been done.
5453
5554
To create a _stable_ branch from the `main` one, e.g., `0.12.x`, run the following commands.
5655

5756
```bash
58-
git checkout origin/main
59-
git checkout -b 0.12.x
57+
git checkout origin/main -b 0.12.x
6058
git checkout origin/main
6159
```
6260

‎noxfile.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,33 @@
1111

1212
@session(python=py_versions)
1313
def tests(s: Session):
14+
""" Run unit tests """
1415
s.install(".")
15-
s.install("pytest")
16+
s.install(
17+
"asyncio",
18+
"pytest",
19+
"pytest-asyncio"
20+
)
1621
# run tests
1722
s.run(
1823
"pytest",
1924
"test/horreum_client_test.py",
2025
*s.posargs
2126
)
27+
28+
29+
@session(python=py_versions)
30+
def its(s: Session):
31+
""" Run integration tests """
32+
s.install(".")
33+
s.install(
34+
"asyncio",
35+
"pytest",
36+
"pytest-asyncio"
37+
)
38+
# run tests
39+
s.run(
40+
"pytest",
41+
"test/horreum_client_it.py",
42+
*s.posargs
43+
)

‎openapi/.gitkeep

Whitespace-only changes.

‎src/horreum/horreum_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from kiota_http.httpx_request_adapter import HttpxRequestAdapter
99

1010
from .keycloak_access_provider import KeycloakAccessProvider
11-
from .raw_client import HorreumRawClient
11+
from .raw_client.horreum_raw_client import HorreumRawClient
1212

1313

1414
async def setup_auth_provider(base_url: str, username: str, password: str) -> AccessTokenProvider:

‎src/horreum/raw_client/.gitignore

-5
This file was deleted.

‎src/horreum/raw_client/__init__.py

-5
This file was deleted.

‎test/horreum_client_it.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ async def authenticated_client() -> HorreumClient:
4343
return client
4444

4545

46-
def test_check_client_version(anonymous_client_without_check: HorreumClient):
47-
version = anonymous_client_without_check.version()
48-
# TODO: we could load the toml and check the versions match
49-
assert version != ""
50-
51-
5246
@pytest.mark.asyncio
5347
async def test_check_server_version(anonymous_client: HorreumClient):
5448
version = await anonymous_client.raw_client.api.config.version.get()
@@ -73,11 +67,9 @@ async def test_check_auth_token(authenticated_client: HorreumClient):
7367

7468
@pytest.mark.asyncio
7569
async def test_missing_username_with_password():
76-
try:
70+
with pytest.raises(RuntimeError) as ex:
7771
await new_horreum_client(base_url="http://localhost:8080", password=password)
78-
pytest.fail("expect RuntimeError here")
79-
except RuntimeError as e:
80-
assert str(e) == "providing password without username, have you missed something?"
72+
assert str(ex.value) == "providing password without username, have you missed something?"
8173

8274

8375
@pytest.mark.asyncio

‎test/horreum_client_test.py

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
import httpx
21
import pytest
3-
from kiota_abstractions.authentication import BaseBearerTokenAuthenticationProvider
4-
from kiota_abstractions.base_request_configuration import RequestConfiguration
5-
from kiota_abstractions.headers_collection import HeadersCollection
6-
from kiota_abstractions.method import Method
7-
from kiota_abstractions.request_information import RequestInformation
82

93
from horreum.horreum_client import new_horreum_client, HorreumClient
10-
from horreum.raw_client.api.test.test_request_builder import TestRequestBuilder
11-
from horreum.raw_client.models.protected_type_access import ProtectedType_access
12-
from horreum.raw_client.models.test import Test
13-
14-
username = "user"
15-
password = "secret"
164

175

186
@pytest.fixture()
@@ -22,7 +10,8 @@ async def anonymous_client() -> HorreumClient:
2210
return client
2311

2412

25-
def test_check_client_version(anonymous_client: HorreumClient):
13+
@pytest.mark.asyncio
14+
async def test_check_client_version(anonymous_client: HorreumClient):
2615
version = HorreumClient.version()
2716
# TODO: we could load the toml and check the versions match
2817
assert version != ""

0 commit comments

Comments
 (0)
Please sign in to comment.