예제 #1
0
def test_upload_and_download_file(root_token):

    response = requests.post(uri('/repositories'),
                             json={'name': generate_string(8)},
                             headers=token_header(root_token))
    assert response.status_code == 201
    repository_id = response.json()['id']

    with open('file.txt', 'wb') as f:
        f.write('this is some text')
    with open('file.txt', 'rb') as f:
        response = requests.post(uri(
            '/repositories/{}/files'.format(repository_id)),
                                 files={'file': f},
                                 data={
                                     'type': 'text',
                                     'modality': 'none'
                                 },
                                 headers=token_header(root_token))
        assert response.status_code == 201
        file_id = response.json()['id']
    os.system('rm file.txt')

    response = requests.get(uri('/repositories/{}/files/{}/content'.format(
        repository_id, file_id)),
                            headers=token_header(root_token))
    assert response.status_code == 200
    assert response.content == 'this is some text'
예제 #2
0
def root_token():

    # Create root token
    response = requests.post(uri('/tokens'),
                             headers=login_header('root', 'secret'))
    token = response.json()['token']
    # This fixture also creates a default user
    response = requests.get(uri('/users?username=user'),
                            headers=token_header(token))
    if len(response.json()) == 0:
        requests.post(uri('/users'),
                      json={
                          'username': '******',
                          'password': '******',
                          'email': '*****@*****.**'
                      },
                      headers=token_header(token))
    # Return root token
    yield token
    # This code will be executed after the fixture loses scope, i.e., when tests finish. This only
    # works if the previous line 'yields' the result instead of 'returns' it.
    response = requests.get(uri('/users?username=user'),
                            headers=token_header(token))
    if len(response.json()) > 0:
        requests.delete(uri('/users/{}'.format(response.json()[0]['id'])),
                        headers=token_header(token))
예제 #3
0
def test_create_user_with_missing_required_fields(root_token):

    username = generate_string(8)
    response = requests.post(uri('/users'),
                             json={'username': username},
                             headers=token_header(root_token))
    assert response.status_code == 400
예제 #4
0
def test_create_user_not_allowed(user_token):

    response = requests.post(uri('/users'),
                             json={
                                 'username': '******',
                                 'password': '******',
                                 'email': '*****@*****.**'
                             },
                             headers=token_header(user_token))
    assert response.status_code == 403
예제 #5
0
def test_create_user_already_exists(root_token):

    response = requests.post(uri('/users'),
                             json={
                                 'username': '******',
                                 'password': '******',
                                 'email': '*****@*****.**'
                             },
                             headers=token_header(root_token))
    assert response.status_code == 400