Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powerbi Automated test suite #376

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions Features/Powerbi_integration_exports/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Commcare lookuptable Test Script

These tests ensure that the [lookup table ](https://confluence.dimagi.com/display/commcarepublic/Lookup+Tables)features work as expected and that there are no regressions
The automated tests comprises of [these Lookuptable functionality.](https://docs.google.com/spreadsheets/d/1aTBv4zGeVuNTdnCyuleZbbpqOhPEGl0f78rcKAGWQHQ/edit#gid=1360466241)
## Executing Scripts

### <ins> On Local Machine </ins>

#### Setting up test environment

```sh

# create and activate a virtualenv using your preferred method. Example:
python -m venv venv
source venv/bin/activate


# install requirements
pip install -r requires.txt

```

[More on setting up virtual environments](https://confluence.dimagi.com/display/GTD/QA+and+Python+Virtual+Environments)


#### Running Tests


- Copy `settings-sample.cfg` to `settings.cfg` and populate `settings.cfg` for
the environment you want to test.
- Run tests using pytest command like:

```sh

# To execute all the test cases
pytest -v --rootdir= Features/Lookuptable/testCases

```
- You could also pass the following arguments
- ` -n 3 --dist=loadfile` - This will run the tests parallelly in 3 instances. The number of reruns is configurable.
- ` --reruns 1` - This will re-run the tests once in case of failures.The number of reruns is configurable too.

### <ins> Trigger Manually on Gitaction </ins>

<img align="right" width="400" src="https://user-images.githubusercontent.com/67914792/168757107-3ce9bb6a-57b5-4c15-b20d-e7883bf9ed65.PNG" alt="clone this repository" />

To manually trigger the script,
- Go to [Lookuptable action](https://github.com/dimagi/dimagi-qa/actions/lookuptable.yml)
- Run workflow
- Use workflow from ```master```
- Run!

If you are a part of the QA team, you'll receive emails for the result of the run after it's complete.

<img align="right" width="400" src="https://user-images.githubusercontent.com/67914792/168756705-88e4b330-b05a-4df2-a60c-7d45e8a2d002.PNG" alt="clone this repository" />

Besides, you should be able to find the zipped results in the **Artifacts** section, of the corresponding run (after it's complete).
Empty file.
14 changes: 14 additions & 0 deletions Features/Powerbi_integration_exports/requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Stores information about all the libraries, modules, and packages that are used in this project.


pandas>=1.2.2
pytest>=6.2.5
pytest-html>=3.1.1
selenium == 4.11.2
openpyxl>=3.0.6
pytest-rerunfailures>=10.2
pytest-xdist>=2.4.0
pytest-xdist[psutil]
pyotp >=2.6.0
pytest-order
py
12 changes: 12 additions & 0 deletions Features/Powerbi_integration_exports/settings-sample.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[default]
# This is the environment url of commcare
url = https://www.commcarehq.org/
# Login username of the webuser
login_username =
# Login password of the webuser
login_password =
# This is a preconfigured authentication key used for 2FA tests on staging - If 2FA enabled on staging.
staging_auth_key =
# This is a preconfigured authentication key used for 2FA tests on prod
prod_auth_key =

Empty file.
73 changes: 73 additions & 0 deletions Features/Powerbi_integration_exports/testCases/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import os

from configparser import ConfigParser
from pathlib import Path
from common_utilities.fixtures import *

""""This file provides fixture functions for driver initialization"""

global driver


@pytest.fixture(scope="session")
def environment_settings_lookup():
"""Load settings from os.environ

Names of environment variables:
DIMAGIQA_URL
DIMAGIQA_LOGIN_USERNAME
DIMAGIQA_LOGIN_PASSWORD
DIMAGIQA_MAIL_USERNAME
DIMAGIQA_MAIL_PASSWORD

See https://docs.github.com/en/actions/reference/encrypted-secrets
for instructions on how to set them.
"""
settings = {}
for name in ["url", "login_username", "login_password", "mail_username",
"mail_password", "staging_auth_key", "prod_auth_key"]:

var = f"DIMAGIQA_{name.upper()}"
if var in os.environ:
settings[name] = os.environ[var]
if "url" not in settings:
env = os.environ.get("DIMAGIQA_ENV") or "staging"
subdomain = "www" if env == "production" else env
# updates the url with the project domain while testing in CI
project = "a/qa-automation-prod" if env == "production" else "a/qa-automation"
settings["url"] = f"https://{subdomain}.commcarehq.org/{project}"
return settings


@pytest.fixture(scope="session", autouse=True)
def settings(environment_settings_lookup):
if os.environ.get("CI") == "true":
settings = environment_settings_lookup
settings["CI"] = "true"
if any(x not in settings for x in ["url", "login_username", "login_password",
"mail_username", "mail_password", "staging_auth_key",
"prod_auth_key"]):
lines = environment_settings_lookup.__doc__.splitlines()
vars_ = "\n ".join(line.strip() for line in lines if "DIMAGIQA_" in line)
raise RuntimeError(
f"Environment variables not set:\n {vars_}\n\n"
"See https://docs.github.com/en/actions/reference/encrypted-secrets "
"for instructions on how to set them."
)
return settings
path = Path(__file__).parent.parent / "settings.cfg"
if not path.exists():
raise RuntimeError(
f"Not found: {path}\n\n"
"Copy settings-sample.cfg to settings.cfg and populate "
"it with values for the environment you want to test."
)
settings = ConfigParser()
settings.read(path)
# updates the url with the project domain while testing in local
if settings["default"]["url"] == "https://www.commcarehq.org/":
settings["default"]["url"] = f"{settings['default']['url']}a/qa-automation-prod"
else:
settings["default"]["url"] = f"{settings['default']['url']}a/qa-automation"
return settings["default"]

Loading
Loading