Skip to content

Commit

Permalink
Merge pull request #53 from antgonza/actually-test
Browse files Browse the repository at this point in the history
add nosetests
  • Loading branch information
charles-cowart authored Aug 19, 2024
2 parents 21069c3 + 0601510 commit d7ae29a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 27 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/qiita-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion qiita_client/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -379,5 +379,6 @@ def register_command(self, command):
PUBLICATIONS = %s
[oauth2]
SERVER_CERT = %s
CLIENT_ID = %s
CLIENT_SECRET = %s"""
13 changes: 10 additions & 3 deletions qiita_client/qiita_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 5 additions & 3 deletions qiita_client/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import logging

logger = logging.getLogger(__name__)
URL = "https://localhost:8383"


class PluginTestCase(TestCase):
Expand All @@ -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/')
Expand Down
15 changes: 8 additions & 7 deletions qiita_client/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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/')
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down
26 changes: 14 additions & 12 deletions qiita_client/tests/test_qiita_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
# -----------------------------------------------------------------------------

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
import pandas as pd

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'
Expand Down Expand Up @@ -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
Expand All @@ -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/")
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d7ae29a

Please sign in to comment.