예제 #1
0
def test_user_agent():
    api = Dhis('https://play.dhis2.org/demo',
               'admin',
               'district',
               30,
               user_agent='customLib/0.0.1')
    assert 'user-agent' in api.session.headers and api.session.headers[
        'user-agent'] == 'customLib/0.0.1'
예제 #2
0
def test_from_auth_file_in_dhishome(auth_file_in_dhishome):
    home = os.path.join(os.path.expanduser(os.path.join('~')))
    dhis_home = os.path.join(home, 'tomcat-dhis-test-524')
    kwargs = {'DHIS_HOME': dhis_home}
    with override_environ(**kwargs):
        api = Dhis.from_auth_file()
        assert api.base_url == 'https://play.dhis2.org/demo'
        assert api.username == 'admin'
예제 #3
0
def test_session():
    api = Dhis('https://play.dhis2.org/demo', 'admin', 'district')
    assert isinstance(api.session, requests.Session)
예제 #4
0
def test_user_agent_not_set():
    api = Dhis('https://play.dhis2.org/demo', 'admin', 'district', 30)
    assert 'user-agent' in api.session.headers and api.session.headers[
        'user-agent']
예제 #5
0
def test_base_url_api_version_below_25():
    with pytest.raises(exceptions.ClientException):
        Dhis('https://play.dhis2.org/demo', 'admin', 'district', 24)
예제 #6
0
def test_base_url_api_version_non_integer():
    with pytest.raises(exceptions.ClientException):
        Dhis('https://play.dhis2.org/demo', 'admin', 'district',
             '123notanumber')
예제 #7
0
def test_base_url_api_version():
    api = Dhis('https://play.dhis2.org/demo', 'admin', 'district', 30)
    assert api.api_url == 'https://play.dhis2.org/demo/api/30'
    assert api.username == 'admin'
예제 #8
0
def test_base_url_with_api():
    with pytest.raises(exceptions.ClientException):
        Dhis('https://play.dhis2.org/demo/api', 'admin', 'district')
예제 #9
0
def test_api_url(entered, expected):
    api = Dhis(entered, 'admin', 'district')
    assert api.base_url == expected
    assert api.username == 'admin'
    assert '{}/api'.format(api.base_url) == '{}/api'.format(expected)
예제 #10
0
def test_str():
    api = Dhis('https://play.dhis2.org/demo', 'admin', 'district')
    assert str(api).startswith('DHIS2')
예제 #11
0
def test_from_auth_file_not_found():
    kwargs = {}
    with override_environ(**kwargs) and pytest.raises(
            exceptions.ClientException):
        Dhis.from_auth_file('not_here.json')
예제 #12
0
def api_with_api_version():
    return Dhis(BASEURL, 'admin', 'district', api_version=30)
예제 #13
0
def test_from_auth_file_in_home(auth_file_home):
    api = Dhis.from_auth_file()
    assert api.base_url == 'https://play.dhis2.org/demo'
    assert api.username == 'admin'
예제 #14
0
def test_from_auth_file_not_valid(auth_file_invalid):
    with pytest.raises(exceptions.ClientException):
        tmp = tempfile.gettempdir()
        filename = os.path.join(tmp, 'auth_test_invalid.json')
        Dhis.from_auth_file(location=filename)
예제 #15
0
def api():
    return Dhis(BASEURL, 'admin', 'district')
예제 #16
0
def test_from_auth_file_not_named(auth_file):
    tmp = tempfile.gettempdir()
    filename = os.path.join(tmp, 'auth_test.json')
    api = Dhis.from_auth_file(filename)
    assert api.base_url == 'https://play.dhis2.org/demo'
    assert api.username == 'admin'