def test_urls(self, params):
     with requests_mock.Mocker():
         with pytest.raises(NoMockAddress) as excinfo:
             with OmeroRequests() as oreq:
                 oreq.configure("mock://test.com")
                 oreq.connect(**params['kwargs'])
         assert str(excinfo.value).endswith(params['error'])
 def test_domain(self, params):
     with requests_mock.Mocker():
         with pytest.raises(NoMockAddress) as excinfo:
             with OmeroRequests() as oreq:
                 oreq.configure(params['domain'])
                 oreq.connect()
         error = ("%s/webclient/" % params['domain'].rstrip("/"))
         assert str(excinfo.value).endswith(error)
    def test_basic_async(self, m):
        with OmeroRequests() as oreq:
            oreq.configure("mock://test.com")
            m.get(oreq.urls['index'], text='index')
            m.get(oreq.urls['login'], text='login')
            oreq.connect()

            plateurls = []
            for i in xrange(0, 10):
                thumb_url = oreq.prepare_url(
                    "/webgateway/render_thumbnail/%i/" % i)
                m.get(thumb_url, content='thumbnail_%i' % i)
                plateurls.append(thumb_url)
            oreq.async_requests(urls=plateurls)
    def test_token(self, token):
        with requests_mock.Mocker() as m:
            with OmeroRequests() as oreq:
                oreq.configure("mock://test.com")
                m.get(oreq.urls['index'], text='index')
                m.get(oreq.urls['login'], text='login')

                auth = oreq.prepare_url(
                    "?server={server}&bsession={bsession}",
                    {
                        'server': oreq.config['server'],
                        'bsession': token
                    })

                m.get(auth, text='auth')
                oreq.connect(token=token)
    def test_basic(self, m):
        with OmeroRequests() as oreq:
            oreq.configure("mock://test.com")
            m.get(oreq.urls['index'], text='index')
            m.get(oreq.urls['login'], text='login')
            oreq.connect()

            thumb_url = oreq.prepare_url(
                "/webgateway/render_thumbnail/12345/")
            m.get(thumb_url, content='12345')
            assert oreq.session.get(thumb_url).content == "12345"
            assert oreq.session.get(thumb_url).status_code == 200

            thumb_url = oreq.prepare_url("/webgateway/render_thumbnail/0000/")
            m.get(thumb_url, status_code=404)
            assert oreq.session.get(thumb_url).status_code == 404
Example #6
0
    try:
        username = args.username
        password = args.password
    except:
        username = None
        password = None

    try:
        token = args.token
    except:
        token = None

    LOG_FILENAME = 'cache-screen-%s.log' % screen_id
    logging.basicConfig(filename=LOG_FILENAME, level=logging.DEBUG)

    with OmeroRequests() as oreq:
        oreq.configure(domain)
        oreq.connect(token=token, username=username, password=password)

        _url = oreq.prepare_url(PLATES_URL, {'screen_id': screen_id})
        grsps = oreq.async_requests(urls=[_url])

        for grsp in grsps:
            for pl in grsp.json()['plates']:
                plate_id = pl['id']
                child_count = fields or pl['childCount']
                child_count = 1 if child_count == 0 else child_count
                plateurl = []
                for run_id in xrange(0, child_count):
                    _u = oreq.prepare_url(WELLS_IMAGES_URL, {
                        'plate_id': plate_id,