{"id":19041664,"url":"https://github.com/hudsonssrosa/pyon-sql-tests","last_synced_at":"2026-05-08T17:30:19.845Z","repository":{"id":126290232,"uuid":"376976301","full_name":"hudsonssrosa/pyon-sql-tests","owner":"hudsonssrosa","description":"PYON-SQL | SQL Testing in Python-Behave","archived":false,"fork":false,"pushed_at":"2021-06-15T09:27:05.000Z","size":13431,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-21T22:43:32.309Z","etag":null,"topics":["allure-report","behave","database-testing","mysql","oracle-sql","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hudsonssrosa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-14T22:57:34.000Z","updated_at":"2021-06-15T09:27:07.000Z","dependencies_parsed_at":"2023-06-16T04:15:23.225Z","dependency_job_id":null,"html_url":"https://github.com/hudsonssrosa/pyon-sql-tests","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hudsonssrosa/pyon-sql-tests","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hudsonssrosa%2Fpyon-sql-tests","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hudsonssrosa%2Fpyon-sql-tests/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hudsonssrosa%2Fpyon-sql-tests/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hudsonssrosa%2Fpyon-sql-tests/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hudsonssrosa","download_url":"https://codeload.github.com/hudsonssrosa/pyon-sql-tests/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hudsonssrosa%2Fpyon-sql-tests/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32789368,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T08:22:46.396Z","status":"ssl_error","status_checked_at":"2026-05-08T08:22:45.650Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["allure-report","behave","database-testing","mysql","oracle-sql","python3"],"created_at":"2024-11-08T22:30:42.718Z","updated_at":"2026-05-08T17:30:19.795Z","avatar_url":"https://github.com/hudsonssrosa.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\".resources/logos/pyon_logo_min.png\" height=\"360\"\u003e\n\n# pyon-sql-tests\nPYON-SQL | SQL Testing in Python-Behave\n\nPyon SQL Tests project is available to implement validations for database scripts and changeset scenarios:\n\n- Programming Language: [Python-based](https://www.python.org/downloads/).\n- Framework for behavioural tests: [Behave](https://behave.readthedocs.io/en/latest/)\n- Minimal library requirements: [Mysql-Connector-Python](https://pypi.org/project/mysql-connector-python/) and [cx-Oracle](https://pypi.org/project/cx-Oracle/)\n\nTo know how you can configure your environment to implement and execute this project locally or even remotely, follow all the instructions from this documentation. So, let's start with it and good luck!\n\n## CLONING THE PROJECT FROM GITHUB\n\nGo to [GITHUB](https://github.com/hudsonssrosa/pyon-sql-tests) and **CLONE** the project using **GIT** (download and install GIT from [here](https://git-scm.com/downloads))\n\nIn you local machine, choose you local repository and clone the project using SSH for Mac OS or Linux platforms with this command:\n\n```bash\n    git clone git@github.com:hudsonssrosa/pyon-sql-tests.git\n```\n\nIf you are having issues when cloning or pushing to the repository make sure you have all your SSH keys in place. Click [here](https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh) for more information about it.\n\n## PREPARING YOUR ENVIRONMENT\n\n### 1. Install Python\n\nDownload and install the [latest Python](https://www.python.org/downloads/) version (3.8 or over). During the installation, make sure about the root user password.\n\n### 2. Choose a good IDE\n\nOnce you have opened the project in an IDE of your preference (suggestion: install [Visual Studio Code](https://code.visualstudio.com/download) or [PyCharm CE](https://www.jetbrains.com/pycharm/)), then you will need to *set the Python interpreter* for the project.\n\nAfter this, you are able to create the *Python Virtual Environment* for the PyonUIT project and install all the requirements needed (libraries/packages). You just need to run for the first time the `update.py` and then the virtual environment as well the libraries in `requirements.txt` will be automatically installed for you.\n\n- In Windows:\n\n```bash\n      python update.py\n```\n\n- In MacOSX or Linux:\n\n```bash\n      python3 update.py\n```\n\n### 3. Install the RDBMS to Manage your Database Locally\n\nTo test locally the examples from this project, you'll need at least the MySQL Workbench installed to manage the database created by the tests. So start installing from\n[MySQL Workbench](https://dev.mysql.com/downloads/workbench/)\n\n### 4. Ways to run this project\n\nBy default, the tests will run locally, but you have 3 ways to customise your execution.\n\n#### 4.1 Run in debugging mode\n\nTo check if the environment is totally operational to begin with some implementation, or even check the existing tests, you might dealing with the environment variables to prepare for an execution. Thus, copy the file `env_settings.properties.local` and paste the new one in project's root (in the same place as the original file) renaming it to `env_settings.properties`. So, you can edit the properties freely, because this file is ignored by GIT versioning.\n\nInto this file, to consider a development or debug setting, ensure the property `development_mode` is set as `true`. With this, all the properties that start with `debug_...` will be considered in a project debugging overwriting any command lines from CLI:\n\n```properties\n    [default]\n    db_user =\n    db_password =\n    db_host =\n    db_name =\n    db_driver_abs_path = \n\n    development_mode = true\n    debug_flag_environment = staging\n\n    # Get more information about PYON CLI, type in the terminal console: \"python behave_runner.py --help\"\n    debug_flag_target = local\n    debug_flag_os = MacOS Catalina\n    debug_flag_os_version =\n    debug_flag_mode = mysql\n\n    debug_behave_tags = demo-mysql\n    debug_behave_excluded_tags = wip\n```\n\n- To generate Allure Reports locally, make sure you have `Java` installed and the flag `generate_report = true` on your `env_settings.properties`.\n\n#### 4.2 Run as if it were in CI\n\nAfter any implementation into the PyonUIT, it is recommended to validate the tests simulating an execution capable to inject parameters in environment variables, like it is performed in a build from a CI server. To validate a test execution, keep in mind to run in a remote server. Before this, you also will need to copy the file `run_behave.sh.local` and paste the new one in project's root (in the same place as the original file) renaming it to `run_behave.sh` to be ignored in commits.\n\nInto this script file, you can set those environment variables, like this:\n\n```bash\n    PYON_ENVIRONMENT='staging'\n    PYON_EXCLUDED_TAG='wip'\n    PYON_TARGET='local'\n    PYON_MODE='mysql'\n    PYON_OS='MacOS Catalina'\n    PYON_OS_VERSION=\n    PYON_TAGS='demo-mysql'\n```\n\n#### 4.3 Run via CLI (only command line)\n\nYou can handle all those parameters presented previously (in section 4.2) setting them directly via CLI. You just need to pass the desired values in the arguments by command line.\nFirst of all, call the main runner file in the terminal and press Enter. So, try this:\n\n```bash\n      python3 behave_runner.py --help\n```\n\nYou might see all the supported arguments that you can use:\n\n```bash\nusage: behave_runner.py [options]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --environment {staging,dev,production}\n                        ==\u003e Environment to execute the tests (default = staging). Find the app URLs in properties file\n  --target {local}      ==\u003e Platform to execute the tests (default = local)\n  --mode {mysql,oracle}\n                        ==\u003e RDBMS to be connected (default = mysql)\n  --os {MacOS High Sierra,MacOS Catalina,MacOS Big sur,Windows,Windows 10,iOS,Android,}\n                        ==\u003e Operational System from the current server\n  --os_version {14.3,14.0,14,13.0,13,12.0,12,11.0,11,10.0,10,9.0,9,8.1,8.0,8,7.1,7.0,7,6.0,6,5.0,5,4.4,}\n                        ==\u003e Preferably use XX.X for mobile and XX for OS platform versions\n  --tags TAGS           ==\u003e Feature(s) / Scenario(s) to be executed (separate tags by comma and without spaces)\n  --exclude {wip,skip,bug,slow,obsolete,}\n                        ==\u003e Feature(s) / Scenario(s) to be ignored / skipped from execution using a single tag (recommended: wip)\n```\n\nFinally, you can vary the command options such as these samples below and much more. If you does not pass the other arguments, it will be considered the default values:\n\n```bash\n     python behave_runner.py --target local\n     python behave_runner.py --target local --environment production\n     python behave_runner.py\n     python behave_runner.py --os 'Windows' --os_version '10'\n     python behave_runner.py --mode oracle\n     python behave_runner.py --tags demo-mysql\n```\n\n## BDD APROACHING USING PYTHON-BEHAVE\n\nThe [Behaviour Driven Development](https://cucumber.io/docs/bdd/) can make our automated tests much more agile, productive, sustainable and with a living-documentation of business. Considering this, in the following sections will be presented a step-by-step about how to implement a simple scenario considering Python-Behave (library backed up by Python code - Cucumber-based) and Selenium to make possible to automate our Gherkin scenarios.\n\n### HOW TO IMPLEMENT TESTS USING PYON-SQL?\n\nConsidering that the number of tests can increase significantly in this project, it is very important to keep in mind that you also need to have a good and coherent organisation of Query files, scenarios, steps and settings associated to the tests. Initially, to have the codes recognised by Behave framework, all the files related to test cases should be implemented into the `features` folder. Take a look at the recommended structure below.\n\n#### 1. Gherkin Files\n\nAll the tests are documented in [Gherkin](https://behave.readthedocs.io/en/latest/tutorial.html#feature-files), a structured and natural language with properly keywords (Given, When, Then) that allows us to write testable specifications. Those files have the format `.feature` and should be organised into the '/features' with subfolders such as ENVIRONMENT FOLDER (dev/staging/production) \u003e DOMAIN FOLDER (global name of a functionality) \u003e FEATURE FILE. For example:\n\n```\n    features\n    └─── feature_domains\n        └─── staging\n            │    demo_mysql_db_recriation.feature\n            │    demo_mysql_table_registers.feature\n            │        ...\n            production\n            └─── ...\n```\n\n##### 1.1. Create a Feature\n\nWith this, you could create a simple scenario that validates if user can search a product at Automation Practice Website. You just need to use the keywords with `Feature:`, `Background:`, `Scenario:`, and describe the behaviours for steps with `Given`, `When` and `Then`:\n\n```gherkin\n@demo-mysql\nFeature: Selecting registers from Pyon Schema Tests tables\n\n    Background: Cleaning up the 'pyon_schema_tests' database\n        Given that \"pyon_schema_tests\" is connected\n\n    @demo-mysql-tables\n    Scenario: The user can create tables, populate and select registers\n        Given that the tables tb_test_resource, tb_test_type, tb_category and tb_feature are created\n        When user populates these tables\n        Then the user can select with a join between tb_feature, tb_test_type and tb_category tables\n        And the feature registers are showed\n```\n\nAs you could see, add a **tag** (started with @) trying to choose an easy and intuitive name that reminds you about the Feature. Also, you can include another tag above the scenario, if you want to create new scenarios into the same file. This can make easier to call specific scenarios or an entire feature to be executed via Behave command line.\n\n##### 1.2. Generate the Step definitions\n\nAfter having a scenario defined, make sure that `development_mode` is `false` in `env_settings.properties` if you want to execute the `python3 behave_runner.py --tags demo-mysql` in the terminal (or set `development_mode` to `true` and include the tag `demo-mysql` to property `debug_behave_tags`). Then, copy the snippet definitions generated automatically in console. You will need to implement your steps using them, like these:\n\n```bash\n    You can implement step definitions for undefined steps with these snippets:\n\n    @given(u'that \"pyon_schema_tests\" is connected')\n    def step_impl(context):\n        raise NotImplementedError(u'STEP: Given that \"pyon_schema_tests\" is connected')\n\n\n    @given(u'that the tables tb_test_resource, tb_test_type, tb_category and tb_feature are created')\n    def step_impl(context):\n        raise NotImplementedError(u'STEP: Given that the tables tb_test_resource, tb_test_type, tb_category and tb_feature are created')\n\n\n    @when(u'user populates these tables')\n    def step_impl(context):\n        raise NotImplementedError(u'STEP: When user populates these tables')\n\n\n    @then(u'the user can select with a join between tb_feature, tb_test_type and tb_category tables')\n    def step_impl(context):\n        raise NotImplementedError(u'STEP: Then the user can select with a join between tb_feature, tb_test_type and tb_category tables')\n\n\n    @then(u'the feature registers are showed')\n    def step_impl(context):\n        raise NotImplementedError(u'STEP: Then the feature registers are showed')\n```\n\n##### 1.3. Create a Step\n\nCopied the snippets, create a new Python file into the '/features/steps' folder with the same or similar name of your `.feature`.\nTry to increment the file name ending with `*_steps.py` and place them in the `steps` folder only (to be read by Behave framework).\n\n```\n    features\n    └─── steps\n        |   demo_mysql_db_schema_steps.py\n        │   demo_mysql_tables_steps.py\n            ...\n```\n\nInto this new Python file, you should import `behave` library to take the advantages of Behave to your [Step Implementation](https://behave.readthedocs.io/en/latest/tutorial.html#python-step-implementations).\n\n```python\nfrom behave import *\n\n    # Paste your snippets for steps...\n```\n\nThen, just paste your snippets from clipboard into the `features/steps/demo_mysql_tables_steps.py` and change the `step_impl` names, for example. Then you are able to create the queries and pass all validations expected.\n\n```python\nfrom behave import *\nfrom features.queries.demo_sql.demo_mysql import ScriptPyonSchema as SqlSample\n\n@given(\"that the tables tb_test_resource, tb_test_type, tb_category and tb_feature are created\")\ndef step_given_that_the_tables_test_resource_test_type_category_and_feature_are_created(context):\n    SqlSample.query_create_tables(context.db_connection)\n\n\n@when(\"user populates these tables\")\ndef step_when_user_populates_these_tables(context):\n    SqlSample.query_populate(context.db_connection)\n\n\n@then(\"the user can select with a join between tb_feature, tb_test_type and tb_category tables\")\ndef step_then_the_user_can_select_with_join_between_tables_feature_test_type_and_category(context):\n    expected_rows = [\n        (\"API TEST\", \"Automated\", \"The planets from Star Wars Universe API\"),\n        (\"MOBILE TEST\", \"Automated\", \"The user can search something on Google Search\"),\n        (\"WEB TEST\", \"Automated\", \"The user can add a product to cart\"),\n        (\"WEB TEST\", \"Manual\", \"The app can be created by the user after he chooses the mode\"),\n    ]\n    SqlSample.query_select_feature_categories(context.db_connection, expected_rows)\n\n\n@then(\"the feature registers are showed\")\ndef step_then_the_feature_registers_are_showed(context):\n    expected_rows = 4\n    SqlSample.query_select_count_feature_categories(context.db_connection, expected_rows)\n```\n\n##### 1.4. Query Objects\n\nNow, you have a basic structure using Behave, but the Steps have no SQL to cover the commands expected in the descriptions. To make this possible, all the queries need to be explicitly declared containing SQL that are recognised by a respective RDBMS settled into Pyon project. So, try to implement reusable method into `features/queries` folder, like this sample:\n\n```\n    features\n    └─── queries\n        └─── demo_sql\n            │   demo_mysql.py\n                ...\n   \n```\n\nAt the 'features/queries' folder, create a new page object class that inherits the BaseSQL module (`from factory.database.sql_wrapper import BaseSQL`):\n\n```python\nimport time\nfrom factory.database.sql_wrapper import BaseSQL as Db\n\n\nclass ScriptPyonSchema(Db):\n    # ... implement the query methods here\n```\n\nEverything you need is create a methods and call the `Db.execute_sql(any_sql, json_connection, validate_content=None):`. The named arg `validate_content` is optional. On the other hand, the `any_sql` and `json_connection` are required.\n\n```python\n    @staticmethod\n    def query_select_feature_categories(db_connection, expected=None):\n        select_tb_feature__categories = \"\"\"\n            SELECT tt.type_name, tc.category_name, tf.test_description\n            FROM tb_feature tf \n            JOIN tb_test_type tt \n            ON tf.id_test_type = tt.id_test_type\n            JOIN tb_category tc\n            ON tf.id_test_category = tc.id_test_category\n            ORDER BY tt.type_name ASC;\n        \"\"\"\n        Db.execute_sql(select_tb_feature__categories, db_connection, expected)\n```\n\n###### 1.4.a) Assertions\n\nTo create validation methods for the steps when is necessary (mainly in the `@Then` step), the Assert methods are already built into the `BaseSQL` class. So, you'll just need to send the expected values for validation distinguishing if they are a list of tuples / registers to be returned or a single number (that represents the number of rows returned):\n\n```python\n    my_list_of_registers_expected = [\n            (\"API TEST\", \"Automated\", \"The planets from Star Wars Universe API\"),\n            (\"MOBILE TEST\", \"Automated\", \"The user can search something on Google Search\"),\n            (\"WEB TEST\", \"Automated\", \"The user can add a product to cart\"),\n            (\"WEB TEST\", \"Manual\", \"The app can be created by the user after he chooses the mode\"),\n        ]\n```\n\n```python\n    my_total_registers_expected = 10\n```\n\n## SELECT THE SCENARIOS TO BE EXECUTED\n\nRegardless if you are using the debug mode to execute tests or triggering them via CI server, you should set the tags accordingly declaring with or without `@`, but separating them by comma and without spaces. See these examples:\n\nYou can combine TAGS like these examples:\n\n- e.g. 1) ISOLATED SCENARIO: `demo-mysql-cleanup`\n\n- e.g. 2) COMBINING SCENARIOS: `demo-mysql-tables,demo-mysql-cleanup`\n\n- e.g. 3) CALLING ENTIRE FEATURES: `demo-mysql`\n\nIf you leave the parameter related to tags empty, all the features from the environment selected will be executed regardless if is set by properties or by command line.\n\n## Set the credentials to store and access sensitive data\n\nAs you know, some passwords and personal data cannot be exposed or accessed easily. Those datas should be encrypted and decrypted by a reliable and safer mechanism. For PYON, that mechanism is by managing the credentials through Jenkins. There are many ways to set credentials, but as the PYON consumes lots of different sensitive variables, then the strategy chosen is access a secret file uploaded and encrypted in 'Jenkins \u003e Credentials \u003e System \u003e Global credentials' (you need to have permission to this page in Jenkins).\n\n```groovy\n    withCredentials([file(credentialsId: 'pyon-secret-data', variable: 'PYON_SECRET_FILE')]) {\n        sh \"\"\"\n            rm -f $WORKSPACE/pyon_secret_data.properties\n            cp $PYON_SECRET_FILE $WORKSPACE\n        \"\"\"\n```\n\nThe variable `PYON_SECRET_FILE` is encrypted and the file is copied into the current building workspace in execution, containing the following variables:\n\n```properties\n    [app-auth]\n    PYON_SECRET_APP_USER_NAME = ...\n    PYON_SECRET_APP_PASS = ...\n\n    [app-configcat]\n    PYON_SECRET_CONFIGCAT_SDK_KEY_FF_DEV = ...\n    PYON_SECRET_CONFIGCAT_SDK_KEY_FF_STAGING = ...\n    PYON_SECRET_CONFIGCAT_SDK_KEY_FF_PRODUCTION = ...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhudsonssrosa%2Fpyon-sql-tests","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhudsonssrosa%2Fpyon-sql-tests","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhudsonssrosa%2Fpyon-sql-tests/lists"}