コード例 #1
0
    def post_request(self):
        """Make stack analyses POST request."""
        logger.info(
            'SA Post request with ecosystem: %s manifest: %s path: %s '
            'show_transitive: %s', self.params.ecosystem,
            self.params.manifest.filename, self.params.file_path,
            self.params.show_transitive)
        # Build manifest file info.
        self._manifest_file_info = {
            'filename': self.params.manifest.filename,
            'filepath': self.params.file_path,
            'content': self.params.manifest.read().decode('utf-8')
        }
        logger.debug('manifest_file_info: %s', self._manifest_file_info)

        # Generate unique request id using UUID, also record timestamp in readable form
        self._new_request_id = str(uuid.uuid4().hex)
        date_str = str(datetime.datetime.now())

        # Make backbone request
        deps = self._make_backbone_request()

        # Finally save results in RDS and upon success return request id.
        rdbAnalyses = RdbAnalyses(self._new_request_id, date_str,
                                  self._manifest_file_info, deps)
        rdbAnalyses.save_post_request()
        data = {
            'status': 'success',
            'submitted_at': date_str,
            'id': self._new_request_id
        }
        logger.info('%s response: %s', self._new_request_id, data)
        return data
コード例 #2
0
 def test_save_post_request_success(self, _commit, _execute):
     """Test success save request."""
     rdbAnalyses = RdbAnalyses('dummy_request_id', '', {}, {})
     self.assertEqual(rdbAnalyses.save_post_request(), None)
コード例 #3
0
 def test_save_post_request_error(self, _execute):
     """Test error save request that raises exception."""
     rdbAnalyses = RdbAnalyses('dummy_request_id', '', {}, {})
     with pytest.raises(Exception) as exception:
         rdbAnalyses.save_post_request()
     self.assertIs(exception.type, RDBSaveException)