Example #1
0
    def setUp(self):

        self.schema_url = "http://localhost:3000/api/v1/schema"
        self.schema_file = resource_string(__name__,
                                           'data/schema.json').decode('utf-8')
        responses.add(responses.GET,
                      self.schema_url,
                      json=json.loads(self.schema_file))
        self.api = Api(base_url="http://localhost:3000",
                       api_key='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')

        self.uuid_one = "4a668ac6daf74364"
        self.uuid_two = "d61f459d077d4cd0"

        self.classification_one = resource_string(
            __name__,
            "data/api/{}.json".format(self.uuid_one)).decode('utf-8')  # noqa
        self.table_one = resource_string(
            __name__, "data/api/{}_table.json".format(self.uuid_one)).decode(
                'utf-8')  # noqa

        self.classification_two = resource_string(
            __name__,
            "data/api/{}.json".format(self.uuid_two)).decode('utf-8')  # noqa
        self.table_two = resource_string(
            __name__, "data/api/{}_table.json".format(self.uuid_two)).decode(
                'utf-8')  # noqa

        self.classification_one_url = "http://localhost:3000/api/v1/classifications/4a668ac6daf74364"
        self.classification_one_table_url = "http://localhost:3000/api/v1/classifications/4a668ac6daf74364/results"

        self.classification_two_url = "http://localhost:3000/api/v1/classifications/d61f459d077d4cd0"
        self.classification_two_table_url = "http://localhost:3000/api/v1/classifications/d61f459d077d4cd0/results"
Example #2
0
    def from_notebook_node(self, nb, resources=None, **kw):
        """Takes PDF output from PDFExporter and uploads to One Codex Documents portal."""
        output, resources = super(OneCodexDocumentExporter, self).from_notebook_node(
            nb, resources=resources, **kw
        )

        from onecodex import Api
        from onecodex.lib.upload import _upload_document_fileobj

        ocx = Api()

        default_filename = "Analysis Report - {dt:%B} {dt.day}, {dt:%Y}".format(
            dt=datetime.datetime.now()
        )

        file_name = resources["metadata"].get("one_codex_doc_portal_filename", default_filename)

        try:
            document_id = _upload_document_fileobj(
                BytesIO(output), file_name, ocx._client.session, ocx.Documents._resource
            )
        except UploadException as exc:
            resp = json.dumps({"status": 500, "message": str(exc)})
            return resp, resources
        except Exception:
            resp = json.dumps(
                {
                    "status": 500,
                    "message": "Upload failed. Please contact [email protected] for assistance.",
                }
            )
            return resp, resources

        resp = json.dumps({"status": 200, "document_id": document_id})
        return resp, resources
Example #3
0
def ocx():
    """Instantiated API client
    """
    with mock_requests(SCHEMA_ROUTES):
        return Api(api_key='1eab4217d30d42849dbde0cd1bb94e39',
                   base_url='http://localhost:3000',
                   cache_schema=False)
Example #4
0
def test_api_creation(api_data):
    ocx = Api(
        api_key="1eab4217d30d42849dbde0cd1bb94e39",
        base_url="http://localhost:3000",
        cache_schema=False,
    )
    assert isinstance(ocx, Api)
    assert True
Example #5
0
 def setUp(self):
     self.schema_url = "http://localhost:3000/api/v1/schema"
     self.schema_file = resource_string(__name__,
                                        'data/schema.json').decode('utf-8')
     responses.add(responses.GET,
                   self.schema_url,
                   json=json.loads(self.schema_file))
     self.api = Api(base_url="http://localhost:3000",
                    api_key='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
Example #6
0
def ocx_w_raven():
    patched_env = {
        'ONE_CODEX_API_BASE': 'http://*****:*****@sentry.example.com/1',
    }
    with mock.patch.dict(os.environ, patched_env):
        with mock_requests(SCHEMA_ROUTES):
            return Api(cache_schema=False, telemetry=True)
Example #7
0
def ocx_w_raven():
    patched_env = os.environ.copy()
    patch = {
        "ONE_CODEX_API_BASE": "http://*****:*****@sentry.example.com/1",
        "ONE_CODEX_NO_TELEMETRY": None,
    }

    patched_env.update(patch)

    with mock.patch.object(os, "environ", patched_env):
        with mock_requests(SCHEMA_ROUTES):
            return Api(cache_schema=False, telemetry=True)
Example #8
0
    def setUp(self):
        self.schema_url = "http://localhost:3000/api/v1/schema"
        self.schema_file = resource_string(__name__,
                                           'data/schema.json').decode('utf-8')
        responses.add(responses.GET,
                      self.schema_url,
                      json=json.loads(self.schema_file))
        self.api = Api(base_url="http://localhost:3000",
                       api_key='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')

        self.num_complete = 2
        self.num_incomplete = 1

        self.complete_analyses = resource_string(
            __name__, 'data/api/complete_analyses.json').decode('utf-8')

        self.incomplete_analyses = resource_string(
            __name__, 'data/api/incomplete_analyses.json').decode('utf-8')

        self.sample = resource_string(__name__,
                                      'data/api/sample.json').decode('utf-8')
        self.metadata = resource_string(
            __name__, 'data/api/metadata.json').decode('utf-8')

        self.uuid_one = '1'
        self.analysis_one = resource_string(
            __name__, 'data/api/complete_analysis_one.json').decode('utf-8')

        self.uuid_two = '2'
        self.analysis_two = resource_string(
            __name__, 'data/api/complete_analysis_two.json').decode('utf-8')

        self.uuid_three = '3'
        self.analysis_three = resource_string(
            __name__, 'data/api/incomplete_analysis_one.json').decode('utf-8')

        # URLS for responses
        self.analysis_one_url = 'http://localhost:3000/api/v1/analyses/1'
        self.analysis_two_url = 'http://localhost:3000/api/v1/analyses/2'
        self.analysis_three_url = 'http://localhost:3000/api/v1/analyses/3'
        self.complete_url = 'http://localhost:3000/api/v1/analyses?per_page=200&where=%7B%22complete%22%3A+true%7D&page=1'
        self.complete_url_new = 'http://localhost:3000/api/v1/analyses?sort=%7B%7D&per_page=200&where=%7B%22complete%22%3A+true%7D&page=1'
        self.incomplete_url = 'http://localhost:3000/api/v1/analyses?per_page=200&where=%7B%22complete%22%3A+false%7D&page=1'
        self.incomplete_url_new = 'http://localhost:3000/api/v1/analyses?sort=%7B%7D&per_page=200&where=%7B%22complete%22%3A+false%7D&page=1'
        self.sample_url = 'http://localhost:3000/api/v1/samples/d66e901ea9854f1f'
        self.metadata_url = 'http://localhost:3000/api/v1/metadata/50fd2f0513d34372'
Example #9
0
def test_bearer_auth_from_env(api_data, monkeypatch):
    monkeypatch.setenv("ONE_CODEX_BEARER_TOKEN", "mysecrettoken")
    ocx = Api(base_url="http://localhost:3000", cache_schema=True)
    assert isinstance(ocx._req_args["auth"], BearerTokenAuth)
    sample = ocx.Samples.get("761bc54b97f64980")
    assert sample.visibility != "public"
Example #10
0
def test_api_key_auth_from_kwargs(api_data):
    ocx = Api(api_key="mysecretkey", base_url="http://localhost:3000", cache_schema=True)
    assert isinstance(ocx._req_args["auth"], HTTPBasicAuth)
Example #11
0
def test_bearer_auth_from_kwargs(api_data):
    ocx = Api(bearer_token="mysecrettoken", base_url="http://localhost:3000", cache_schema=True)
    assert isinstance(ocx._req_args["auth"], BearerTokenAuth)
Example #12
0
def test_api_key_auth_from_env(api_data, monkeypatch):
    monkeypatch.setenv("ONE_CODEX_API_KEY", "mysecretkey")
    ocx = Api(base_url="http://localhost:3000", cache_schema=True)
    assert isinstance(ocx._req_args["auth"], HTTPBasicAuth)
Example #13
0
def test_bearer_auth_from_env(api_data, monkeypatch):
    monkeypatch.setenv('ONE_CODEX_BEARER_TOKEN', 'mysecrettoken')
    ocx = Api(base_url='http://localhost:3000', cache_schema=True)
    assert isinstance(ocx._req_args['auth'], BearerTokenAuth)
    sample = ocx.Samples.get('761bc54b97f64980')
    assert sample.visibility != 'public'
Example #14
0
def test_api_key_auth_from_kwargs(api_data):
    ocx = Api(api_key='mysecretkey',
              base_url='http://localhost:3000',
              cache_schema=True)
    assert isinstance(ocx._req_args['auth'], HTTPBasicAuth)
Example #15
0
def test_api_key_auth_from_env(api_data, monkeypatch):
    monkeypatch.setenv('ONE_CODEX_API_KEY', 'mysecretkey')
    ocx = Api(base_url='http://localhost:3000', cache_schema=True)
    assert isinstance(ocx._req_args['auth'], HTTPBasicAuth)