Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unit test for download module #35

Merged
merged 24 commits into from Mar 29, 2023
Merged

unit test for download module #35

merged 24 commits into from Mar 29, 2023

Conversation

To-Ki-O
Copy link
Collaborator

@To-Ki-O To-Ki-O commented Mar 27, 2023

フィードバック機能のダウンロードモジュールに関する単体テストを作成しました。

よろしくお願いします。

@ryo-ma
Copy link
Contributor

ryo-ma commented Mar 27, 2023

rebaseコマンド叩きましたか? Files Changedが見えづらいので、最新のmainからrebasdを叩いてください

@To-Ki-O
Copy link
Collaborator Author

To-Ki-O commented Mar 27, 2023

失礼いたしました。
上手くリベースが出来ておりませんでした。

リベースいたしましたので、ご確認よろしくお願いします。

@ryo-ma
Copy link
Contributor

ryo-ma commented Mar 27, 2023

@To-Ki-O すいませんが、あと最終的な実行手順ももらえますか?

@To-Ki-O
Copy link
Collaborator Author

To-Ki-O commented Mar 27, 2023

承知しました。

  1. 通常通りの手順でDockerコンテナの立ち上げ、ckanext-feedbackのインストールを行う
  2. コンテナ内に入る
    docker exec -it --user root ckan /bin/bash
  3. その他の必要なものをインストールする
    pip install -r /usr/lib/ckan/venv/src/ckan/dev-requirements.txt
    pip install pytest-ckan
  4. テスト用DBを作成する
    createdb ckan_test -O ckan -E utf-8 -h db -U ckan
  5. ディレクトリを移動
    cd /usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/tests
  6. テストを実行
    CKAN_SQLALCHEMY_URL= CKAN_DATASTORE_READ_URL= CKAN_DATASTORE_WRITE_URL= pytest -s --ckan-ini=config/test.ini --cov=ckanext.feedback --cov-branch --disable-warnings services/utilization/test_details.py

この手順でテストを実行できます。

@ryo-ma
Copy link
Contributor

ryo-ma commented Mar 27, 2023

上記の手順は詳細ドキュメントに追加しておきましょうか。

@ryo-ma
Copy link
Contributor

ryo-ma commented Mar 27, 2023

こちらのコマンドを実行すると以下のように no tests run になりますが何かわかりますでしょうか?

CKAN_SQLALCHEMY_URL= CKAN_DATASTORE_READ_URL= CKAN_DATASTORE_WRITE_URL= pytest -s --ckan-ini=config/test.ini --cov=ckanext.feedback --cov-branch --disable-warnings services/utilization/test_details.py
2023-03-27 14:25:25,422 INFO  [ckan.cli] Using configuration file /usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/tests/config/test.ini                                                [11/3739]
2023-03-27 14:25:25,422 INFO  [ckan.config.environment] Loading static files from public
2023-03-27 14:25:25,535 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/venv/src/ckan/ckan/templates
2023-03-27 14:25:25,734 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/venv/src/ckan/ckan/templates
========================================= test session starts =========================================
platform linux -- Python 3.8.16, pytest-4.6.5, py-1.11.0, pluggy-0.13.1
rootdir: /usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/tests
plugins: Faker-18.3.1, freezegun-0.4.1, ckan-0.0.12, split-tests-1.0.9, pyfakefs-3.2, rerunfailures-8.0, cov-2.7.1
collected 0 items


---------- coverage: platform linux, python 3.8.16-final-0 -----------
Name                                                                                                       Stmts   Miss Branch BrPart  Cover
--------------------------------------------------------------------------------------------------------------------------------------------
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/__init__.py                                    0      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/command/feedback.py                           74     49      8      0    30%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/controllers/__init__.py                        0      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/controllers/download.py                       12      4      2      0    57%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/controllers/resource.py                        0      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/controllers/utilization.py                    55     31      4      0    41%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/models/__init__.py                             0      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/models/download.py                            12      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/models/issue.py                               21      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/models/resource_comment.py                    43      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/models/session.py                              5      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/models/utilization.py                         50      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/plugin.py                                     32      4      0      0    88%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/services/__init__.py                           0      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/services/download/__init__.py                  0      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/services/download/summary.py                  22     11      2      0    46%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/services/resource/__init__.py                  0      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/services/resource/comment.py                   0      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/services/resource/summary.py                   0      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/services/utilization/__init__.py               0      0      0      0   100%                                                                    /usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/services/utilization/comment.py                0      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/services/utilization/comment_approval.py       0      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/services/utilization/details.py               27     16      2      0    38%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/services/utilization/registration.py           0      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/services/utilization/search.py                15      8      6      0    33%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/services/utilization/summary.py               10      6      2      0    33%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/views/__init__.py                              0      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/views/download.py                              9      0      0      0   100%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/views/error_handler.py                        20      6      2      0    64%
/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/views/utilization.py                          10      0      2      0   100%
__init__.py                                                                                                    0      0      0      0   100%
controllers/__init__.py                                                                                        0      0      0      0   100%
controllers/test_download.py                                                                                  39     39      2      0     0%
controllers/test_resource.py                                                                                   0      0      0      0   100%
controllers/test_utilization.py                                                                                0      0      0      0   100%
models/__init__.py                                                                                             0      0      0      0   100%
models/test_download.py                                                                                        0      0      0      0   100%
models/test_issue.py                                                                                           0      0      0      0   100%
models/test_resource_comment.py                                                                                0      0      0      0   100%
models/test_utilization.py                                                                                     0      0      0      0   100%
test_plugin.py                                                                                                 2      2      0      0     0%
--------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                                                                        458    176     32      0    58%

==================================== no tests ran in 0.08 seconds =====================================

@ryo-ma
Copy link
Contributor

ryo-ma commented Mar 27, 2023

#35 (comment)
こちらの件はコマンドの末尾にディレクトリ指定が必要?な気がします 例えば CKAN_SQLALCHEMY_URL= CKAN_DATASTORE_READ_URL= CKAN_DATASTORE_WRITE_URL= pytest -s --ckan-ini=config/test.ini --cov=ckanext.feedback --cov-branch --disable-warnings services/utilization/test_details.py ./

@To-Ki-O
Copy link
Collaborator Author

To-Ki-O commented Mar 27, 2023

Slackのコードをそのまま掲載してしまい、すいませんでした。
ご指摘いただいた通り、ディレクトリに指定が必要になります。

手順通りであれば、/usr/lib/ckan/venv/lib/python3.8/site-packages/ckanext/feedback/testsにいるはずですので、
以下のコードでテスト実行が可能です。

CKAN_SQLALCHEMY_URL= CKAN_DATASTORE_READ_URL= CKAN_DATASTORE_WRITE_URL= pytest -s --ckan-ini=config/test.ini --cov=ckanext.feedback --cov-branch --disable-warnings ./

※ #35 (comment)で指摘いただいたコードと同様になります

@ryo-ma ryo-ma merged commit d9b9b75 into main Mar 29, 2023
2 checks passed
To-Ki-O added a commit that referenced this pull request Mar 29, 2023
* initial commit to do test

* modify test.ini and test_download.py in models

* move test.ini from root to ckanext/feedback/tests

* delete sections that is not needed

* delete test.init and modify config/test.ini

* add DownloadSummary model test

* modify indents in download model test

* add download controller test

* add test about download service

* delete test about download model

* commit to checkout

* change to use the mock of database access

* commit to checkout

* commit to checkout

* commit to checkout

* rewrite the test to use test DB

* run isort, black, pflake8

* rename views to services

* delete DownloadController.increment_resource_download

* delete app_context

* sepalate the test of extended_download

* modify static initializaer to setup_class

* add setup function and move resource and app into it

* change setup to setup_method
@To-Ki-O To-Ki-O deleted the feature/test-download branch March 30, 2023 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants