diff --git a/.github/workflows/qiita-ci.yml b/.github/workflows/qiita-ci.yml index ebfd92c..d09ac5e 100644 --- a/.github/workflows/qiita-ci.yml +++ b/.github/workflows/qiita-ci.yml @@ -81,6 +81,12 @@ jobs: conda activate qiita_client pip --quiet install . + # Note that the qiita conda environment has installed the qiita_client "master branch" + # but to fully test we need to install the current branch of qiita_client + conda deactivate + conda activate qiita + pip --quiet install . + - name: Starting Main Services shell: bash -l {0} run: | @@ -119,6 +125,9 @@ jobs: conda activate qiita_client export QIITA_ROOTCA_CERT=`pwd`/qiita-dev/qiita_core/support_files/ci_rootca.crt export QIITA_CONFIG_FP=`pwd`/qiita-dev/qiita_core/support_files/config_test_local.cfg + export QIITA_CLIENT_DEBUG_LEVEL=DEBUG + nosetests --with-doctest --with-coverage --cover-package=qiita_client + - uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} diff --git a/README.md b/README.md index 7dfeedf..2f7eb4d 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This package includes the Qiita Client utility library, a library to simplify th How to test this package? ------------------------- -In order to test the Qiita Client package, a local installation of Qiita should be running in test mode on the address `https://localhost:21174`, with the default test database created in Qiita's test suite. +In order to test the Qiita Client package, a local installation of Qiita should be running in test mode on the address `https://localhost:8383`, with the default test database created in Qiita's test suite. Also, if Qiita is running with the default server SSL certificate, you need to export the variable `QIITA_ROOTCA_CERT` in your environment, so the Qiita Client can perform secure connections against the Qiita server: ```bash diff --git a/qiita_client/plugin.py b/qiita_client/plugin.py index a0fdc53..3af462e 100644 --- a/qiita_client/plugin.py +++ b/qiita_client/plugin.py @@ -250,7 +250,7 @@ def __call__(self, server_url, job_id, output_dir): # this value will prevent underlying libraries # from validating the server's cert using # certifi's pem cache. - ca_cert=environ['QIITA_ROOTCA_CERT']) + ca_cert=config.get('oauth2', 'SERVER_CERT')) if job_id == 'register': self._register(qclient) @@ -379,5 +379,6 @@ def register_command(self, command): PUBLICATIONS = %s [oauth2] +SERVER_CERT = %s CLIENT_ID = %s CLIENT_SECRET = %s""" diff --git a/qiita_client/qiita_client.py b/qiita_client/qiita_client.py index 610097f..ca7b189 100644 --- a/qiita_client/qiita_client.py +++ b/qiita_client/qiita_client.py @@ -28,9 +28,16 @@ logger = logging.getLogger(__name__) JOB_COMPLETED = False -MAX_RETRIES = 3 -MIN_TIME_SLEEP = 180 -MAX_TIME_SLEEP = 360 +# if the log level is not CRITICAL, the default, then we not expect slow +# responses from the server so let's make the retries values small +if logger.level != logging.CRITICAL: + MAX_RETRIES = 2 + MIN_TIME_SLEEP = 2 + MAX_TIME_SLEEP = 5 +else: + MAX_RETRIES = 3 + MIN_TIME_SLEEP = 180 + MAX_TIME_SLEEP = 360 BLANK_FILE_THRESHOLD = 100 diff --git a/qiita_client/testing.py b/qiita_client/testing.py index 89e7a25..da55598 100644 --- a/qiita_client/testing.py +++ b/qiita_client/testing.py @@ -15,6 +15,7 @@ import logging logger = logging.getLogger(__name__) +URL = "https://localhost:8383" class PluginTestCase(TestCase): @@ -24,12 +25,13 @@ def setUpClass(cls): cls.client_id = '19ndkO3oMKsoChjVVWluF7QkxHRfYhTKSFbAVt8IhK7gZgDaO4' cls.client_secret = ('J7FfQ7CQdOxuKhQAf1eoGgBAE81Ns8Gu3EKaWFm3IO2JKh' 'AmmCWZuabe0O5Mp28s1') - qiita_port = int(environ.get('QIITA_PORT', 21174)) + cls.ca_cert = environ.get('QIITA_ROOTCA_CERT') # do not rely on defining ca_cert for these tests. Instead append # the appropriate CA cert to certifi's pem file. - cls.qclient = QiitaClient("https://localhost:%d" % qiita_port, - cls.client_id, cls.client_secret) + cls.qclient = QiitaClient( + URL, cls.client_id, cls.client_secret, cls.ca_cert) + logger.debug( 'PluginTestCase.setUpClass() token %s' % cls.qclient._token) cls.qclient.post('/apitest/reload_plugins/') diff --git a/qiita_client/tests/test_plugin.py b/qiita_client/tests/test_plugin.py index 4981cfa..ab87f6b 100644 --- a/qiita_client/tests/test_plugin.py +++ b/qiita_client/tests/test_plugin.py @@ -13,7 +13,7 @@ from json import dumps from tempfile import mkdtemp -from qiita_client.testing import PluginTestCase +from qiita_client.testing import PluginTestCase, URL from qiita_client import (QiitaPlugin, QiitaTypePlugin, QiitaCommand, QiitaArtifactType, ArtifactInfo) @@ -146,7 +146,8 @@ def html_generator_func(a, b, c, d): 'PLUGIN_TYPE = artifact definition\n', 'PUBLICATIONS = \n', '\n', - '[oauth2]\n'] + '[oauth2]\n', + 'SERVER_CERT = \n'] # We will test the last 2 lines independently since they're variable # in each test run self.assertEqual(conf[:-2], exp_lines) @@ -167,12 +168,12 @@ def html_generator_func(a, b, c, d): validate_func, html_generator_func, atypes) # Generate the config file for the new plugin - tester.generate_config('ls', 'echo') + tester.generate_config('ls', 'echo', self.ca_cert) # Ask Qiita to reload the plugins self.qclient.post('/apitest/reload_plugins/') # Install the current plugin - tester("https://localhost:21174", 'register', 'ignored') + tester(URL, 'register', 'ignored') # Check that it has been installed obs = self.qclient.get('/qiita_db/plugins/NewPlugin/1.0.0/') @@ -211,9 +212,9 @@ def func(qclient, job_id, job_params, working_dir): {'out1': 'Demultiplexed'}) tester.register_command(a_cmd) - tester.generate_config('ls', 'echo') + tester.generate_config('ls', 'echo', self.ca_cert) self.qclient.post('/apitest/reload_plugins/') - tester("https://localhost:21174", 'register', 'ignored') + tester(URL, 'register', 'ignored') obs = self.qclient.get('/qiita_db/plugins/NewPlugin/0.0.1/') self.assertEqual(obs['name'], 'NewPlugin') @@ -229,7 +230,7 @@ def func(qclient, job_id, job_params, working_dir): 'status': 'queued'} job_id = self.qclient.post('/apitest/processing_job/', data=data)['job'] - tester("https://localhost:21174", job_id, self.outdir) + tester(URL, job_id, self.outdir) status = self._wait_for_running_job(job_id) self.assertEqual(status, 'success') diff --git a/qiita_client/tests/test_qiita_client.py b/qiita_client/tests/test_qiita_client.py index 17184e1..87178b0 100644 --- a/qiita_client/tests/test_qiita_client.py +++ b/qiita_client/tests/test_qiita_client.py @@ -7,7 +7,7 @@ # ----------------------------------------------------------------------------- from unittest import TestCase, main -from os import remove, close, environ +from os import remove, close from os.path import basename, exists from tempfile import mkstemp from json import dumps @@ -15,7 +15,7 @@ from qiita_client.qiita_client import (QiitaClient, _format_payload, ArtifactInfo) -from qiita_client.testing import PluginTestCase +from qiita_client.testing import PluginTestCase, URL from qiita_client.exceptions import BadRequestError CLIENT_ID = '19ndkO3oMKsoChjVVWluF7QkxHRfYhTKSFbAVt8IhK7gZgDaO4' @@ -97,12 +97,9 @@ def test_format_payload_error(self): class QiitaClientTests(PluginTestCase): def setUp(self): - self.tester = QiitaClient("https://localhost:21174", + self.tester = QiitaClient(URL, CLIENT_ID, - CLIENT_SECRET) - self.bad_tester = QiitaClient("https://localhost:21174", - BAD_CLIENT_ID, - CLIENT_SECRET) + CLIENT_SECRET, self.ca_cert) self.clean_up_files = [] # making assertRaisesRegex compatible with Python 2.7 and 3.9 @@ -115,14 +112,14 @@ def tearDown(self): remove(fp) def test_init(self): - obs = QiitaClient("https://localhost:21174", + obs = QiitaClient(URL, CLIENT_ID, CLIENT_SECRET, - ca_cert=environ['QIITA_ROOT_CA']) - self.assertEqual(obs._server_url, "https://localhost:21174") + ca_cert=self.ca_cert) + self.assertEqual(obs._server_url, URL) self.assertEqual(obs._client_id, CLIENT_ID) self.assertEqual(obs._client_secret, CLIENT_SECRET) - self.assertEqual(obs._verify, environ['QIITA_ROOT_CA']) + self.assertEqual(obs._verify, self.ca_cert) def test_get(self): obs = self.tester.get("/qiita_db/artifacts/1/") @@ -244,9 +241,14 @@ def test_update_job_step_ignore_failure(self): # confirm that update_job_step behaves as before when ignore_error # parameter absent or set to False. + self.bad_tester = QiitaClient(URL, + BAD_CLIENT_ID, + CLIENT_SECRET, + self.ca_cert) with self.assertRaises(BaseException): - self.bad_tester.update_job_step(job_id, new_step) + self.bad_tester.update_job_step( + job_id, new_step, ignore_error=False) with self.assertRaises(BaseException): self.bad_tester.update_job_step(job_id,