Ejemplo n.º 1
0
def test_not_admin_failure(client, add_user):
    _ = add_user(role=ROLE_USER, log_him_in=True)

    publisher = add_publisher()
    _ = client.delete(endpoint=endpoint,
                      publisher_id=publisher.id,
                      check_status=403)
Ejemplo n.º 2
0
def test_default(client, add_user, role):
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)
    role_is_manager = role == ROLE_MANAGER

    name = f'User-{get_random_str()}'
    password = get_random_str()
    email = f'{get_random_str()}@new.com'
    data = dict(
        name=name,
        password=password,
        email=email,
        role=role,
    )

    if role_is_manager:
        publisher = add_publisher()
        data['publisher_id'] = publisher.id

    resp = client.post(
        endpoint=endpoint,
        data=data,
    )
    assert 'id' in resp
    instance = User.query.get(resp['id'])
    assert instance

    assert instance.name == name
    assert instance.email == email
    assert instance.role == role
    if role_is_manager:
        assert instance.publisher_id == publisher.id
Ejemplo n.º 3
0
def test_default(client, add_user, name, role, email):
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)

    user = add_user()
    data = dict(
        name=name,
        role=role,
        email=email,
    )
    if role == ROLE_MANAGER:
        publisher = add_publisher()
        data['publisher_id'] = publisher.id
    resp = client.put(
        endpoint=endpoint,
        user_id=user.id,
        data=data,
    )
    assert 'id' in resp
    assert resp['id'] == user.id
    new_user = User.query.get(resp['id'])
    assert new_user

    for var_name in ('name', 'email', 'role'):
        val = locals()[var_name]
        if val is not None:
            assert getattr(user, var_name) == val
Ejemplo n.º 4
0
def test_wrong_id_failure(client, add_user):
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)

    publisher = add_publisher()
    _ = client.get(endpoint=endpoint,
                   publisher_id=publisher.id + 100,
                   check_status=404)
Ejemplo n.º 5
0
def test_wrong_id_failure(client, add_user):
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)

    publisher = add_publisher()
    _ = client.delete(endpoint=endpoint,
                      publisher_id=129129129129192,
                      check_status=404)
    assert Publisher.query.get(publisher.id)
Ejemplo n.º 6
0
def test_default(client, add_user):
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)

    publisher = add_publisher()
    resp = client.delete(
        endpoint=endpoint,
        publisher_id=publisher.id,
    )
    assert 'id' in resp
    assert resp['id'] == publisher.id
    assert not Publisher.query.get(resp['id'])
Ejemplo n.º 7
0
def test_no_params_failure(client, add_user):
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)

    publisher = add_publisher()
    _ = client.put(endpoint=endpoint,
                   publisher_id=publisher.id,
                   check_status=400,
                   data=dict(
                       name=None,
                       comment=None,
                       airtime=None,
                   ))
Ejemplo n.º 8
0
def test_default(client, add_user):
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)

    publisher = add_publisher()
    resp = client.get(
        endpoint=endpoint
    )
    assert 'total' in resp
    assert resp['total'] == 1
    assert 'results' in resp
    assert len(resp['results']) == 1
    assert publisher.id == resp['results'][0]['id']
    assert 'created_by' not in resp['results'][0]
Ejemplo n.º 9
0
def test_search_mode(client, add_user):
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)

    # Create publishers
    test_cases = []
    all_ids = set()
    common_string = get_random_str(15)
    for params in [[f] for f in search_fields] + [search_fields]:
        # Add trash publishers to make some noise
        add_publisher(**{p: get_random_str() for p in params})
        
        # Add publishers with common string in params
        prefixed = common_string + get_random_str()
        postfixed = get_random_str() + common_string
        middle = get_random_str() + common_string + get_random_str()

        prefixed_id = add_publisher(**{p: prefixed for p in params}).id
        all_ids.update({
            prefixed_id,
            add_publisher(**{p: postfixed for p in params}).id,
            add_publisher(**{p: middle for p in params}).id,
        })
        test_cases.append((prefixed[:-1], {prefixed_id}))
    # Add common test case
    test_cases.append((common_string, all_ids))
    
    # Run test cases
    for query, publisher_ids in test_cases:
        resp = client.get(
            endpoint=endpoint,
            query=query,
            query_fields=[f for f in search_fields]
        )
        assert 'total' in resp
        assert resp['total'] == len(publisher_ids)

        assert 'results' in resp
        assert {r['id'] for r in resp['results']} == publisher_ids
Ejemplo n.º 10
0
def test_default(client, add_user):
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)

    publisher = add_publisher()
    resp = client.get(
        endpoint=endpoint,
        publisher_id=publisher.id,
    )
    assert 'id' in resp
    assert resp['id'] == publisher.id

    assert 'name' in resp
    assert resp['name'] == publisher.name

    assert 'created_by' not in resp
Ejemplo n.º 11
0
def test_malformed_params_failure(client, add_user, name, comment, airtime,
                                  param_name):
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)

    publisher = add_publisher()
    resp = client.put(endpoint=endpoint,
                      publisher_id=publisher.id,
                      data=dict(
                          name=name,
                          comment=comment,
                          airtime=airtime,
                      ),
                      check_status=400)
    assert 'errors' in resp
    assert len(resp['errors']) == 1
    assert param_name in resp['errors'][0].lower()
Ejemplo n.º 12
0
def test_search_mode_failure(client, add_user):
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)

    common_string = get_random_str(15)
    test_cases = [
        (add_publisher(**{p: get_random_str() + common_string}), p)
        for p in search_fields
    ]
    for publisher, param in test_cases:
        resp = client.get(
            endpoint=endpoint,
            query=common_string,
            query_fields=list(set(search_fields) - {param})
        )
        assert 'results' in resp
        assert publisher.id not in {r['id'] for r in resp['results']}
Ejemplo n.º 13
0
def test_user_publisher_id_field(client, add_user, role):
    """
    Checks that user can not update role to manager without publisher_id and admin with it
    """
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)
    user = add_user()

    data = dict(role=role)
    if role == ROLE_ADMIN:
        publisher = add_publisher()
        data['publisher_id'] = publisher.id
    resp = client.put(endpoint=endpoint,
                      user_id=user.id,
                      data=data,
                      check_status=400)
    assert 'errors' in resp
    assert len(resp['errors']) == 1
    assert 'publisher_id' in resp['errors'][0]
Ejemplo n.º 14
0
def test_file_publisher(client, add_user, role):
    """
    Checks that publisher_id is required for admin and shouldn`t be filled for manager
    """
    _ = add_user(role=role, log_him_in=True)
    data = dict(
        file=open('tests/data/FaceImage.jpg', 'rb'),
        comment=get_random_str(256),
    )
    if role == ROLE_MANAGER:
        publisher = add_publisher()
        data['publisher_id'] = publisher.id
    resp = client.post(endpoint=endpoint,
                       content_type='multipart/form-data',
                       data=data,
                       check_status=400)
    assert 'errors' in resp
    assert len(resp['errors']) == 1
    assert 'publisher_id' in resp['errors'][0]
Ejemplo n.º 15
0
def test_user_publisher_id_field(client, add_user, role):
    """
    Checks that user can not add manager without publisher_id and admin with it
    """
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)

    name = f'User-{get_random_str()}'
    password = get_random_str()
    email = f'{get_random_str()}@new.com'
    data = dict(
        name=name,
        password=password,
        email=email,
        role=role,
    )
    if role == ROLE_ADMIN:
        publisher = add_publisher()
        data['publisher_id'] = publisher.id
    resp = client.post(endpoint=endpoint, data=data, check_status=400)
    assert 'errors' in resp
    assert len(resp['errors']) == 1
    assert 'publisher_id' in resp['errors'][0]
Ejemplo n.º 16
0
def test_default(client, add_user, name, comment, airtime):
    _ = add_user(role=ROLE_ADMIN, log_him_in=True)

    publisher = add_publisher()
    resp = client.put(endpoint=endpoint,
                      publisher_id=publisher.id,
                      data=dict(
                          name=name,
                          comment=comment,
                          airtime=airtime,
                      ))
    assert 'id' in resp
    assert resp['id'] == publisher.id
    updated_publisher = Publisher.query.get(resp['id'])
    assert updated_publisher

    assert 'name' in resp
    assert updated_publisher.name == name == resp['name']

    assert 'comment' in resp
    assert updated_publisher.comment == comment == resp['comment']

    assert 'airtime' in resp
    assert updated_publisher.airtime == airtime == resp['airtime']