Skip to content

Commit d7ae29a

Browse files
Merge pull request #53 from antgonza/actually-test
add nosetests
2 parents 21069c3 + 0601510 commit d7ae29a

File tree

7 files changed

+49
-27
lines changed

7 files changed

+49
-27
lines changed

Diff for: .github/workflows/qiita-ci.yml

+9
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ jobs:
8181
conda activate qiita_client
8282
pip --quiet install .
8383
84+
# Note that the qiita conda environment has installed the qiita_client "master branch"
85+
# but to fully test we need to install the current branch of qiita_client
86+
conda deactivate
87+
conda activate qiita
88+
pip --quiet install .
89+
8490
- name: Starting Main Services
8591
shell: bash -l {0}
8692
run: |
@@ -119,6 +125,9 @@ jobs:
119125
conda activate qiita_client
120126
export QIITA_ROOTCA_CERT=`pwd`/qiita-dev/qiita_core/support_files/ci_rootca.crt
121127
export QIITA_CONFIG_FP=`pwd`/qiita-dev/qiita_core/support_files/config_test_local.cfg
128+
export QIITA_CLIENT_DEBUG_LEVEL=DEBUG
129+
nosetests --with-doctest --with-coverage --cover-package=qiita_client
130+
122131
- uses: codecov/codecov-action@v3
123132
with:
124133
token: ${{ secrets.CODECOV_TOKEN }}

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This package includes the Qiita Client utility library, a library to simplify th
99

1010
How to test this package?
1111
-------------------------
12-
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.
12+
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.
1313
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:
1414

1515
```bash

Diff for: qiita_client/plugin.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def __call__(self, server_url, job_id, output_dir):
250250
# this value will prevent underlying libraries
251251
# from validating the server's cert using
252252
# certifi's pem cache.
253-
ca_cert=environ['QIITA_ROOTCA_CERT'])
253+
ca_cert=config.get('oauth2', 'SERVER_CERT'))
254254

255255
if job_id == 'register':
256256
self._register(qclient)
@@ -379,5 +379,6 @@ def register_command(self, command):
379379
PUBLICATIONS = %s
380380
381381
[oauth2]
382+
SERVER_CERT = %s
382383
CLIENT_ID = %s
383384
CLIENT_SECRET = %s"""

Diff for: qiita_client/qiita_client.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@
2828
logger = logging.getLogger(__name__)
2929

3030
JOB_COMPLETED = False
31-
MAX_RETRIES = 3
32-
MIN_TIME_SLEEP = 180
33-
MAX_TIME_SLEEP = 360
31+
# if the log level is not CRITICAL, the default, then we not expect slow
32+
# responses from the server so let's make the retries values small
33+
if logger.level != logging.CRITICAL:
34+
MAX_RETRIES = 2
35+
MIN_TIME_SLEEP = 2
36+
MAX_TIME_SLEEP = 5
37+
else:
38+
MAX_RETRIES = 3
39+
MIN_TIME_SLEEP = 180
40+
MAX_TIME_SLEEP = 360
3441
BLANK_FILE_THRESHOLD = 100
3542

3643

Diff for: qiita_client/testing.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import logging
1616

1717
logger = logging.getLogger(__name__)
18+
URL = "https://localhost:8383"
1819

1920

2021
class PluginTestCase(TestCase):
@@ -24,12 +25,13 @@ def setUpClass(cls):
2425
cls.client_id = '19ndkO3oMKsoChjVVWluF7QkxHRfYhTKSFbAVt8IhK7gZgDaO4'
2526
cls.client_secret = ('J7FfQ7CQdOxuKhQAf1eoGgBAE81Ns8Gu3EKaWFm3IO2JKh'
2627
'AmmCWZuabe0O5Mp28s1')
27-
qiita_port = int(environ.get('QIITA_PORT', 21174))
28+
cls.ca_cert = environ.get('QIITA_ROOTCA_CERT')
2829

2930
# do not rely on defining ca_cert for these tests. Instead append
3031
# the appropriate CA cert to certifi's pem file.
31-
cls.qclient = QiitaClient("https://localhost:%d" % qiita_port,
32-
cls.client_id, cls.client_secret)
32+
cls.qclient = QiitaClient(
33+
URL, cls.client_id, cls.client_secret, cls.ca_cert)
34+
3335
logger.debug(
3436
'PluginTestCase.setUpClass() token %s' % cls.qclient._token)
3537
cls.qclient.post('/apitest/reload_plugins/')

Diff for: qiita_client/tests/test_plugin.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from json import dumps
1414
from tempfile import mkdtemp
1515

16-
from qiita_client.testing import PluginTestCase
16+
from qiita_client.testing import PluginTestCase, URL
1717
from qiita_client import (QiitaPlugin, QiitaTypePlugin, QiitaCommand,
1818
QiitaArtifactType, ArtifactInfo)
1919

@@ -146,7 +146,8 @@ def html_generator_func(a, b, c, d):
146146
'PLUGIN_TYPE = artifact definition\n',
147147
'PUBLICATIONS = \n',
148148
'\n',
149-
'[oauth2]\n']
149+
'[oauth2]\n',
150+
'SERVER_CERT = \n']
150151
# We will test the last 2 lines independently since they're variable
151152
# in each test run
152153
self.assertEqual(conf[:-2], exp_lines)
@@ -167,12 +168,12 @@ def html_generator_func(a, b, c, d):
167168
validate_func, html_generator_func, atypes)
168169

169170
# Generate the config file for the new plugin
170-
tester.generate_config('ls', 'echo')
171+
tester.generate_config('ls', 'echo', self.ca_cert)
171172
# Ask Qiita to reload the plugins
172173
self.qclient.post('/apitest/reload_plugins/')
173174

174175
# Install the current plugin
175-
tester("https://localhost:21174", 'register', 'ignored')
176+
tester(URL, 'register', 'ignored')
176177

177178
# Check that it has been installed
178179
obs = self.qclient.get('/qiita_db/plugins/NewPlugin/1.0.0/')
@@ -211,9 +212,9 @@ def func(qclient, job_id, job_params, working_dir):
211212
{'out1': 'Demultiplexed'})
212213
tester.register_command(a_cmd)
213214

214-
tester.generate_config('ls', 'echo')
215+
tester.generate_config('ls', 'echo', self.ca_cert)
215216
self.qclient.post('/apitest/reload_plugins/')
216-
tester("https://localhost:21174", 'register', 'ignored')
217+
tester(URL, 'register', 'ignored')
217218

218219
obs = self.qclient.get('/qiita_db/plugins/NewPlugin/0.0.1/')
219220
self.assertEqual(obs['name'], 'NewPlugin')
@@ -229,7 +230,7 @@ def func(qclient, job_id, job_params, working_dir):
229230
'status': 'queued'}
230231
job_id = self.qclient.post('/apitest/processing_job/',
231232
data=data)['job']
232-
tester("https://localhost:21174", job_id, self.outdir)
233+
tester(URL, job_id, self.outdir)
233234

234235
status = self._wait_for_running_job(job_id)
235236
self.assertEqual(status, 'success')

Diff for: qiita_client/tests/test_qiita_client.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
# -----------------------------------------------------------------------------
88

99
from unittest import TestCase, main
10-
from os import remove, close, environ
10+
from os import remove, close
1111
from os.path import basename, exists
1212
from tempfile import mkstemp
1313
from json import dumps
1414
import pandas as pd
1515

1616
from qiita_client.qiita_client import (QiitaClient, _format_payload,
1717
ArtifactInfo)
18-
from qiita_client.testing import PluginTestCase
18+
from qiita_client.testing import PluginTestCase, URL
1919
from qiita_client.exceptions import BadRequestError
2020

2121
CLIENT_ID = '19ndkO3oMKsoChjVVWluF7QkxHRfYhTKSFbAVt8IhK7gZgDaO4'
@@ -97,12 +97,9 @@ def test_format_payload_error(self):
9797

9898
class QiitaClientTests(PluginTestCase):
9999
def setUp(self):
100-
self.tester = QiitaClient("https://localhost:21174",
100+
self.tester = QiitaClient(URL,
101101
CLIENT_ID,
102-
CLIENT_SECRET)
103-
self.bad_tester = QiitaClient("https://localhost:21174",
104-
BAD_CLIENT_ID,
105-
CLIENT_SECRET)
102+
CLIENT_SECRET, self.ca_cert)
106103
self.clean_up_files = []
107104

108105
# making assertRaisesRegex compatible with Python 2.7 and 3.9
@@ -115,14 +112,14 @@ def tearDown(self):
115112
remove(fp)
116113

117114
def test_init(self):
118-
obs = QiitaClient("https://localhost:21174",
115+
obs = QiitaClient(URL,
119116
CLIENT_ID,
120117
CLIENT_SECRET,
121-
ca_cert=environ['QIITA_ROOT_CA'])
122-
self.assertEqual(obs._server_url, "https://localhost:21174")
118+
ca_cert=self.ca_cert)
119+
self.assertEqual(obs._server_url, URL)
123120
self.assertEqual(obs._client_id, CLIENT_ID)
124121
self.assertEqual(obs._client_secret, CLIENT_SECRET)
125-
self.assertEqual(obs._verify, environ['QIITA_ROOT_CA'])
122+
self.assertEqual(obs._verify, self.ca_cert)
126123

127124
def test_get(self):
128125
obs = self.tester.get("/qiita_db/artifacts/1/")
@@ -244,9 +241,14 @@ def test_update_job_step_ignore_failure(self):
244241

245242
# confirm that update_job_step behaves as before when ignore_error
246243
# parameter absent or set to False.
244+
self.bad_tester = QiitaClient(URL,
245+
BAD_CLIENT_ID,
246+
CLIENT_SECRET,
247+
self.ca_cert)
247248

248249
with self.assertRaises(BaseException):
249-
self.bad_tester.update_job_step(job_id, new_step)
250+
self.bad_tester.update_job_step(
251+
job_id, new_step, ignore_error=False)
250252

251253
with self.assertRaises(BaseException):
252254
self.bad_tester.update_job_step(job_id,

0 commit comments

Comments
 (0)