예제 #1
0
def test_hub_build_pull():
    args = set_hub_build_parser().parse_args(
        [os.path.join(cur_dir, 'hub-mwu'), '--push', '--test-uses', '--raise-error'])
    HubIO(args).build()

    args = set_hub_pushpull_parser().parse_args(['jinahub/pod.dummy_mwu_encoder'])
    HubIO(args).pull()

    args = set_hub_pushpull_parser().parse_args(['jinahub/pod.dummy_mwu_encoder:0.0.6'])
    HubIO(args).pull()
예제 #2
0
def test_hub_build_pull(mocker, monkeypatch, tmpdir, dummy_access_token):

    mock = mocker.Mock()

    def _mock_get(url, headers):
        mock(url=url, headers=headers)
        return MockResponse(response_code=requests.codes.ok)

    def _mock_post(url, headers, data):
        mock(url=url, headers=headers, data=data)
        return MockResponse(response_code=requests.codes.ok)

    def _mock_home():
        return Path(str(tmpdir))

    monkeypatch.setattr(Path, 'home', _mock_home)
    monkeypatch.setattr(requests, 'get', _mock_get)
    monkeypatch.setattr(requests, 'post', _mock_post)
    monkeypatch.setattr(HubIO, '_docker_login', mock)

    args = set_hub_build_parser().parse_args(
        [os.path.join(cur_dir, 'hub-mwu'), '--push', '--raise-error'])
    HubIO(args).build()

    args = set_hub_pushpull_parser().parse_args(
        ['jinahub/pod.dummy_mwu_encoder:0.0.6'])
    HubIO(args).pull()
예제 #3
0
def test_login(tmpdir, monkeypatch, mocker):
    import requests
    import webbrowser
    from pathlib import Path

    class MockResponse:
        def __init__(self, content):
            self.content = content

        def json(self):
            return self.content

        def status_code(self):
            return requests.codes.ok

    mock = mocker.Mock()

    def _mock_post(url, headers, data):
        mock(url=url, headers=headers, data=data)
        resp = {
            'device_code': 'device',
            'user_code': 'user',
            'verification_uri': 'verification',
            'access_token': 'access',
        }
        return MockResponse(resp)

    def _mock_home():
        return Path(str(tmpdir))

    args = set_hub_pushpull_parser()
    monkeypatch.setattr(requests, 'post', _mock_post)
    monkeypatch.setattr(webbrowser, 'open', None)
    monkeypatch.setattr(Path, 'home', _mock_home)
    HubIO(args).login()
    device_request_kwargs = mock.call_args_list[0][1]
    assert device_request_kwargs[
        'url'] == 'https://github.com/login/device/code'
    assert device_request_kwargs['headers'] == {'Accept': 'application/json'}
    assert 'client_id' in device_request_kwargs['data']
    assert 'scope' in device_request_kwargs['data']

    access_request_kwargs = mock.call_args_list[1][1]
    assert access_request_kwargs[
        'url'] == 'https://github.com/login/oauth/access_token'
    assert access_request_kwargs['headers'] == {'Accept': 'application/json'}
    assert 'client_id' in access_request_kwargs['data']
    assert 'device_code' in access_request_kwargs['data']
    assert access_request_kwargs['data']['device_code'] == 'device'

    list_dir = os.listdir(str(tmpdir))
    assert '.jina' in list_dir
    jina_subfolder = os.path.join(str(tmpdir), '.jina')
    assert Path(os.path.join(jina_subfolder, 'access.yml')).exists()
    with open(os.path.join(jina_subfolder, 'access.yml')) as fp:
        assert fp.read() == 'access_token: access\n'
예제 #4
0
def test_hub_pull():
    args = set_hub_pushpull_parser().parse_args(['jinahub/pod.dummy_mwu_encoder:0.0.6'])
    HubIO(args).pull()