-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
beta v.1.0.0 - DB config, list terms and GitHub Actions (#13)
* support: add command RUN to Makefile * support: mkdocs config and define new docs pages * test: config of TestClient interface to handle integration tests of the service * support: ignoring .env files * support: Make command to run loading produciton variables * support: reformat logs for uvicorn server * support: database connection & initial config * support: pydantic schemas for glossary Terms * support: env file loading module * feat: Enum for exceptions of business rules * feat: serializer to normalize API responses * feat: endpoint that lists & search Test Terms from glossary database * docs: list & filter test Terms * docs: add link to docs on GH Page * docs: remove unsed config from mkdocs * Update execute-python-tests.yml * support: update dependencies inside requirements files * support: creates an env file from GitHub secrets, creates an env file * fix: removed extra colons * fix: double-step to use gh secret * support: make help command skips a line before printing results * support: using market GH action to create env file * fix: GHA secret typo error
- Loading branch information
1 parent
8550131
commit b484702
Showing
25 changed files
with
507 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,16 +15,28 @@ jobs: | |
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} # See docs: https://github.com/actions/checkout#checkout-pull-request-head-commit-instead-of-merge-commit | ||
|
||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Creates .staging.env file | ||
uses: SpicyPizza/[email protected] | ||
with: | ||
envkey_DATABASE_CONNECTION_STRING: ${{ secrets.DB_CONNECTION_STRING }} | ||
file_name: .staging.env | ||
fail_on_empty: true | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
- name: Execute tests with pytest | ||
run: | | ||
python -m pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,3 +157,6 @@ cython_debug/ | |
#.idea/ | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/python | ||
|
||
# .env files | ||
*.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# test-glossary-project | ||
Building a glossary of testing terms based on ISTQB's glossary | ||
|
||
Documentation is available at https://thiagojacinto.github.io/test-glossary-project/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Service | ||
|
||
TestGlossary offers an API Service to be used, and documentation for that is also available in well stablished formats - once the server is up and running: | ||
|
||
- `OpenAPI v3`: accessing `/api/openapi.json` | ||
- `swagger`: accessing `/api/docs` | ||
- `redocs`: accessing `/api/redocs` | ||
|
||
While you may find some discussion here about the funcionalities, feel free to visit the the links above. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# API: Version 1 | ||
|
||
This page lists the features implemented in this version of the Test-Glossary service API. | ||
|
||
## `api/v1/healthcheck` | ||
|
||
Endpoint that returns an OK status response just to give an overall status feedback. | ||
|
||
### Allowed Methods | ||
|
||
``` | ||
GET api/v1/healthcheck | ||
``` | ||
|
||
## `api/v1/terms` | ||
|
||
Service that concentrate interactions between user and test Terms database. | ||
|
||
- returns a paginated list of all registered glossary test Terms; | ||
- allow filtering of specific test Terms, returning a paginated list as well, if any match. | ||
|
||
### Allowed Methods | ||
``` | ||
GET api/v1/terms | ||
GET api/v1/terms?page=2&terms_per_page=5 | ||
GET api/v1/terms/search/{specific-term} | ||
GET api/v1/terms/search/{specific-term}?page=1&terms_per_page=5 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
version: 1 | ||
disable_existing_loggers: False | ||
formatters: | ||
default: | ||
"()": uvicorn.logging.DefaultFormatter | ||
format: '%(asctime)s %(levelname)s %(name)s - %(message)s' | ||
access: | ||
"()": uvicorn.logging.AccessFormatter | ||
format: '%(asctime)s %(levelname)s %(name)s - %(message)s' | ||
handlers: | ||
default: | ||
formatter: default | ||
class: logging.StreamHandler | ||
stream: ext://sys.stderr | ||
access: | ||
formatter: access | ||
class: logging.StreamHandler | ||
stream: ext://sys.stdout | ||
loggers: | ||
uvicorn.error: | ||
level: INFO | ||
handlers: | ||
- default | ||
propagate: no | ||
uvicorn.access: | ||
level: INFO | ||
handlers: | ||
- access | ||
propagate: yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
site_name: TestGlossary | ||
theme: readthedocs | ||
theme: readthedocs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,7 @@ uvloop==0.16.0 | |
watchgod==0.7 | ||
websockets==10.2 | ||
zipp==3.7.0 | ||
|
||
SQLAlchemy==1.4.34 | ||
psycopg2==2.9.3 | ||
greenlet==1.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
from testglossary.internal.config import configuration | ||
|
||
# from FastAPI docs' https://fastapi.tiangolo.com/tutorial/sql-databases/#create-the-sqlalchemy-parts | ||
|
||
engine = create_engine( | ||
url=configuration.DATABASE_CONNECTION_STRING, pool_pre_ping=True, echo=True | ||
) | ||
|
||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | ||
|
||
Base = declarative_base() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from sqlalchemy import Column, ForeignKey, Integer, String | ||
|
||
from testglossary.database.connection import Base | ||
|
||
|
||
class Term(Base): | ||
"""Test term to be explained""" | ||
|
||
__tablename__ = "terms" | ||
|
||
id = Column(Integer, primary_key=True, index=True) | ||
name = Column(String) | ||
acronym = Column(String) | ||
definition = Column(String) | ||
version = Column(Integer) | ||
language_id = Column(Integer, ForeignKey("languages.id"), index=True) | ||
|
||
|
||
class Language(Base): | ||
"""Choose language of test term translation""" | ||
|
||
__tablename__ = "languages" | ||
|
||
id = Column(Integer, primary_key=True, index=True) | ||
language = Column(String, unique=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from sqlalchemy.orm import Session | ||
|
||
from testglossary.database.entities import Term | ||
|
||
|
||
def get_terms(db: Session, page: int = 0, results_per_page: int = 30): | ||
""" | ||
Return all test terms, paginated | ||
""" | ||
return db.query(Term).offset(page).limit(results_per_page).all() | ||
|
||
|
||
def get_term_by_name( | ||
db: Session, term_name: str, page: int = 0, results_per_page: int = 5 | ||
): | ||
""" | ||
Search for a test term by its name | ||
""" | ||
return ( | ||
db.query(Term) | ||
.where(Term.name.ilike("%{}%".format(term_name))) | ||
.offset(page) | ||
.limit(results_per_page) | ||
.all() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from os import getenv | ||
|
||
from pydantic import BaseSettings | ||
|
||
|
||
class Configuration(BaseSettings): | ||
""" | ||
Configuration & settings wrapper using Pydantic's BaseSettings | ||
""" | ||
|
||
APP_NAME: str = "TestGlossary API" | ||
DATABASE_CONNECTION_STRING: str = "PROVIDE A VALID DB CONNECTION STRING" | ||
|
||
class Config: | ||
""" | ||
Sub class for handling .env file reading | ||
""" | ||
|
||
env_file = ".staging.env" | ||
env_file_encoding = "utf-8" | ||
|
||
|
||
if getenv("PRODUCTION_READY") == "true": | ||
configuration = Configuration(_env_file=".env") | ||
else: | ||
configuration = Configuration() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
terms: dict = { | ||
"NOT_FOUND": "It was not possible to find any test term with that filter.", | ||
"EMPTY_LIST": "The test term list is currently empty.", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from pydantic import BaseModel | ||
|
||
from testglossary.models.schemas import Term | ||
|
||
|
||
class Paginated_ouput(BaseModel): | ||
""" | ||
Paginated response output serializer. | ||
""" | ||
|
||
result: list | dict | None | ||
page: int = 0 | ||
offset: int = 0 | ||
|
||
|
||
class Paginated_terms_list(Paginated_ouput): | ||
""" | ||
Specialized paginated response for a Test Terms list | ||
""" | ||
|
||
result: list[Term] |
Oops, something went wrong.