dbtext


Namedbtext JSON
Version 2.3.1 PyPI version JSON
download
home_pageNone
SummaryDatabase to text utility for approval testing
upload_time2024-06-17 09:25:37
maintainerNone
docs_urlNone
authorJohan Andersson
requires_python>=3.7
licenseGNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # dbtext
Utility for storing a database as a directory of plain text files, and reading from those text files.
Currently has implementations for MS SQL server, MySQL, Sqlite3 and MongoDB.
The first 3 of these require "pyodbc" to be installed, and MongoDB requires "pymongo" to be installed.

## installation
```
pip install dbtext pyodbc (for MSSQL, MySQL, Sqlite3)
pip install dbtext pymongo (for MongoDB)
```

## usage

First, dump your test database to this format. For example, with MSSQL:

```python
    from dbtext import MSSQL_DBText
    with pyodbc.connect(connStr) as conn:
        with dbtext.MSSQL_DBText("dump", conn) as testdb: # the name "dump" doesn't matter, just a temporary name
            testdb.write_data("db_tables", use_master_connection=True) # creates a directory called db_tables
    
```
For MongoDB:
```python
    from dbtext import Mongo_DBText

    dbClient = Mongo_DBText()
    dbClient.create(host=connStr) # as in pymongo, "host" can be a full connection string
    dbClient.dump_data_directory("mongodata") # creates a directory called mongodata
```

Then you create tests, probably with TextTest, that use this directory as test data ("copy_test_path")

A test harness script might do something like for MSSQL:

```python
    import dbtext, os
    testdbname = "ttdb_" + str(os.getpid()) # some temporary name not to clash with other tests
    with dbtext.MSSQL_DBText(testdbname) as db: # the name you use here will be used for the directory name in the current working directory
        # You need a script 'create_empty.sql' that sets up the schema but no data
        # db.create will set up the schema and read the test data from a directory here called "db_tables"
        db.create(sqlfile="create_empty.sql")
         
        # Then it should take the testdbname and configure your system to start a server against the new database
        # ...
        do_some_setup() 

        # tell it the test is starting for real now. Only necessary if the database is changed by setup via the system
        db.update_start_rv() 

        # do whatever it is the test does

        db.dumptables("myext", "*") # dump changes in all the tables you're interested in. "myext" is whatever extension you want to use, probably the TextTest one 
```

For MongoDB, two classes are provided, Mongo_DBText and LocalMongo_DBText.
For test usage, you generally want to use LocalMongo_DBText, which works like the MSSQL version above,
i.e. it creates you a new MongoDB server running on any free port locally and populates it with the data in question.
Mongo_DBText is used for connecting to already running instances, for example if you need to start it via Docker.

```python
    import dbtext
    with dbtext.LocalMongo_DBText(data_dirname=testdbname) as db: # the name you use here will be used for the directory name in the current working directory
        db.create()
        if not db.setup_succeeded(): # could not start MongoDB, for example
            return False

        testConnStr = "mongodb://localhost:" + str(self.db.port) # provide to your system in some way

        # do whatever it is the test does
        # ...
        
        db.dump_changes("myext") # dump changes in all the tables you're interested in. "myext" is whatever extension you want to use, probably the TextTest one 
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "dbtext",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": null,
    "author": "Johan Andersson",
    "author_email": "Geoff Bache <geoff.bache@pobox.com>",
    "download_url": "https://files.pythonhosted.org/packages/d9/4a/9be5a97d49e61c5cf8885fddd289fafdc052bfe0ac63a1d3c2348584b572/dbtext-2.3.1.tar.gz",
    "platform": null,
    "description": "# dbtext\r\nUtility for storing a database as a directory of plain text files, and reading from those text files.\r\nCurrently has implementations for MS SQL server, MySQL, Sqlite3 and MongoDB.\r\nThe first 3 of these require \"pyodbc\" to be installed, and MongoDB requires \"pymongo\" to be installed.\r\n\r\n## installation\r\n```\r\npip install dbtext pyodbc (for MSSQL, MySQL, Sqlite3)\r\npip install dbtext pymongo (for MongoDB)\r\n```\r\n\r\n## usage\r\n\r\nFirst, dump your test database to this format. For example, with MSSQL:\r\n\r\n```python\r\n    from dbtext import MSSQL_DBText\r\n    with pyodbc.connect(connStr) as conn:\r\n        with dbtext.MSSQL_DBText(\"dump\", conn) as testdb: # the name \"dump\" doesn't matter, just a temporary name\r\n            testdb.write_data(\"db_tables\", use_master_connection=True) # creates a directory called db_tables\r\n    \r\n```\r\nFor MongoDB:\r\n```python\r\n    from dbtext import Mongo_DBText\r\n\r\n    dbClient = Mongo_DBText()\r\n    dbClient.create(host=connStr) # as in pymongo, \"host\" can be a full connection string\r\n    dbClient.dump_data_directory(\"mongodata\") # creates a directory called mongodata\r\n```\r\n\r\nThen you create tests, probably with TextTest, that use this directory as test data (\"copy_test_path\")\r\n\r\nA test harness script might do something like for MSSQL:\r\n\r\n```python\r\n    import dbtext, os\r\n    testdbname = \"ttdb_\" + str(os.getpid()) # some temporary name not to clash with other tests\r\n    with dbtext.MSSQL_DBText(testdbname) as db: # the name you use here will be used for the directory name in the current working directory\r\n        # You need a script 'create_empty.sql' that sets up the schema but no data\r\n        # db.create will set up the schema and read the test data from a directory here called \"db_tables\"\r\n        db.create(sqlfile=\"create_empty.sql\")\r\n         \r\n        # Then it should take the testdbname and configure your system to start a server against the new database\r\n        # ...\r\n        do_some_setup() \r\n\r\n        # tell it the test is starting for real now. Only necessary if the database is changed by setup via the system\r\n        db.update_start_rv() \r\n\r\n        # do whatever it is the test does\r\n\r\n        db.dumptables(\"myext\", \"*\") # dump changes in all the tables you're interested in. \"myext\" is whatever extension you want to use, probably the TextTest one \r\n```\r\n\r\nFor MongoDB, two classes are provided, Mongo_DBText and LocalMongo_DBText.\r\nFor test usage, you generally want to use LocalMongo_DBText, which works like the MSSQL version above,\r\ni.e. it creates you a new MongoDB server running on any free port locally and populates it with the data in question.\r\nMongo_DBText is used for connecting to already running instances, for example if you need to start it via Docker.\r\n\r\n```python\r\n    import dbtext\r\n    with dbtext.LocalMongo_DBText(data_dirname=testdbname) as db: # the name you use here will be used for the directory name in the current working directory\r\n        db.create()\r\n        if not db.setup_succeeded(): # could not start MongoDB, for example\r\n            return False\r\n\r\n        testConnStr = \"mongodb://localhost:\" + str(self.db.port) # provide to your system in some way\r\n\r\n        # do whatever it is the test does\r\n        # ...\r\n        \r\n        db.dump_changes(\"myext\") # dump changes in all the tables you're interested in. \"myext\" is whatever extension you want to use, probably the TextTest one \r\n```\r\n",
    "bugtrack_url": null,
    "license": "GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007  Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.   This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.  0. Additional Definitions.  As used herein, \"this License\" refers to version 3 of the GNU Lesser General Public License, and the \"GNU GPL\" refers to version 3 of the GNU General Public License.  \"The Library\" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.  An \"Application\" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.  A \"Combined Work\" is a work produced by combining or linking an Application with the Library.  The particular version of the Library with which the Combined Work was made is also called the \"Linked Version\".  The \"Minimal Corresponding Source\" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.  The \"Corresponding Application Code\" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.  1. Exception to Section 3 of the GNU GPL.  You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.  2. Conveying Modified Versions.  If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:  a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or  b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.  3. Object Code Incorporating Material from Library Header Files.  The object code form of an Application may incorporate material from a header file that is part of the Library.  You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:  a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.  b) Accompany the object code with a copy of the GNU GPL and this license document.  4. Combined Works.  You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:  a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.  b) Accompany the Combined Work with a copy of the GNU GPL and this license document.  c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.  d) Do one of the following:  0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.  1) Use a suitable shared library mechanism for linking with the Library.  A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.  e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)  5. Combined Libraries.  You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:  a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.  b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.  6. Revised Versions of the GNU Lesser General Public License.  The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.  Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License \"or any later version\" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.  If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. ",
    "summary": "Database to text utility for approval testing",
    "version": "2.3.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/texttest/dbtext/issues",
        "Homepage": "https://github.com/texttest/dbtext"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1c2a40f8259a2cce7324896e4df6a0c7465ef8914da99fd7ac4c2418c63a87dd",
                "md5": "3c0c78d135640bf4685bb4c878fbeeef",
                "sha256": "5d09566ea2464687d3a8567e916dc3ee49dc4dd2d63a36f4c5c3f80f9fa219b2"
            },
            "downloads": -1,
            "filename": "dbtext-2.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3c0c78d135640bf4685bb4c878fbeeef",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 27351,
            "upload_time": "2024-06-17T09:25:36",
            "upload_time_iso_8601": "2024-06-17T09:25:36.153592Z",
            "url": "https://files.pythonhosted.org/packages/1c/2a/40f8259a2cce7324896e4df6a0c7465ef8914da99fd7ac4c2418c63a87dd/dbtext-2.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d94a9be5a97d49e61c5cf8885fddd289fafdc052bfe0ac63a1d3c2348584b572",
                "md5": "1c767846fa4b973940c663d270dae4ef",
                "sha256": "bb5115de2825c4b987f689f2c9db0b148266d1c983a22f3e16b43f2ab76d7545"
            },
            "downloads": -1,
            "filename": "dbtext-2.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "1c767846fa4b973940c663d270dae4ef",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 25697,
            "upload_time": "2024-06-17T09:25:37",
            "upload_time_iso_8601": "2024-06-17T09:25:37.824528Z",
            "url": "https://files.pythonhosted.org/packages/d9/4a/9be5a97d49e61c5cf8885fddd289fafdc052bfe0ac63a1d3c2348584b572/dbtext-2.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-17 09:25:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "texttest",
    "github_project": "dbtext",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "dbtext"
}
        
Elapsed time: 0.58708s