def test_api_task_create_two_tasks_with_same_title(api, new_user,
                                                   unique_task_title):
    """
    1. Sign in.
    2. Create a task with a unique title
    3. Create a task with the same title (shall fail)
    """
    api.authenticate(new_user.username, new_user.password)
    api.create_task(Task(unique_task_title))
    with pytest.raises(TodoAppApiException):
        api.create_task(Task(unique_task_title))
def test_api_task_create_two_tasks_with_same_tag(api, new_user,
                                                 unique_task_title,
                                                 unique_tag_name):
    """
    1. Sign in.
    2. Create a task with a unique title and a unique tag
    3. Create a task with another title and the same tag
    """
    api.authenticate(new_user.username, new_user.password)
    task1 = api.create_task(
        Task(f"{unique_task_title}1", [Tag(unique_tag_name)]))
    task2 = api.create_task(
        Task(f"{unique_task_title}2", [Tag(unique_tag_name)]))
    assert task1.tags[0].name == unique_tag_name
    assert task2.tags[0].name == unique_tag_name
예제 #3
0
def test_api_conf_token_expiration(api, default_user, unique_task_title):
    """
    1. Authenticate with the default user's credentials (using token mode).
    2. Wait 30 seconds and create a task (x19)
    3. Wait for 30 seconds.
    3. Create a task. (shall fail)
    """
    token = api.authenticate(default_user.username, default_user.password, mode="token")
    assert token.username == default_user.username
    for i in range(19):
        time.sleep(30)
        api.create_task(Task(f"{unique_task_title}{i}"))
    time.sleep(30)
    with pytest.raises(TodoAppApiException) as e_info:
        api.create_task(Task(f"{unique_task_title}{i+1}"))
    assert "HTTP 401" in str(e_info.value)
def test_api_task_create_task_anonymous(api, unique_task_title):
    """
    1. Create a task (user not authentified) (shall fail)
    """
    with pytest.raises(TodoAppApiException) as e_info:
        api.create_task(Task(unique_task_title))
    assert "HTTP 401" in str(e_info.value)
def test_api_task_create_task_empty_title(api, new_user):
    """
    1. Sign in.
    2. Create a task with an empty title
    """
    api.authenticate(new_user.username, new_user.password)
    task = api.create_task(Task(""))
    assert task.title == ""
def test_api_task_create_task_with_a_too_long_title(
        api, new_user, unique_task_title_too_long):
    """
    1. Sign in.
    2. Create a task with a unique title with 21 characters (shall fail).
    """
    api.authenticate(new_user.username, new_user.password)
    with pytest.raises(TodoAppApiException):
        api.create_task(Task(unique_task_title_too_long))
def test_api_task_create_task(api, new_user, unique_task_title):
    """
    1. Sign in.
    2. Create a task with no tag.
    """
    api.authenticate(new_user.username, new_user.password)
    task = api.create_task(Task(unique_task_title))
    assert task.title == unique_task_title
    assert len(task.tags) == 0
def test_api_authentication_failed_basic(api, username, password,
                                         unique_task_title):
    """
    1.  Sign in with bad credentials using basic mode
    2. Create a task (shall fail).
    """
    api.authenticate(username, password, mode="basic")
    with pytest.raises(TodoAppApiException) as e_info:
        api.create_task(Task(unique_task_title))
    assert "HTTP 401" in str(e_info.value)
def test_api_task_create_task_with_one_tag(api, new_user, unique_task_title,
                                           unique_tag_name):
    """
    1. Sign in.
    2. Create a task with one tag.
    """
    api.authenticate(new_user.username, new_user.password)
    task = api.create_task(Task(unique_task_title, [Tag(unique_tag_name)]))
    assert task.title == unique_task_title
    assert task.tags[0].name == unique_tag_name
예제 #10
0
def test_api_task_create_task_with_a_long_title(api, new_user,
                                                unique_task_title):
    """
    1. Sign in.
    2. Create a task with a unique title with 20 characters.
    """
    api.authenticate(new_user.username, new_user.password)
    long_title = f"{unique_task_title}{'A'*20}"[:20]
    task = api.create_task(Task(long_title))
    assert task.title == long_title
예제 #11
0
def test_api_task_create_task_with_many_tags(api, new_user, unique_task_title,
                                             unique_tag_name):
    """
    1. Sign in.
    2. Create a task with two tags.
    """
    api.authenticate(new_user.username, new_user.password)
    tag_names = [f"{unique_tag_name}1", f"{unique_tag_name}2"]
    task = api.create_task(
        Task(unique_task_title, [Tag(name) for name in tag_names]))
    assert task.title == unique_task_title
    assert set(tag_names) == set([tag.name for tag in task.tags])
예제 #12
0
def new_task_done_three_tags(base_url, new_user):
    api = TodoAppAPI(base_url)
    api.authenticate(new_user.username, new_user.password)
    task = api.create_task(
        Task(
            random_name(16),
            [Tag(random_name(16)),
             Tag(random_name(16)),
             Tag(random_name(16))],
        ))
    task.done = True
    updated_task = api.update_task(task.id, task)
    return updated_task
def test_api_authentication_success_basic(api, default_user,
                                          unique_task_title):
    """
    1. Sign in with the default user's credentials (using basic mode).
    2. Create a task.
    """
    # TODO ask developers to add a /me endpoint in order to make the authentication
    # tests cleaner when using the basic mode - instead we have to create task in order
    # to check if we are authenticated
    api.authenticate(default_user.username,
                     default_user.password,
                     mode="basic")
    api.create_task(Task(unique_task_title))
예제 #14
0
def new_task(base_url, new_user):
    api = TodoAppAPI(base_url)
    api.authenticate(new_user.username, new_user.password)
    task = api.create_task(Task(random_name(16), [Tag(random_name(16))]))
    return task