Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions qiita_db/support_files/patches/python_patches/34.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from random import SystemRandom
from string import ascii_letters, digits

from qiita_db.sql_connection import TRN

pool = ascii_letters + digits
client_id = ''.join([SystemRandom().choice(pool) for _ in range(50)])
client_secret = ''.join([SystemRandom().choice(pool) for _ in range(255)])

with TRN:
sql = """INSERT INTO qiita.oauth_identifiers (client_id, client_secret)
VALUES (%s, %s)"""
TRN.add(sql, [client_id, client_secret])
TRN.execute()

print "Please, add these values to your target gene plugin configuration file:"
print "CLIENT_ID = %s" % client_id
print "CLIENT_SECRET = %s" % client_secret
17 changes: 17 additions & 0 deletions qiita_plugins/target_gene/tgp/split_libraries/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@


class UtilTests(TestCase):
@httpretty.activate
def setUp(self):
httpretty.register_uri(
httpretty.POST,
"https://test_server.com/qiita_db/authenticate/",
body='{"access_token": "token", "token_type": "Bearer", '
'"expires_in": "3600"}')

self.qclient = QiitaClient("https://test_server.com")
self._clean_up_files = []

Expand Down Expand Up @@ -51,6 +58,11 @@ def test_get_artifact_information(self):
httpretty.GET,
"https://test_server.com/qiita_db/artifacts/1/type/",
body='{"type": "FASTQ", "success": true, "error": ""}')
httpretty.register_uri(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated from setUp

httpretty.POST,
"https://test_server.com/qiita_db/authenticate/",
body='{"access_token": "token", "token_type": "Bearer", '
'"expires_in": "3600"}')

obs_fps, obs_mf, obs_at = get_artifact_information(self.qclient, 1)

Expand All @@ -67,6 +79,11 @@ def test_get_artifact_error(self):
httpretty.GET,
"https://test_server.com/qiita_db/artifacts/1/filepaths/",
body='{"filepaths": '', "success": false, "error": "some error"}')
httpretty.register_uri(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

httpretty.POST,
"https://test_server.com/qiita_db/authenticate/",
body='{"access_token": "token", "token_type": "Bearer", '
'"expires_in": "3600"}')

with self.assertRaises(ValueError):
get_artifact_information(self.qclient, 1)
Expand Down
4 changes: 4 additions & 0 deletions qiita_plugins/target_gene/tgp/support_files/config_file.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
# If the Qiita server certificate is not a valid certificate,
# put here the path to the certificate so it can be verified
SERVER_CERT =

# Oauth2 plugin configuration
CLIENT_ID =
CLIENT_SECRET =
53 changes: 50 additions & 3 deletions qiita_plugins/target_gene/tgp/tests/test_qiita_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@


class QiitaClientTests(TestCase):
@httpretty.activate
def setUp(self):
httpretty.register_uri(
httpretty.POST,
"https://test_server.com/qiita_db/authenticate/",
body='{"access_token": "token", "token_type": "Bearer", '
'"expires_in": "3600"}')
self.tester = QiitaClient("https://test_server.com")
self._clean_up_files = []
self._old_fp = environ.get('QP_TARGET_GENE_CONFIG_FP')
Expand All @@ -31,24 +37,40 @@ def tearDown(self):
else:
del environ['QP_TARGET_GENE_CONFIG_FP']

@httpretty.activate
def test_init(self):
httpretty.register_uri(
httpretty.POST,
"https://test_server.com/qiita_db/authenticate/",
body='{"access_token": "token", "token_type": "Bearer", '
'"expires_in": "3600"}')
obs = QiitaClient("https://test_server.com")
self.assertEqual(obs._server_url, "https://test_server.com")
self.assertTrue(obs._verify)

@httpretty.activate
def test_init_cert(self):
httpretty.register_uri(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated from setUp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remove this one - tests fail. The other 2, however, have been removed.

httpretty.POST,
"https://test_server.com/qiita_db/authenticate/",
body='{"access_token": "token", "token_type": "Bearer", '
'"expires_in": "3600"}')
fd, cert_fp = mkstemp()
close(fd)
with open(cert_fp, 'w') as f:
f.write(CERT_FP)
fd, conf_fp = mkstemp()
close(fd)
with open(conf_fp, 'w') as f:
f.write(CONF_FP)
f.write(CONF_FP % cert_fp)

self._clean_up_files.append(conf_fp)

environ['QP_TARGET_GENE_CONFIG_FP'] = conf_fp
obs = QiitaClient("https://test_server.com")

self.assertEqual(obs._server_url, "https://test_server.com")
self.assertEqual(obs._verify, "/path/to/test_certificate.crt")
self.assertEqual(obs._verify, cert_fp)

@httpretty.activate
def test_get(self):
Expand Down Expand Up @@ -100,8 +122,33 @@ def test_post_error(self):
[main]
# If the Qiita server certificate is not a valid certificate,
# put here the path to the certificate so it can be verified
SERVER_CERT = /path/to/test_certificate.crt
SERVER_CERT = %s

# Oauth2 plugin configuration
CLIENT_ID = client_id
CLIENT_SECRET = client_secret
"""

CERT_FP = """-----BEGIN CERTIFICATE-----
MIIDVjCCAj4CCQCP4XnDqToF2zANBgkqhkiG9w0BAQUFADBtMQswCQYDVQQGEwJV
UzETMBEGA1UECBMKQ2FsaWZvcm5pYTESMBAGA1UEBxMJU2FuIERpZWdvMQ0wCwYD
VQQKEwRVQ1NEMRIwEAYDVQQLEwlLbmlnaHRMYWIxEjAQBgNVBAMTCWxvY2FsaG9z
dDAeFw0xNTEyMTgyMjE3MzBaFw0xNjEyMTcyMjE3MzBaMG0xCzAJBgNVBAYTAlVT
MRMwEQYDVQQIEwpDYWxpZm9ybmlhMRIwEAYDVQQHEwlTYW4gRGllZ28xDTALBgNV
BAoTBFVDU0QxEjAQBgNVBAsTCUtuaWdodExhYjESMBAGA1UEAxMJbG9jYWxob3N0
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt1ggW4M/l3Wpru4+2Cro
nnqaUWD0ImLnkdAbmDjhGiCdKqdb8yzLeKipGaRY383gd5vMWHsKB1I3t+EzFWiY
fxd12Evx6MUIXVZSkdConk+8xlmJ5ba1Hgy7qzErY7+HOtgqm1ylyqTuOZyv3Umv
0W6ETLVz/alfzxTlqAkvuJn7I7RrbY81I3b5SOUxJTtj9pPwkZtVOD0ha3FH0LBu
lE4oi6rQQhzIbUDWLITZRCteplV5ikbC3JqaJ7pDiYnOIPnRR0UF+xdyTiOvSNH8
WrKuAdGGN+90PDt8fgQOwptE5l/RGyoJ2on7nlSj5crDtYzXXDYw0DCzuFG12nZV
FwIDAQABMA0GCSqGSIb3DQEBBQUAA4IBAQBTQJ8WYpSfsXsgmDa2uIYX5E+8ECGn
patQJuxYfOEp9knnBBe+QcaBMY6E7uH6EZz2QwS/gdhfY8e8QXw9sh9ZrQKQlIAK
Q5l5qxAtek0C90qdseYWoomBhpmqMUicF0OgecbdZ4X6Tfc4hvN5IXUTMn9ZJEaV
fduah3c7xEkSbHQl6iHnJswNKTc7Amm+BIwuYJjCZxVgKxAgvYzzg/TFU03gqzfE
h7ARs1p4WdHH+WTMqCZq8+sju3Lum4uwjYaiLaFE7psDkWWAYOu6Jv/o0V1zER/S
LzNaDfkm5kq4VURhPMQzdAiVdiTNKDFnLB3erg6wG95q5OiGNO1WYSw2
-----END CERTIFICATE-----"""

if __name__ == '__main__':
main()
6 changes: 6 additions & 0 deletions qiita_plugins/target_gene/tgp/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@


class UtilTests(TestCase):
@httpretty.activate
def setUp(self):
httpretty.register_uri(
httpretty.POST,
"https://test_server.com/qiita_db/authenticate/",
body='{"access_token": "token", "token_type": "Bearer", '
'"expires_in": "3600"}')
self.qclient = QiitaClient("https://test_server.com")

def test_system_call(self):
Expand Down