Skip to content

Commit

Permalink
[#97] Rename and update backend tests for GovTool rebranding
Browse files Browse the repository at this point in the history
This commit encompasses a significant update to the backend testing suite,
aligning it with the GovTool rebranding as part of ticket #111. The changes
include renaming test directories, files, and updating references within
the test cases to reflect the new project codename.

Technical Details:
- Renamed the backend testing directory from `tests/vva-be` to `tests/govtool-backend`.
- Updated `.github/workflows/test_backend.yml` to reference the new test directory and updated project URLs.
- Renamed several files within the test directory, including `.env.example`, `.gitignore`, `README.md`, `config.py`, and various test case files.
- Modified test case files to replace 'vva' references with 'govtool', ensuring the tests are correctly aligned with the updated backend application name.
  • Loading branch information
placek committed Feb 6, 2024
1 parent 033d39c commit 9bacd7b
Show file tree
Hide file tree
Showing 22 changed files with 115 additions and 37 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/test_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
push:
paths:
- .github/workflows/test_backend.yml
# - src/vva-be
# - tests/vva-be
# - govtool/backend
# - tests/govtool-backend

schedule:
- cron: '0 0 * * *'
Expand All @@ -18,23 +18,23 @@ on:
options:
- "sanchogov.tools/api"
- "staging.govtool.byron.network/api"
- "vva-sanchonet.cardanoapi.io/api"
- "govtool-sanchonet.cardanoapi.io/api"

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11.4
cache: 'pip'

- name: Run Backend Test
working-directory: tests/vva-be
working-directory: tests/govtool-backend
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions tests/vva-be/README.md → tests/govtool-backend/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
VVA-BE PyTest
GovTool backend PyTest
=================
This test is responsible for following

- Perform basic tests on VVA backend endpoints.
- Perform basic tests on GovTool backend endpoints.
- Publish the reports to metrics server for visualization.

## Installation
Expand Down Expand Up @@ -31,7 +31,7 @@ This will generate test_data.json that will be used to run tests.


## Run tests
In the root directory of tests/vva-be run the following command
In the root directory of tests/govtool-backend run the following command
```shell
export BASE_URL="url" # server's url e.g. https://staging.govtool.byron.network/api"
export METRICS_URL="url" # metrics server Url
Expand Down
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.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from models.TestResult import Metrics

from test_cases.vva_api import VVAApi
from test_cases.govtool_api import VVAApi

from config import CURRENT_GIT_HASH
from config import BUILD_ID
Expand All @@ -18,7 +18,7 @@


@pytest.fixture(scope="session")
def vva_api():
def govtool_api():
base_url: str = os.environ.get('BASE_URL')
metrics_url: str = os.environ.get('METRICS_URL')

Expand Down Expand Up @@ -64,13 +64,13 @@ def vva_api():
@pytest.hookimpl(wrapper=True, tryfirst=True)
def pytest_runtest_makereport(item):
rep = yield
vva_api_object = item.funcargs.get("vva_api")
govtool_api_object = item.funcargs.get("govtool_api")

if rep.when == "call":

test_func_name = re.search(r'(?<=::)(.*?)*(?=\[|$)', rep.nodeid).group()

vva_api_object.add_test_metrics(
govtool_api_object.add_test_metrics(
Metrics(
outcome=rep.outcome,
test_name=test_func_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@


@pytest.fixture(scope="module", params=ada_holders)
def ada_holder_delegate_to_drep(request, vva_api):
def ada_holder_delegate_to_drep(request, govtool_api):
ada_holder: AdaHolder = request.param

delegation_data = Delegation(
stakeKey=ada_holder["stakeKey"],
dRepId=ada_holder["drepId"]
)

yield delegation_data
yield delegation_data
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions tests/govtool-backend/test_cases/test_ada_holder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from models.TestData import AdaHolder, Delegation

def test_ada_delegation(govtool_api, ada_holder_delegate_to_drep):
print(ada_holder_delegate_to_drep)
response = govtool_api.ada_holder_get_current_delegation(ada_holder_delegate_to_drep["stakeKey"])
resp = response.json()
if resp:
assert ada_holder_delegate_to_drep["drepId"] in resp


def test_check_voting_power(govtool_api, ada_holder_delegate_to_drep):
response = govtool_api.ada_holder_get_voting_power(ada_holder_delegate_to_drep["stakeKey"])
ada_holder_voting_power = response.json()
assert isinstance(ada_holder_voting_power, int)
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ def validate_voteonproposal_list(voteonproposal_list: [VoteonProposal]) -> bool:
return True


def test_list_drep(vva_api):
response = vva_api.drep_list()
def test_list_drep(govtool_api):
response = govtool_api.drep_list()
drep_list = response.json()
validate_drep_list(drep_list)


def test_initialized_getVotes( vva_api, registered_drep):
response = vva_api.drep_getVotes(registered_drep["drepId"])
def test_initialized_getVotes( govtool_api, registered_drep):
response = govtool_api.drep_getVotes(registered_drep["drepId"])
validate_voteonproposal_list(response.json())
votes = response.json()
proposals = map(lambda x: x["vote"]["proposalId"], votes)
proposals = list(proposals)
assert len(proposals)==0


def test_initialized_getVotingPower(vva_api, registered_drep):
response = vva_api.drep_get_voting_power(registered_drep["drepId"])
assert isinstance(response.json(), int)
def test_initialized_getVotingPower(govtool_api, registered_drep):
response = govtool_api.drep_get_voting_power(registered_drep["drepId"])
assert isinstance(response.json(), int)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def validate_proposal_list(proposal_list: [Proposal]) -> bool:
return True


def test_list_proposal(vva_api):
response = vva_api.proposal_list()
def test_list_proposal(govtool_api):
response = govtool_api.proposal_list()
proposal_list = response.json()
assert validate_proposal_list(proposal_list)
78 changes: 78 additions & 0 deletions tests/govtool-backend/test_cases/vva_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import json
import time
from typing import Any

import requests
from requests import Response

from models.TestResult import Metrics
from config import BUILD_ID


class GovToolApi():

def __init__(self, base_url: str):
self._base_url = base_url
self._session = requests.Session()
self._session.headers.update({"Accept": "application/json", "content-type": "application/json"})
self.requests_log = []
self.tests_log = []

def __request(self, method: str, endpoint: str, param: Any | None = None,
body: Any | None = None) -> Response:
endpoint = endpoint if endpoint.startswith('/') else '/' + endpoint
full_url = self._base_url + endpoint
full_url = full_url + "/" + param if param else full_url
start_time = int(time.time()*1000000)

response = self._session.request(method, full_url, json=body)

end_time = int(time.time()*1000000)
response_time = end_time - start_time

try:
response_json = json.dumps(response.json())
response_json_str = response_json[:200]
except:
response_json_str = "Something went wrong"

request_info = {
"method": method,
"endpoint": endpoint,
"path_param": param,
"json": json.dumps(body),
"status_code": response.status_code,
"response_json": response_json_str,
"response_time": response_time,
"start_date": int(start_time),
"build_id": BUILD_ID
}

self.requests_log.append(request_info)

assert 200 >= response.status_code <= 299, f"Expected {method}{endpoint} to succeed but got statusCode:{response.status_code} : body:{response.text}"
return response

def __get(self, endpoint: str, param: str | None = None) -> Response:
return self.__request('GET', endpoint, param)

def drep_list(self) -> Response:
return self.__get('/drep/list')

def drep_getVotes(self, drep_id) -> Response:
return self.__get('/drep/getVotes', drep_id)

def drep_get_voting_power(self, drep_id) -> Response:
return self.__get('/drep/get-voting-power', drep_id)

def proposal_list(self) -> Response:
return self.__get('/proposal/list')

def ada_holder_get_current_delegation(self, stake_key: str) -> Response:
return self.__get('/ada-holder/get-current-delegation', stake_key)

def ada_holder_get_voting_power(self, stake_key) -> Response:
return self.__get('/ada-holder/get-voting-power', stake_key)

def add_test_metrics(self, metrics: Metrics):
self.tests_log.append(metrics)
File renamed without changes.
File renamed without changes.
14 changes: 0 additions & 14 deletions tests/vva-be/test_cases/test_ada_holder.py

This file was deleted.

0 comments on commit 9bacd7b

Please sign in to comment.