diff options
author | Alexander Kabui | 2021-03-31 22:31:01 +0300 |
---|---|---|
committer | Alexander Kabui | 2021-03-31 22:31:01 +0300 |
commit | f065ea860f8001942bbf7c61eb49e515d358d2eb (patch) | |
tree | 24d4882482e7bf605547e2d934a6835bb11fe4b8 | |
parent | f6c6851504f14a1a163b6eeb5e3653a5ec3f5ceb (diff) | |
download | genenetwork3-f065ea860f8001942bbf7c61eb49e515d358d2eb.tar.gz |
add temp_db setup and integration tests
-rw-r--r-- | gn3/api/datasets.py | 28 | ||||
-rw-r--r-- | gn3/experimental_db.py | 11 | ||||
-rw-r--r-- | tests/integration/test_datasets.py | 28 |
3 files changed, 67 insertions, 0 deletions
diff --git a/gn3/api/datasets.py b/gn3/api/datasets.py new file mode 100644 index 0000000..874c76a --- /dev/null +++ b/gn3/api/datasets.py @@ -0,0 +1,28 @@ +"""this module contains code for creating datasets""" +from flask import Blueprint +from flask import jsonify + +from gn3.computations.datasets import create_dataset + + +dataset = Blueprint("dataset", __name__) + + +@dataset.route("/") +def dataset_home(): + """initial test endpont for dataset""" + return jsonify({"results": "ok"}) + + +@dataset.route("/create/<dataset_name>/") +@dataset.route("/create/<dataset_name>/<dataset_type>") +def create_dataset_api(dataset_name, dataset_type=None): + """Test api/create/dataset/<dataset_name>/<dataset_type>""" + + new_dataset = create_dataset( + dataset_type=dataset_type, dataset_name=dataset_name) + + results = { + "dataset":new_dataset + } + return jsonify(results) diff --git a/gn3/experimental_db.py b/gn3/experimental_db.py new file mode 100644 index 0000000..c928265 --- /dev/null +++ b/gn3/experimental_db.py @@ -0,0 +1,11 @@ +"""this function contains experimental db staff""" +from typing import Tuple +import MySQLdb as mdb # type: ignore + + +def database_connector()->Tuple: + """function to create db connector""" + conn = mdb.connect("local", "kabui", "1234", "db_webqtl") + cursor = conn.cursor() + + return (conn, cursor) diff --git a/tests/integration/test_datasets.py b/tests/integration/test_datasets.py new file mode 100644 index 0000000..255d998 --- /dev/null +++ b/tests/integration/test_datasets.py @@ -0,0 +1,28 @@ +"""this module contains integration tests for datasets""" +from unittest import TestCase +from unittest import mock + +from collections import namedtuple +from gn3.app import create_app + + +class DatasetIntegrationTests(TestCase): + """class contains integration tests for datasets""" + + def setUp(self): + self.app = create_app().test_client() + + @mock.patch("gn3.api.datasets.create_dataset") + def test_create_dataset(self, mock_dataset): + """test for creating dataset object""" + mock_dataset_creator = namedtuple( + 'ProbeSet', ["dataset_name", "dataset_type"]) + new_dataset = mock_dataset_creator("HC_M2_0606_P", "ProbeSet") + mock_dataset.return_value = new_dataset + response = self.app.get( + "/api/dataset/create/HC_M2_0606_P/", follow_redirects=True) + mock_dataset.assert_called_once_with( + dataset_type=None, dataset_name="HC_M2_0606_P") + results = response.get_json()["dataset"] + self.assertEqual(results[1], "ProbeSet") + self.assertEqual(response.status_code, 200) |