예제 #1
0
 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')
예제 #2
0
파일: test_util.py 프로젝트: mjunaidi/qiita
 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")
예제 #3
0
 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)
예제 #4
0
 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')
예제 #5
0
def execute_job(server_url, job_id, output_dir):
    """Starts the plugin and executes the assigned task

    Parameters
    ----------
    server_url : str
        The url of the server
    job_id : str
        The job id

    Raises
    ------
    RuntimeError
        If there is a problem gathering the job information
    """
    qclient = QiitaClient(server_url)
    # Request job information
    job_info = qclient.get("/qiita_db/jobs/%s" % job_id)
    # Check if we have received the job information so we can start it
    if job_info and job_info['success']:
        # Starting the heartbeat
        start_heartbeat(qclient, job_id)
        # Execute the given task
        task_name = job_info['command']
        task = TASK_DICT[task_name]

        if not exists(output_dir):
            makedirs(output_dir)
        try:
            payload = task(qclient, job_id, job_info['parameters'],
                           output_dir)
        except Exception:
            exc_str = repr(traceback.format_exception(*sys.exc_info()))
            error_msg = ("Error executing %s:\n%s" % (task_name, exc_str))
            payload = format_payload(False, error_msg=error_msg)
        # The job completed
        complete_job(qclient, job_id, payload)
    else:
        raise RuntimeError("Can't get job (%s) information" % job_id)
예제 #6
0
파일: plugin.py 프로젝트: mjunaidi/qiita
def execute_job(server_url, job_id, output_dir):
    """Starts the plugin and executes the assigned task

    Parameters
    ----------
    server_url : str
        The url of the server
    job_id : str
        The job id

    Raises
    ------
    RuntimeError
        If there is a problem gathering the job information
    """
    qclient = QiitaClient(server_url)
    # Request job information
    job_info = qclient.get("/qiita_db/jobs/%s" % job_id)
    # Check if we have received the job information so we can start it
    if job_info and job_info['success']:
        # Starting the heartbeat
        start_heartbeat(qclient, job_id)
        # Execute the given task
        task_name = job_info['command']
        task = TASK_DICT[task_name]

        if not exists(output_dir):
            makedirs(output_dir)
        try:
            payload = task(qclient, job_id, job_info['parameters'], output_dir)
        except Exception:
            exc_str = repr(traceback.format_exception(*sys.exc_info()))
            error_msg = ("Error executing %s:\n%s" % (task_name, exc_str))
            payload = format_payload(False, error_msg=error_msg)
        # The job completed
        complete_job(qclient, job_id, payload)
    else:
        raise RuntimeError("Can't get job (%s) information" % job_id)
예제 #7
0
    def test_init_cert(self):
        httpretty.register_uri(
            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 % 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, cert_fp)
예제 #8
0
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')

    def tearDown(self):
        for fp in self._clean_up_files:
            if exists(fp):
                remove(fp)
        if self._old_fp:
            environ['QP_TARGET_GENE_CONFIG_FP'] = self._old_fp
        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(
            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 % 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, cert_fp)

    @httpretty.activate
    def test_get(self):
        httpretty.register_uri(
            httpretty.GET,
            "https://test_server.com/qiita_db/artifacts/1/type/",
            body='{"type": "FASTQ", "success": true, "error": ""}')
        obs = self.tester.get("/qiita_db/artifacts/1/type/")
        exp = {"type": "FASTQ", "success": True, "error": ""}
        self.assertEqual(obs, exp)

    @httpretty.activate
    def test_get_error(self):
        httpretty.register_uri(
            httpretty.GET,
            "https://test_server.com/qiita_db/artifacts/1/type/",
            status=500)
        obs = self.tester.get("/qiita_db/artifacts/1/type/")
        self.assertIsNone(obs)

    @httpretty.activate
    def test_post(self):
        httpretty.register_uri(
            httpretty.POST,
            "https://test_server.com/qiita_db/artifacts/1/type/",
            body='{"type": "FASTQ", "success": true, "error": ""}')
        obs = self.tester.post("/qiita_db/artifacts/1/type/", data="")
        exp = {"type": "FASTQ", "success": True, "error": ""}
        self.assertEqual(obs, exp)

    @httpretty.activate
    def test_post_error(self):
        httpretty.register_uri(
            httpretty.POST,
            "https://test_server.com/qiita_db/artifacts/1/type/",
            status=500)
        obs = self.tester.post("/qiita_db/artifacts/1/type/")
        self.assertIsNone(obs)
예제 #9
0
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')

    def tearDown(self):
        for fp in self._clean_up_files:
            if exists(fp):
                remove(fp)
        if self._old_fp:
            environ['QP_TARGET_GENE_CONFIG_FP'] = self._old_fp
        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(
            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 % 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, cert_fp)

    @httpretty.activate
    def test_get(self):
        httpretty.register_uri(
            httpretty.GET,
            "https://test_server.com/qiita_db/artifacts/1/type/",
            body='{"type": "FASTQ", "success": true, "error": ""}')
        obs = self.tester.get("/qiita_db/artifacts/1/type/")
        exp = {"type": "FASTQ", "success": True, "error": ""}
        self.assertEqual(obs, exp)

    @httpretty.activate
    def test_get_error(self):
        httpretty.register_uri(
            httpretty.GET,
            "https://test_server.com/qiita_db/artifacts/1/type/",
            status=500)
        obs = self.tester.get("/qiita_db/artifacts/1/type/")
        self.assertIsNone(obs)

    @httpretty.activate
    def test_post(self):
        httpretty.register_uri(
            httpretty.POST,
            "https://test_server.com/qiita_db/artifacts/1/type/",
            body='{"type": "FASTQ", "success": true, "error": ""}')
        obs = self.tester.post("/qiita_db/artifacts/1/type/", data="")
        exp = {"type": "FASTQ", "success": True, "error": ""}
        self.assertEqual(obs, exp)

    @httpretty.activate
    def test_post_error(self):
        httpretty.register_uri(
            httpretty.POST,
            "https://test_server.com/qiita_db/artifacts/1/type/",
            status=500)
        obs = self.tester.post("/qiita_db/artifacts/1/type/")
        self.assertIsNone(obs)