{"id":15449829,"url":"https://github.com/cortze/unit-db-test","last_synced_at":"2026-05-03T04:38:48.588Z","repository":{"id":195842394,"uuid":"693651099","full_name":"cortze/unit-db-test","owner":"cortze","description":"Unittest wrapper focused on making DB integrity tests","archived":false,"fork":false,"pushed_at":"2024-02-07T13:21:53.000Z","size":53,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-06T22:04:46.701Z","etag":null,"topics":["gtihub-actions","postgresql","python","python-ci","resilience","tooling","unnitest"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cortze.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-09-19T12:54:12.000Z","updated_at":"2023-12-01T13:45:09.000Z","dependencies_parsed_at":"2023-09-22T18:29:31.738Z","dependency_job_id":null,"html_url":"https://github.com/cortze/unit-db-test","commit_stats":null,"previous_names":["cortze/dbtest"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cortze%2Funit-db-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cortze%2Funit-db-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cortze%2Funit-db-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cortze%2Funit-db-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cortze","download_url":"https://codeload.github.com/cortze/unit-db-test/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245999619,"owners_count":20707572,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["gtihub-actions","postgresql","python","python-ci","resilience","tooling","unnitest"],"created_at":"2024-10-01T21:02:05.107Z","updated_at":"2026-05-03T04:38:43.562Z","avatar_url":"https://github.com/cortze.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# unit-db-test \u0026middot; [![PyPI Release](https://img.shields.io/pypi/v/unit-db-test.svg)](https://pypi.org/project/unit-db-test/) ![](https://github.com/cortze/dbtest/actions/workflows/module_tests.yml/badge.svg) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\nIs your tool hard to debug? Would it be easier to check it at the DB level? \n\nThis module is for you! **unit-db-test** is a Python tool for conducting database tests. It is a unittest wrapper focussed on making DB integrity tests.\nAs it is an extension over the `unittest.TestCase` it is easy to configure and easy to integrate with GitHub actions.\n\n\n\n## Features\n\n- It has an integrated connection to a Postgres Database: easily configurable using the `.env` file.\n- Fully compatible with `SQLAlchemy` and `Pandas`: get a `pandas.Dataframe` out of any SQL query you want to test.\n- Unit-test oriented: Check if the `pandas.Dataframe` output matches the expected values, or catch it when the test fails.\n\n## Installation\n\nYou can install **dbtests** using pip:\n\n```bash\npip install unit-db-test\n```\n\n## Usage\nHere's how you can use dbtests in your projects:\n\n1. Create a `./test` folder as with any other kind of `unittests` (it is in fact compatible with other `unittests` just make there is a connection to a Postgres DB), and create a `test-file`.\n```shell\nmy-tool/\n├── my-tool/\n│   ├── __init__.py\n│   ├── script_1.py\n└── tests/\n    ├── __init__.py\n    └── test_script_1.py\n```\n\n2. Once the script is created, we need to import the dependencies:\n```python\n# test_script_1.py\n# Dependencies\nimport unittest\nfrom unit_db_test.testcase import DBintegrityTest\n```\n\n3. Create a `DBintegrityTest` as if it was a `unittest.TestCase`. It is important to define the path to the `.env` that keeps the Postgres DB credentials:\n\n```python\nclass TestDBTestModule(DBintegrityTest):\n    db_config_file = '.postgresql.env'\n```\n\n4. Create as many `test` functions as pleased:\n```python\n    def test_not_null_items_in_column(self):\n        # the query that SHOULDN'T create an assertion\n        sql_query = \"\"\"\n        SELECT \n            id\n        FROM test_table;        \n        \"\"\"\n        df = self.db.get_df_from_sql_query(sql_query)\n        self.assertNotNullItemsInColumn(df, 'id')\n\nif __name__ == '__main__':\n    unittest.main()\n```\n\n5. Run it as you please:\n```shell\npython -m unittest tests/test_script_1.py\n```\n\nThe tests can be run locally or integrated with Github Actions. \nFor more examples, please check:\n- [Github Action example](https://github.com/cortze/unit-db-test/blob/main/.github/workflows/module_tests.yml)\n- [Test example](https://github.com/cortze/unit-db-test/blob/main/tests/test_module.py)\n\n## Custom Assert \nThe **dbtest** module contemplates new assert functions over `pandas.Dataframe` objects. \nThis way the result of a simple query can be easily checked with the standard `unittest` nomenclature.\n\nThe list of current Asserts is the following:\n- assertNotNullItemsInColumn(self, df, column)\n- assertCustomNullItemsInColumn(self, df, column, target)\n- assertNoRows(self, df)\n- assertNRows(self, df, target_rows)\n\nThere will be more to come (under demand most probably). Feel free to suggest new ones though!\n\n\n## Contributing\nIf you want to contribute to this project, please follow these guidelines:\n\n- Fork the repository\n- Create a new branch\n- Make your changes\n- Submit a pull request\n- Bugs and Issues\n\nIf you encounter any bugs or issues, please report them here.\n\n## Contact\nAuthor: Mikel Cortes ([@cortze](https://github.com/cortze))\n\nFeel free to reach out if you have any questions or suggestions!\n\n## License\nThis project is licensed under the MIT License - see the [LICENSE](https://github.com/cortze/unit-db-test/blob/main/LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcortze%2Funit-db-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcortze%2Funit-db-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcortze%2Funit-db-test/lists"}