diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6548863..825e1e4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,6 +7,50 @@ on: - main - dev jobs: + testing: + runs-on: ubuntu-latest + services: + redis: + image: redis + ports: + - 6379:6379 + mariadb: + image: mariadb:10.11 + env: + MYSQL_ROOT_PASSWORD: password + MYSQL_DATABASE: mpx_test_04 + MYSQL_USER: test_user + MYSQL_PASSWORD: test_password + ports: + - 3306:3306 + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: '3.10' + - name: Install dependencies + run: | + sudo apt install libmariadb3 libmariadb-dev + pip install poetry + + - name: Poetry install env. + run: poetry install + - name: Load database + run: | + mysql --protocol=tcp -h localhost --user=root --password=password -e "CREATE DATABASE IF NOT EXISTS mpx_test_04;" + mysql --protocol=tcp -h localhost --user=root --password=password -e "GRANT ALL PRIVILEGES ON mpx_test_04.* TO 'test_user'@'%' IDENTIFIED BY 'test_password';" + mysql --protocol=tcp -h localhost --user=root --password=password mpx_test_04 < tests/sql_dumps/mpx_test_04.sql + mysql --protocol=tcp -h localhost --user=root --password=password -e "use mpx_test_04; SHOW TABLES;" + - name: Run pytest + env: + DB_URL: "https://test_user:test_password@127.0.0.1:3306/mpx_test_04" + REDIS_URL: "redis://127.0.0.1:6379" + REDIS_DB_BROKER: 1 + REDIS_DB_BACKEND: 1 + DEBUG: True + LOG_LEVEL: "DEBUG" + run: poetry run pytest -rfeP -x tests/ format-checker: runs-on: ubuntu-latest steps: @@ -15,6 +59,7 @@ jobs: uses: actions/setup-python@v3 with: python-version: '3.10' - - run: pip install flake8 poetry + - name: Install dependencies + run: pip install flake8 poetry - name: Run flake8 - Code style check run: poetry run flake8 . --config=.flake8 -v diff --git a/poetry.lock b/poetry.lock index 6f679c1..bd7a717 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1026,23 +1026,23 @@ zookeeper = ["kazoo (>=1.3.1)"] [[package]] name = "mariadb" -version = "1.1.5.post3" +version = "1.1.6" description = "Python MariaDB extension" category = "main" optional = false python-versions = ">=3.7" files = [ - {file = "mariadb-1.1.5.post3-cp310-cp310-win32.whl", hash = "sha256:85a76359a746aac09e87f666d2bc22e33c4bfc6324a4c13d2593c2a91a184f80"}, - {file = "mariadb-1.1.5.post3-cp310-cp310-win_amd64.whl", hash = "sha256:ae44fd1aec97ff873b25420f48220da4e5a688dbd327ec145acad41e8ba8fea2"}, - {file = "mariadb-1.1.5.post3-cp311-cp311-win32.whl", hash = "sha256:4cf132556c3be86f235fa4849ccf36a09ecc34c277d894cfd7fafd8b2b370446"}, - {file = "mariadb-1.1.5.post3-cp311-cp311-win_amd64.whl", hash = "sha256:60e7c1bc55b297accb1d423e922a1131dcc5c03ba0035ea961889c72541d3662"}, - {file = "mariadb-1.1.5.post3-cp37-cp37m-win32.whl", hash = "sha256:ea6890ada88efd6ae8a7ca3152753c2853fcd65105e03ecbc79e5104f1ef4a97"}, - {file = "mariadb-1.1.5.post3-cp37-cp37m-win_amd64.whl", hash = "sha256:78b597c598c4bec0e0e44885fd06545dd80ca2ed445e77d72a75342658afa290"}, - {file = "mariadb-1.1.5.post3-cp38-cp38-win32.whl", hash = "sha256:e78d05532197728e4cf9d1a28cdf86bf8e9e3f5eef52c9321800a2c7644b9781"}, - {file = "mariadb-1.1.5.post3-cp38-cp38-win_amd64.whl", hash = "sha256:a7bc81f750128d069c850153f582d512f6a67b42af44ab668ce35ccf069be0e6"}, - {file = "mariadb-1.1.5.post3-cp39-cp39-win32.whl", hash = "sha256:fa5f0f42bfb87013f179f9c3bc3deefa13398cae1e027a869b367db9dc8dd285"}, - {file = "mariadb-1.1.5.post3-cp39-cp39-win_amd64.whl", hash = "sha256:0f805d6e5406318438df4923cc01bea80cfdddeee5f53dd22057b94f75391545"}, - {file = "mariadb-1.1.5.post3.tar.gz", hash = "sha256:f9336dd4cb3207e621933bb5221f33fac0d7184db64dc44c70531430f4ecdcee"}, + {file = "mariadb-1.1.6-cp310-cp310-win32.whl", hash = "sha256:b8db1d71c914de000953b8b7d3554838593db97a144075ea52bc439b85d1ec64"}, + {file = "mariadb-1.1.6-cp310-cp310-win_amd64.whl", hash = "sha256:876b40420fb0d897c928e8f486deb419631464972cb19b9e0ca0206a57944bef"}, + {file = "mariadb-1.1.6-cp311-cp311-win32.whl", hash = "sha256:f18f26b67fe4bbd57212cd42593b1a43206f758353cfe400983ee23542bed2c5"}, + {file = "mariadb-1.1.6-cp311-cp311-win_amd64.whl", hash = "sha256:95e2bc091b05ab16a2cf0083a927670bc99b813dfd35cec989e6f2f6c7c60a27"}, + {file = "mariadb-1.1.6-cp37-cp37m-win32.whl", hash = "sha256:979005321961b62a0a84bfb8046784a473ce390dff8c97fe362ac21f1d3e6b26"}, + {file = "mariadb-1.1.6-cp37-cp37m-win_amd64.whl", hash = "sha256:ffd7bc78f3b408f2074d804f3834ef8343e32df935549623c8e67938ac4be146"}, + {file = "mariadb-1.1.6-cp38-cp38-win32.whl", hash = "sha256:9928ffc43a582d0c44f25d2e7096cf97d049d02a76fcd24e67d4527db13b5af0"}, + {file = "mariadb-1.1.6-cp38-cp38-win_amd64.whl", hash = "sha256:bc8195c1dd5510730126b7d76a69bab1450dcb7690edffafc891a7f1e848a33e"}, + {file = "mariadb-1.1.6-cp39-cp39-win32.whl", hash = "sha256:cb4af75855e6d33824472e692220b67064b43df6f9b441c385463cb851509d78"}, + {file = "mariadb-1.1.6-cp39-cp39-win_amd64.whl", hash = "sha256:34d73bcc7d159c86b2c0d7041880f609eaf32d876c3d06534a677b05d99c905d"}, + {file = "mariadb-1.1.6.tar.gz", hash = "sha256:af17a7eb29d24e9ac00f323909c4ba0c47f643ee4b7b890a158cb855ec866454"}, ] [package.dependencies] @@ -2295,4 +2295,4 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools" [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.11" -content-hash = "faccfabd30cae87a97a184fab5d91e369210eacdc60a3f3ec18a9554e79363be" +content-hash = "cc32554c7e9f7e0a3e81d93a3675e9f9926217bfd0d93cbc4133de3a54acc86d" diff --git a/pyproject.toml b/pyproject.toml index 93a849d..9cb8f7b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ mpire = "2.6.0" pandas = "~1.4.0" requests = "^2.28.0" python-dotenv = "^0.21.0" -mariadb = "^1.1.4" +mariadb = "^1.1.6" psutil = "^5.9.3" dash-bootstrap-components = "^1.2.1" dash = {extras = ["celery"], version = "^2.7.1"} diff --git a/tests/sql_dumps/mpx_test_04.sql b/tests/sql_dumps/mpx_test_04.sql index d140ee3..94989ce 100644 --- a/tests/sql_dumps/mpx_test_04.sql +++ b/tests/sql_dumps/mpx_test_04.sql @@ -19,6 +19,8 @@ -- Table structure for table `alignment` -- +CREATE DATABASE IF NOT EXISTS mpx_test_04; + DROP TABLE IF EXISTS `alignment`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!50503 SET character_set_client = utf8mb4 */; @@ -464,6 +466,47 @@ CREATE TABLE `variantView` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- Function Table +CREATE FUNCTION IF NOT EXISTS `mpx_test_04`.DB_VERSION() RETURNS INTEGER RETURN 1; +-- VIEW Table +DROP VIEW IF EXISTS `mpx_test_04`.`referenceView`; +CREATE VIEW `mpx_test_04`.`referenceView` AS +SELECT + `reference`.id AS "reference.id", + `reference`.accession AS "reference.accession", + `reference`.`description` AS "reference.description", + `reference`.organism AS "reference.organism", + `reference`.standard AS "reference.standard", + `reference`.translation_id AS "translation.id", + molecule.id AS "molecule.id", + molecule.`type` AS "molecule.type", + molecule.accession AS "molecule.accession", + molecule.symbol AS "molecule.symbol", + molecule.`description` AS "molecule.description", + molecule.`length` AS "molecule.length", + molecule.segment AS "molecule.segment", + molecule.standard AS "molecule.standard", + element.id AS "element.id", + element.type AS "element.type", + element.accession AS "element.accession", + element.symbol AS "element.symbol", + element.description AS "element.description", + element.start AS "element.start", + element.`end` AS "element.end", + element.strand AS "element.strand", + element.sequence AS "element.sequence", + elempart.`start` AS "elempart.start", + elempart.`end` AS "elempart.end", + elempart.strand AS "elempart.strand", + elempart.segment AS "elempart.segment" +FROM + `mpx_test_04`.reference +LEFT JOIN `mpx_test_04`.molecule ON reference.id = molecule.reference_id +LEFT JOIN `mpx_test_04`.element ON molecule.id = element.molecule_id +LEFT JOIN `mpx_test_04`.elempart ON element.id = elempart.element_id; + + + -- -- Dumping data for table `variantView` -- diff --git a/tests/test_date_slider.py b/tests/test_date_slider.py index e13b25d..65e5769 100644 --- a/tests/test_date_slider.py +++ b/tests/test_date_slider.py @@ -7,6 +7,8 @@ from pages.utils_worldMap_explorer import DateSlider DB_DUMP_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "sql_dumps") +# os.environ['TZ'] = 'Europe/Germany' +# os.system('tzutil /s "Central Standard Time"') class TestDateSlider(unittest.TestCase): @@ -26,14 +28,29 @@ def test_dates(self): assert len(self.date_slider.date_list) == 96 def test_unix_time_millis(self): - assert 1670022000 == DateSlider.unix_time_millis(date(2022, 12, 3)) + # HACK: the problem is if you're using Unix timestamps in your pytest tests + # and the timezone of the Github Actions or any testing instance + # environment is different from the timezone used + # to generate the Unix timestamps, you may get unexpected results. + # , that is why we use list to capture either 2022-12-2 or 2022-12-3. + assert DateSlider.unix_time_millis(date(2022, 12, 3)) in [ + 1670022000, + 1670025600, + ] + # assert 1670022000 == DateSlider.unix_time_millis(date(2022, 12, 3)) def test_unix_to_date(self): - assert DateSlider.unix_to_date(1669935600) == date(2022, 12, 2) - assert DateSlider.unix_to_date(1672527600) == date(2023, 1, 1) + assert DateSlider.unix_to_date(1669939200) == date(2022, 12, 2) + assert DateSlider.unix_to_date(1672531200) == date(2023, 1, 1) + + # assert DateSlider.unix_to_date(1669935600) == date(2022, 12, 2) + # assert DateSlider.unix_to_date(1672527600) == date(2023, 1, 1) def test_get_all_dates_in_interval(self): - dates = [1669935600, 1672527600] + dates = [1671840000, 1672531200] + + # dates = [1671836400, 1672527600] start from date(2022, 12, 24) + # dates = [1669935600, 1672527600] default interval = 9 date_list = self.date_slider.get_all_dates_in_interval(dates, interval) correct_dates = [ diff --git a/tests/test_db_preprocessing.py b/tests/test_db_preprocessing.py index 215157d..45ed02f 100644 --- a/tests/test_db_preprocessing.py +++ b/tests/test_db_preprocessing.py @@ -62,7 +62,7 @@ def test_world_df(self): } for reference in [2, 4]: for completeness in ["complete", "partial"]: - print((world_dfs[completeness][reference].head())) + # print((world_dfs[completeness][reference].head())) assert ( list(world_dfs[completeness][reference].columns) == DbProperties.world_df_columns