Skip to content

Commit

Permalink
Merge pull request #562 from gridsingularity/feature/GSYE-818
Browse files Browse the repository at this point in the history
GSYE-818: Use default CDS from gsy-web for testimg the CDS parser
  • Loading branch information
hannesdiedrich authored Dec 18, 2024
2 parents 8dbf5d5 + 43d575a commit 5d32ab3
Show file tree
Hide file tree
Showing 6 changed files with 462 additions and 148 deletions.
10 changes: 10 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Reason for the proposed changes

Please describe what we want to achieve and why.

## Proposed changes

-

<!--- If needed, choose which branch of the gsy-backend-integration-tests repository will be used to run integration tests. Please only edit the name of the branch. -->
**GSY_WEB_BRANCH**=master
48 changes: 31 additions & 17 deletions .github/workflows/gsy-framework_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,35 @@ jobs:
test-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
env:
TOXENV: ci
run: |
pip install tox==3.24.4
tox -e $TOXENV
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Parse gsy-web branch
env:
prBody: ${{ github.event.pull_request.body }}
run: |
echo "PARSED_GSY_WEB_BRANCH=$(echo -e $prBody | sed -n 's/.*\*\*GSY_WEB_BRANCH\*\*=\([^ ]*\).*/\1/p')" >> $GITHUB_OUTPUT
id: parse_gsy_web_branch
- name: validate parsed gsy web tests branch
env:
PARSED_GSY_WEB_BRANCH: ${{ steps.parse_gsy_web_branch.outputs.PARSED_GSY_WEB_BRANCH }}
run: |
echo "GSY_WEB_BRANCH=${PARSED_GSY_WEB_BRANCH:-master}" >> $GITHUB_OUTPUT
id: validated_gsy_web_branch
- name: Install dependencies
env:
TOXENV: ci
GITHUB_ACCESS_TOKEN: ${{ secrets.GSYDEV_TOKEN }}
TARGET_BRANCH: ${{ steps.validated_gsy_web_branch.outputs.GSY_WEB_BRANCH }}
run: |
pip install tox==3.24.4
tox -e $TOXENV
- name: Check coverage with Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN_GSY_FRAMEWORK }}
fail_ci_if_error: true
verbose: true
- name: Check coverage with Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN_GSY_FRAMEWORK }}
fail_ci_if_error: true
verbose: true
39 changes: 39 additions & 0 deletions gsy_framework/default_cds_downloader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
import shutil
import tempfile

import requests


class DefaultCDSDownloader:
"""Handle CDS file download"""

def __init__(self):
self.workdir = tempfile.mkdtemp()
self.cds_file_path = os.path.join(self.workdir, "CommunityDataSheet.xlsx")

def download(self):
"""Download cds file to temp dir"""
header = {
"Authorization": f"Bearer {os.environ['GITHUB_ACCESS_TOKEN']}",
"X-GitHub-Api-Version": "2022-11-28",
"Accept": "application/vnd.github.raw+json",
}
url = (
f"https://api.github.com/repos/gridsingularity/gsy-web/contents/config/static/"
f"CommunityDataSheet.xlsx?ref={os.environ.get('TARGET_BRANCH', 'master')}"
)
response = requests.get(url, headers=header)
if response.status_code == 200:
with open(self.cds_file_path, "wb") as file:
file.write(response.content)
return

assert False, (
f"Default CDS could not be downloaded because of: "
f"{response.status_code}; {response.json()}"
)

def cleanup(self):
"""Remove temporary directory."""
shutil.rmtree(self.workdir)
Binary file removed tests/fixtures/community_datasheet.xlsx
Binary file not shown.
Loading

0 comments on commit 5d32ab3

Please sign in to comment.