-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
312 additions
and
42 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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# name: databuilder | ||
|
||
# on: | ||
# push: | ||
# branches: | ||
# - main | ||
|
||
# jobs: | ||
# run-workflow-script: | ||
# runs-on: ubuntu-latest | ||
|
||
# steps: | ||
# - name: Checkout main branch | ||
# uses: actions/checkout@v2 | ||
# with: | ||
# ref: main | ||
|
||
# - name: Set up Python | ||
# uses: actions/setup-python@v2 | ||
# with: | ||
# python-version: "3.11.4" | ||
|
||
# # - name: Install dependencies # not needed atm as we are not using any requirements apart from default libs | ||
# # run: | | ||
# # python -m pip install --upgrade pip | ||
# # pip install -r requirements.txt | ||
|
||
# - name: Run Python script | ||
# run: python src/combine_data.py | ||
|
||
# - name: Archive generated files as artifact | ||
# uses: actions/upload-artifact@v4 | ||
# with: | ||
# name: generated-files | ||
# path: ./api | ||
|
||
# - name: Checkout production branch | ||
# uses: actions/checkout@v2 | ||
# with: | ||
# ref: production | ||
|
||
# - name: Download generated files artifact | ||
# uses: actions/download-artifact@v4 | ||
# with: | ||
# name: generated-files | ||
# path: ./api | ||
|
||
# - name: Apply changes to production branch | ||
# run: | | ||
# git config --local user.email "[email protected]" | ||
# git config --local user.name "GitHub Action" | ||
# git add . | ||
# git diff-index --quiet HEAD || (git commit -a -m "Add generated files from main branch" --allow-empty && git push origin production) |
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,24 @@ | ||
# name: data sorter | ||
# run-name: Sorting data on branch ${{github.ref_name}} | ||
# on: | ||
# push: | ||
# branches: | ||
# - "!main" | ||
# - "!production" | ||
# - "*" | ||
|
||
# permissions: write-all | ||
# jobs: | ||
# sort-data: | ||
# runs-on: ubuntu-latest | ||
# steps: | ||
# - name: checkout repo content | ||
# uses: actions/checkout@v2 | ||
|
||
# - name: setup python | ||
# uses: actions/setup-python@v4 | ||
# with: | ||
# python-version: "3.11" | ||
|
||
# - name: sort data | ||
# run: python src/sort_data.py |
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,24 @@ | ||
# name: data validator | ||
# run-name: Validating data on branch ${{github.ref_name}} | ||
# on: | ||
# push: | ||
# branches: | ||
# - "!main" | ||
# - "!production" | ||
# - "*" | ||
|
||
# permissions: write-all | ||
# jobs: | ||
# sort-data: | ||
# runs-on: ubuntu-latest | ||
# steps: | ||
# - name: checkout repo content | ||
# uses: actions/checkout@v2 | ||
|
||
# - name: setup python | ||
# uses: actions/setup-python@v4 | ||
# with: | ||
# python-version: "3.11" | ||
|
||
# - name: sort data | ||
# run: python src/validate_data.py |
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,47 +1,47 @@ | ||
name: data-sorter | ||
run-name: Push by ${{ github.actor }} is sorting station mappings.json | ||
on: | ||
push: | ||
branches: | ||
- "*" | ||
- "*/**" | ||
- "!main" # Exclude the main branch | ||
permissions: write-all | ||
jobs: | ||
consolidate-and-sort-data: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: checkout repo content | ||
uses: actions/checkout@v2 # checkout the repository content | ||
# name: data-sorter | ||
# run-name: Push by ${{ github.actor }} is sorting station mappings.json | ||
# on: | ||
# push: | ||
# branches: | ||
# - "*" | ||
# - "*/**" | ||
# - "!main" # Exclude the main branch | ||
# permissions: write-all | ||
# jobs: | ||
# consolidate-and-sort-data: | ||
# runs-on: ubuntu-latest | ||
# steps: | ||
# - name: checkout repo content | ||
# uses: actions/checkout@v2 # checkout the repository content | ||
|
||
- name: setup python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.11" # install the python version needed | ||
# - name: setup python | ||
# uses: actions/setup-python@v4 | ||
# with: | ||
# python-version: "3.11" # install the python version needed | ||
|
||
- name: Check, sort and consolidate data | ||
id: consolidate | ||
working-directory: . | ||
run: python .github/workflows/main.py | ||
# - name: Check, sort and consolidate data | ||
# id: consolidate | ||
# working-directory: . | ||
# run: python .github/workflows/main.py | ||
|
||
- name: Check script outcome | ||
run: | | ||
if [ ${{ steps.consolidate.outcome }} != 'success' ]; then | ||
echo "Sorting and consolidation of data failed, data invalid" | ||
exit 1 | ||
fi | ||
# - name: Check script outcome | ||
# run: | | ||
# if [ ${{ steps.consolidate.outcome }} != 'success' ]; then | ||
# echo "Sorting and consolidation of data failed, data invalid" | ||
# exit 1 | ||
# fi | ||
|
||
- if: ${{ steps.consolidate.outcome == 'success' }} | ||
name: commit files | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git add -A | ||
git diff-index --quiet HEAD || (git commit -a -m "Consolidated and formatted data" --allow-empty) | ||
# - if: ${{ steps.consolidate.outcome == 'success' }} | ||
# name: commit files | ||
# run: | | ||
# git config --local user.email "[email protected]" | ||
# git config --local user.name "GitHub Action" | ||
# git add -A | ||
# git diff-index --quiet HEAD || (git commit -a -m "Consolidated and formatted data" --allow-empty) | ||
|
||
- if: ${{ steps.consolidate.outcome == 'success' }} | ||
name: push changes | ||
uses: ad-m/[email protected] | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: ${{ github.ref }} | ||
# - if: ${{ steps.consolidate.outcome == 'success' }} | ||
# name: push changes | ||
# uses: ad-m/[email protected] | ||
# with: | ||
# github_token: ${{ secrets.GITHUB_TOKEN }} | ||
# branch: ${{ github.ref }} |
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,5 @@ | ||
{ | ||
"python.analysis.extraPaths": [ | ||
"./src" | ||
] | ||
} |
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,13 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "Run tests", | ||
"type": "shell", | ||
"command": "python3", | ||
"args": [ | ||
"src/test_runner.py" | ||
] | ||
} | ||
] | ||
} |
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 @@ | ||
- read data and overwrite data later on, to automatically enforce upper case for all ICAO for ex. or convert str frequencies to float |
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 @@ | ||
print("Test sort workflow") |
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,31 @@ | ||
import unittest | ||
import os | ||
import sys | ||
|
||
|
||
def run_tests(): | ||
""" | ||
This function runs all unit tests inside of the tests/ directory and its subdirectories. | ||
""" | ||
|
||
# Get the absolute path of the directory containing this script | ||
script_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
# Construct the path to the tests/ directory next to this script | ||
tests_dir = os.path.join(script_dir, "tests") | ||
|
||
# Discover and run tests in the tests/ directory and its subdirectories | ||
test_loader = unittest.TestLoader() | ||
test_suite = test_loader.discover( | ||
start_dir=tests_dir, pattern="test_*.py", top_level_dir=script_dir | ||
) | ||
test_runner = unittest.TextTestRunner() | ||
result = test_runner.run(test_suite) | ||
|
||
# Explicitly exit with status code based on test result | ||
if not result.wasSuccessful(): | ||
sys.exit(1) # Exit with non-zero status code if tests failed | ||
|
||
|
||
if __name__ == "__main__": | ||
run_tests() |
Empty file.
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,24 @@ | ||
from unittest import TestCase | ||
|
||
from validators.logon import logon_validator | ||
|
||
|
||
class TestLogonValidator(TestCase): | ||
def test_normal(self): | ||
|
||
logon = "EDMM_FUL_CTR" | ||
self.assertEqual(logon.upper(), logon_validator(logon)) | ||
|
||
logon = "edmm_ful_ctr" | ||
self.assertEqual(logon.upper(), logon_validator(logon)) | ||
|
||
logon = "EDDL_TWR" | ||
self.assertEqual(logon.upper(), logon_validator(logon)) | ||
|
||
logon = "eddb_twr" | ||
self.assertEqual(logon.upper(), logon_validator(logon)) | ||
|
||
def test_exceptions(self): | ||
with self.assertRaises(ValueError): | ||
logon = "EDMM_INVALIDSUFFIX" | ||
logon_validator(logon) |
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,29 @@ | ||
from unittest import TestCase | ||
|
||
from pydantic import ValidationError | ||
from views.icao import ICAOModel | ||
|
||
|
||
class TestICAOType(TestCase): | ||
def test_normal(self): | ||
ICAOModel(icao="EDDB") | ||
ICAOModel(icao="EDDL") | ||
ICAOModel(icao="EDDF") | ||
|
||
def test_lowercase(self): | ||
test = ICAOModel(icao="eddl") | ||
|
||
self.assertEqual(test.icao, "EDDL") | ||
|
||
def test_expections(self): | ||
# ValidationError due to numbers in ICAO | ||
with self.assertRaises(ValidationError): | ||
ICAOModel(icao="1ADW") | ||
|
||
# ValidationError due to <4 letters | ||
with self.assertRaises(ValidationError): | ||
ICAOModel(icao="EDD") | ||
|
||
# ValidationError due to >4 letters | ||
with self.assertRaises(ValidationError): | ||
ICAOModel(icao="EDDTT") |
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 @@ | ||
print("Test validate workflow") |
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,24 @@ | ||
LOGON_SUFFIXES = [ | ||
"DEL", | ||
"RMP", | ||
"GND", | ||
"TWR", | ||
"DEP", | ||
"APP", | ||
"CTR", | ||
"FSS", | ||
"RDO", | ||
"TMV", | ||
"FMP", | ||
] | ||
|
||
|
||
def logon_validator(value: str) -> str: | ||
value = value.strip().upper() | ||
|
||
parts = value.split("_") | ||
|
||
if len(parts) >= 2 and not parts[-1] in LOGON_SUFFIXES: | ||
raise ValueError(f"Suffix {parts[-1]} is not allowed.") | ||
|
||
return value |
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,14 @@ | ||
from pydantic import BaseModel, Field, field_validator | ||
|
||
|
||
class ICAOModel(BaseModel): | ||
icao: str = Field( | ||
..., | ||
pattern=r"^[A-Za-z]{4}$", | ||
description="Must be a string of exactly 4 letters.", | ||
) | ||
|
||
@field_validator("icao") | ||
@classmethod | ||
def validate_icao(cls, value: str) -> str: | ||
return value.strip().upper() |
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 @@ | ||
from typing import Literal | ||
|
||
|
||
ScheduleType = Literal["EDGG", "EDMM", "EDWW"] |
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,22 @@ | ||
from typing import List, Literal, Optional | ||
from pydantic import BaseModel, field_validator | ||
|
||
from validators.logon import logon_validator | ||
from views.schedules import ScheduleType | ||
|
||
|
||
class Station(BaseModel): | ||
logon: str | ||
frequency: float | ||
abbreviation: str | ||
description: Optional[str] | ||
schedule_show_always: Optional[ScheduleType] | ||
schedule_show_booked: Optional[ScheduleType] | ||
relevant_airports: List[str] | ||
gcap_status: Optional[Literal["AFIS", "1", "2"]] | ||
s1_twr: Optional[bool] | ||
|
||
@field_validator("logon") | ||
@classmethod | ||
def validate_logon(cls, value: str) -> str: | ||
return logon_validator(value) |