コード例 #1
0
ファイル: ag_pulldown.py プロジェクト: biocore/labadmin
 def post(self):
     # Do nothing if no file given
     if 'barcodes' not in self.request.files:
         surveys = db.list_external_surveys()
         self.render("ag_pulldown.html", currentuser=self.current_user,
                     barcodes='', blanks='', external='', surveys=surveys,
                     errors="No barcode file given, thus nothing could "
                            "be pulled down.")
         return
     # Get file information, ignoring commented out lines
     fileinfo = self.request.files['barcodes'][0]['body']
     lines = fileinfo.splitlines()
     # barcodes must be in first column, stripping in case extra spaces
     samples = [l.split('\t')[0].strip() for l in lines
                if not l.startswith('#')]
     barcodes = [b for b in samples if not b.upper().startswith('BLANK')]
     blanks = [b for b in samples if b.upper().startswith('BLANK')]
     hold = self.get_arguments('external', [])
     if hold:
         external = ','.join(hold)
     else:
         external = ''
     surveys = db.list_external_surveys()
     self.render("ag_pulldown.html", currentuser=self.current_user,
                 barcodes=",".join(barcodes), blanks=",".join(blanks),
                 surveys=surveys, external=external, errors='')
コード例 #2
0
    def test_post(self):
        self.mock_login_admin()
        response = self.post('/ag_pulldown/download/',
                             {'barcodes': ['000001448', '000001447',
                                           '100001449', '000001445',
                                           '000015296', '000015297',
                                           '000015298', '000015299',
                                           '000016180', '000016280',
                                           '000016281', '000016283',
                                           '000016284'],
                              'blanks': ['BLANK000001449', 'BLANK000001453',
                                         'BLANK100001453'],
                              'external': db.list_external_surveys()[:1],
                              'selected_ag_surveys': [-1, -2, -3, -4, -5],
                              'merged': 'True'})
        self.assertEqual(response.headers['Content-Disposition'],
                         'attachment; filename=metadata.zip')
        self.assertIn('failures.txt', response.body)
        self.assertIn('survey_Personal_Information_md.txt', response.body)

        # store the resulting zip archive to disc ...
        tmpfile = NamedTemporaryFile(mode='w', delete=False,
                                     prefix='metadata_pulldown_single_',
                                     suffix='.zip')
        tmpfile.write(response.body)
        tmpfile.close()
        # ... and read the content as dict of strings
        result = extract_zip(tmpfile.name)
        os.remove(tmpfile.name)

        # read in the true content from data dir for comparison
        truth = extract_zip(join(dirname(realpath(__file__)), 'data',
                                 'results_barcodes.zip'))
        self.maxDiff = None
        self.assertEqual(sneak_files(result), sneak_files(truth))
コード例 #3
0
    def post(self):
        form = ThirdPartyData()
        form.survey.choices = [(x, x) for x in db.list_external_surveys()]
        msg = ''
        seperators = {'comma': ',', 'tab': '\t', 'space': ' '}

        args = {a: v[0] for a, v in viewitems(self.request.arguments)}
        form.process(data=args)
        # Validate form and make sure upload happened
        if not form.validate() or 'file_in' not in self.request.files:
            self.render("ag_third_party.html", the_form=form, errors=msg)
            return

        # Format file for stringIO
        file_body = self.request.files['file_in'][0]['body'].replace(
            "\r\n", "\n").replace("\r", "\n")
        file_body = StringIO(unicode(file_body), newline=None)
        try:
            count = db.store_external_survey(
                file_body,
                form.survey.data,
                separator=seperators[form.seperator.data],
                survey_id_col=form.survey_id.data,
                trim=form.trim.data)
        except KeyError as e:
            msg = 'Header column not found: %s' % str(e)
        except Exception as e:
            # Print any error that happens to the page
            msg = str(e)
        else:
            msg = "%d surveys added to '%s' successfully" % \
                  (count, form.survey.data)
        self.render("ag_third_party.html", the_form=form, errors=msg)
コード例 #4
0
 def post(self):
     # Do nothing if no file given
     if 'barcodes' not in self.request.files:
         self.render("ag_pulldown.html",
                     currentuser=self.current_user,
                     barcodes='',
                     blanks='',
                     external='')
         return
     # Get file information, ignoring commented out lines
     fileinfo = self.request.files['barcodes'][0]['body']
     lines = fileinfo.splitlines()
     # barcodes must be in first column, stripping in case extra spaces
     samples = [
         l.split('\t')[0].strip() for l in lines if not l.startswith('#')
     ]
     barcodes = [b for b in samples if not b.upper().startswith('BLANK')]
     blanks = [b for b in samples if b.upper().startswith('BLANK')]
     hold = self.get_arguments('external', [])
     if hold:
         external = ','.join(hold)
     else:
         external = ''
     surveys = db.list_external_surveys()
     self.render("ag_pulldown.html",
                 currentuser=self.current_user,
                 barcodes=",".join(barcodes),
                 blanks=",".join(blanks),
                 surveys=surveys,
                 external=external)
コード例 #5
0
    def post(self):
        form = ThirdPartyData()
        form.survey.choices = [(x, x) for x in db.list_external_surveys()]
        msg = ''
        seperators = {'comma': ',', 'tab': '\t', 'space': ' '}

        args = {a: v[0] for a, v in viewitems(self.request.arguments)}
        form.process(data=args)
        # Validate form and make sure upload happened
        if not form.validate() or 'file_in' not in self.request.files:
            self.render("ag_third_party.html", the_form=form,
                        errors=msg)
            return

        # Format file for stringIO
        file_body = self.request.files['file_in'][0]['body'].replace(
            "\r\n", "\n").replace("\r", "\n")
        file_body = StringIO(unicode(file_body), newline=None)
        try:
            count = db.store_external_survey(
                file_body, form.survey.data,
                separator=seperators[form.seperator.data],
                survey_id_col=form.survey_id.data, trim=form.trim.data)
        except KeyError as e:
            msg = 'Header column not found: %s' % str(e)
        except Exception as e:
            # Print any error that happens to the page
            msg = str(e)
        else:
            msg = "%d surveys added to '%s' successfully" % \
                  (count, form.survey.data)
        self.render("ag_third_party.html", the_form=form,
                    errors=msg)
コード例 #6
0
ファイル: test_ag_pulldown.py プロジェクト: biocore/labadmin
 def test_post(self):
     self.mock_login_admin()
     response = self.post('/ag_pulldown/download/',
                          {'barcodes': ['000001445',
                                        '000001446',
                                        '000001447',
                                        '000001448',
                                        '100001449',
                                        '000016180',
                                        '000015296',
                                        '000015297',
                                        '000015298',
                                        '000015299',
                                        '000015300',
                                        '000016280',
                                        '000016281',
                                        '000016282',
                                        '000016283',
                                        '000016284'],
                           'blanks': ['BLANK000001449',
                                      'BLANK000001453',
                                      'BLANK100001453'],
                           'external': db.list_external_surveys()[:1]})
     self.assertEqual(response.headers['Content-Disposition'],
                      'attachment; filename=metadata.zip')
     self.assertIn('failures.txt', response.body)
     self.assertIn('survey_1_md.txt', response.body)
コード例 #7
0
 def get(self):
     surveys = db.list_external_surveys()
     self.render("ag_pulldown.html",
                 currentuser=self.current_user,
                 barcodes=[],
                 surveys=surveys,
                 errors='')
コード例 #8
0
ファイル: test_ag_pulldown.py プロジェクト: biocore/labadmin
 def test_get(self):
     self.mock_login_admin()
     response = self.get('/ag_pulldown/')
     self.assertEqual(response.code, 200)
     for survey in db.list_external_surveys():
         self.assertIn("<option value='%s'>%s</option>" % (survey, survey),
                       response.body)
     self.assertNotIn('<input type="submit" disabled>', response.body)
コード例 #9
0
 def test_get(self):
     self.mock_login_admin()
     response = self.get('/ag_pulldown/')
     self.assertEqual(response.code, 200)
     for survey in db.list_external_surveys():
         self.assertIn("<option value='%s'>%s</option>" % (survey, survey),
                       response.body)
     self.assertNotIn('<input type="submit" disabled>', response.body)
コード例 #10
0
    def post(self):
        # Do nothing if no file given
        if 'barcodes' not in self.request.files:
            surveys = db.list_external_surveys()
            ags = db.list_ag_surveys(map(int, self.get_arguments('agsurveys')))
            self.render("ag_pulldown.html",
                        currentuser=self.current_user,
                        barcodes='',
                        blanks='',
                        external='',
                        surveys=surveys,
                        errors="No barcode file given, thus nothing could "
                        "be pulled down.",
                        agsurveys=ags,
                        merged=self.get_argument('merged', default='False'))
            return
        # Get file information, ignoring commented out lines
        fileinfo = self.request.files['barcodes'][0]['body']
        lines = fileinfo.splitlines()
        # barcodes must be in first column, stripping in case extra spaces
        samples = [
            l.split('\t')[0].strip() for l in lines if not l.startswith('#')
        ]
        barcodes = [b for b in samples if not b.upper().startswith('BLANK')]
        blanks = [b for b in samples if b.upper().startswith('BLANK')]

        hold = self.get_arguments('external')

        if hold:
            external = ','.join(hold)
        else:
            external = ''
        surveys = db.list_external_surveys()
        ags = db.list_ag_surveys(map(int, self.get_arguments('agsurveys')))
        self.render("ag_pulldown.html",
                    currentuser=self.current_user,
                    barcodes=",".join(barcodes),
                    blanks=",".join(blanks),
                    surveys=surveys,
                    external=external,
                    errors='',
                    agsurveys=ags,
                    merged=self.get_argument('merged', default='False'))
コード例 #11
0
    def test_get(self):
        self.mock_login_admin()
        tpsurveys = db.list_external_surveys()
        form = ThirdPartyData()
        # make sure that at least this third party survey exist in the DB
        if len(tpsurveys) == 0:
            response = self.post('/ag_third_party/add/',
                                 {'name': 'newTPsurvey',
                                  'description': 'akSJdghcakscmakld  fh',
                                  'url': 'www.google.com'})

        response = self.get('/ag_third_party/data/')
        self.assertEqual(response.code, 200)
        # test that all fields are present in the HTML side.
        for key, element in form.__dict__['_fields'].items():
            self.assertIn(str(element.label), response.body)
        for survey in tpsurveys:
            self.assertIn('<option value="%s">%s</option>' % (survey, survey),
                          response.body)
コード例 #12
0
    def test_get(self):
        self.mock_login_admin()
        tpsurveys = db.list_external_surveys()
        form = ThirdPartyData()
        # make sure that at least this third party survey exist in the DB
        data = {
            'name': 'newTPsurvey',
            'description': 'akSJdghcakscmakld  fh',
            'url': 'www.google.com'
        }
        if len(tpsurveys) == 0:
            response = self.post('/ag_third_party/add/', data)

        response = self.get('/ag_third_party/data/')
        self.assertEqual(response.code, 200)
        # test that all fields are present in the HTML side.
        for key, element in form.__dict__['_fields'].items():
            self.assertIn(str(element.label), response.body)
        for survey in tpsurveys:
            self.assertIn('<option value="%s">%s</option>' % (survey, survey),
                          response.body)
        # roll back change to the DB
        self._clean_up_funcs.append(
            partial(db.ut_remove_external_survey, **data))
コード例 #13
0
    def test_post_select_surveys(self):
        self.mock_login_admin()
        response = self.post('/ag_pulldown/download/',
                             {'barcodes': ['000037555', '000065893',
                                           '000067690', '000037583',
                                           '000066526', '000031568'],
                              'blanks': [],
                              'external': [],
                              'selected_ag_surveys': [-2, -3, -8],
                              'merged': 'False'})
        # store the resulting zip archive to disc ...
        tmpfile = NamedTemporaryFile(mode='w', delete=False,
                                     prefix='metadata_pulldown_multiple_sel_',
                                     suffix='.zip')
        tmpfile.write(response.body)
        tmpfile.close()
        # ... and read the content as dict of strings
        result = extract_zip(tmpfile.name)
        self.assertItemsEqual(result.keys(),
                              ['failures.txt',
                               'survey_Fermented_Foods_md.txt',
                               'survey_Pet_Information_md.txt'])
        os.remove(tmpfile.name)

        # no blanks
        response = self.post('/ag_pulldown/download/',
                             {'barcodes': ('000001445', '000001446',
                                           '000001447', '000001448',
                                           '100001449', '000016180',
                                           '000015296', '000015297',
                                           '000015298', '000015299',
                                           '000015300', '000016280',
                                           '000016281', '000016282',
                                           '000016283', '000016284'),
                              'blanks': [],
                              'external': db.list_external_surveys()[:1]})
        self.assertEqual(response.code, 200)
        self.assertEqual(response.headers['Content-Disposition'],
                         'attachment; filename=metadata.zip')

        # no externals
        response = self.post('/ag_pulldown/download/',
                             {'barcodes': ['000001445',
                                           '000001446',
                                           '000001447',
                                           '000001448',
                                           '100001449',
                                           '000016180',
                                           '000015296',
                                           '000015297',
                                           '000015298',
                                           '000015299',
                                           '000015300',
                                           '000016280',
                                           '000016281',
                                           '000016282',
                                           '000016283',
                                           '000016284'],
                              'blanks': ['BLANK000001449',
                                         'BLANK000001453',
                                         'BLANK100001453'],
                              'external': []})
        self.assertEqual(response.code, 200)
        self.assertEqual(response.headers['Content-Disposition'],
                         'attachment; filename=metadata.zip')
コード例 #14
0
 def get(self):
     form = ThirdPartyData()
     form.survey.choices = [(x, x) for x in db.list_external_surveys()]
     self.render("ag_third_party.html", the_form=form,
                 errors='')
コード例 #15
0
 def get(self):
     form = ThirdPartyData()
     form.survey.choices = [(x, x) for x in db.list_external_surveys()]
     self.render("ag_third_party.html", the_form=form, errors='')
コード例 #16
0
ファイル: ag_pulldown.py プロジェクト: biocore/labadmin
 def get(self):
     surveys = db.list_external_surveys()
     self.render("ag_pulldown.html", currentuser=self.current_user,
                 barcodes=[], surveys=surveys, errors='')
コード例 #17
0
    def test_post(self):
        self.mock_login_admin()
        response = self.post('/ag_pulldown/download/',
                             {'barcodes': ['000001445',
                                           '000001446',
                                           '000001447',
                                           '000001448',
                                           '100001449',
                                           '000016180',
                                           '000015296',
                                           '000015297',
                                           '000015298',
                                           '000015299',
                                           '000015300',
                                           '000016280',
                                           '000016281',
                                           '000016282',
                                           '000016283',
                                           '000016284'],
                              'blanks': ['BLANK000001449',
                                         'BLANK000001453',
                                         'BLANK100001453'],
                              'external': db.list_external_surveys()[:1]})
        self.assertEqual(response.headers['Content-Disposition'],
                         'attachment; filename=metadata.zip')
        self.assertIn('failures.txt', response.body)
        self.assertIn('survey_1_md.txt', response.body)

        # no blanks
        response = self.post('/ag_pulldown/download/',
                             {'barcodes': ['000001445',
                                           '000001446',
                                           '000001447',
                                           '000001448',
                                           '100001449',
                                           '000016180',
                                           '000015296',
                                           '000015297',
                                           '000015298',
                                           '000015299',
                                           '000015300',
                                           '000016280',
                                           '000016281',
                                           '000016282',
                                           '000016283',
                                           '000016284'],
                              'blanks': '',
                              'external': db.list_external_surveys()[:1]})
        self.assertEqual(response.code, 200)
        self.assertEqual(response.headers['Content-Disposition'],
                         'attachment; filename=metadata.zip')

        # no externals
        response = self.post('/ag_pulldown/download/',
                             {'barcodes': ['000001445',
                                           '000001446',
                                           '000001447',
                                           '000001448',
                                           '100001449',
                                           '000016180',
                                           '000015296',
                                           '000015297',
                                           '000015298',
                                           '000015299',
                                           '000015300',
                                           '000016280',
                                           '000016281',
                                           '000016282',
                                           '000016283',
                                           '000016284'],
                              'blanks': ['BLANK000001449',
                                         'BLANK000001453',
                                         'BLANK100001453'],
                              'external': ''})
        self.assertEqual(response.code, 200)
        self.assertEqual(response.headers['Content-Disposition'],
                         'attachment; filename=metadata.zip')