Esempio n. 1
0
    def test_post_ndex(self):
        pdict = {}
        pdict[nbgwas_rest.ALPHA_PARAM] = 0.5
        pdict[nbgwas_rest.NDEX_PARAM] = 'someid'
        pdict['protein_coding'] = 'hg19'
        pdict[nbgwas_rest.SNP_LEVEL_SUMMARY_PARAM] = (io.BytesIO(b'hi there'),
                                                      'yo.txt')
        pdict[nbgwas_rest.SNP_LEVEL_SUMMARY_COL_LABEL_PARAM] = 'hi,how,are'
        rv = self._app.post(nbgwas_rest.SNP_ANALYZER_NS, data=pdict,
                            follow_redirects=True)
        self.assertEqual(rv.status_code, 202)
        res = rv.headers['Location']
        self.assertTrue(res is not None)
        self.assertTrue(nbgwas_rest.SNP_ANALYZER_NS in res)

        uuidstr = re.sub('^.*/', '', res)
        nbgwas_rest.app.config[nbgwas_rest.JOB_PATH_KEY] = self._temp_dir

        tpath = nbgwas_rest.get_task(uuidstr,
                                     basedir=nbgwas_rest.get_submit_dir())
        self.assertTrue(os.path.isdir(tpath))
        jsonfile = os.path.join(tpath, nbgwas_rest.TASK_JSON)
        self.assertTrue(os.path.isfile(jsonfile))
        with open(jsonfile, 'r') as f:
            jdata = json.load(f)

        self.assertEqual(jdata[nbgwas_rest.ALPHA_PARAM], 0.5)
        self.assertEqual(jdata[nbgwas_rest.NDEX_PARAM], 'someid')
        self.assertEqual(jdata[nbgwas_rest.SNP_LEVEL_SUMMARY_COL_LABEL_PARAM],
                         'hi,how,are')
Esempio n. 2
0
    def test_get_task_for_validuuid(self):
        somefile = os.path.join(self._temp_dir, '1')
        open(somefile, 'a').close()
        theuuid_dir = os.path.join(self._temp_dir, '1.2.3.4', '1234')
        os.makedirs(theuuid_dir, mode=0o755)

        someipfile = os.path.join(self._temp_dir, '1.2.3.4', '1')
        open(someipfile, 'a').close()
        self.assertEqual(nbgwas_rest.get_task('1234',
                                              basedir=self._temp_dir),
                         theuuid_dir)
Esempio n. 3
0
 def test_get_task_for_nonexistantuuid(self):
     self.assertEqual(nbgwas_rest.get_task(str(uuid.uuid4()),
                                           basedir=self._temp_dir), None)
Esempio n. 4
0
 def test_get_task_for_none_uuid(self):
     self.assertEqual(nbgwas_rest.get_task(None,
                                           basedir=self._temp_dir), None)
Esempio n. 5
0
 def test_get_task_basedir_not_a_directory(self):
     somefile = os.path.join(self._temp_dir, 'hi')
     open(somefile, 'a').close()
     self.assertEqual(nbgwas_rest.get_task('foo', basedir=somefile), None)
Esempio n. 6
0
 def test_get_task_basedir_none(self):
     self.assertEqual(nbgwas_rest.get_task('foo'), None)