Beispiel #1
0
def test_get_comments_category_byid():
    """
        Verify status code and content of the response.
    """
    category = CateGory()
    cat_id = category.get_rand_category_from_collection()['id']
    response = category.get_comments_category_byid(cat_id)
    collection = (response.json())
    # Verifying the ID used as input does exist in the record
    assert collection["id"] == cat_id \
        and response.status_code == 200, 'Record not returned successfully'
Beispiel #2
0
def test_get_comments_categories():
    """
        Verify status code and content of the response.
    """
    category = CateGory()
    response = category.get_all_categories_from_collection()
    collection = response.json()
    # Verifying a random record from the collection
    random_index = random.randrange(len(collection))
    random_id = collection[random_index]['id']
    assert any(d.get('id', None) == random_id for d in collection) \
        and response.status_code == 200, 'Get for all records was not successful'
Beispiel #3
0
def test_put_comments_category_byid():
    """
        Verify status code and content of the response.
    """
    category = CateGory()
    cat_id = category.get_rand_category_from_collection()['id']
    payload = {'name': 'Test_AN_UPDATE_HERE'}
    headers = {'content-type': 'application/json'}
    response_u = category.put_comments_post_byid(cat_id, payload, headers)
    # Verify the PUT/update on the selected record from the collection
    response = category.get_all_categories_from_collection()
    collection = response.json()
    assert any(d.get('id', None) == cat_id
               and d.get('name', None) == 'Test_AN_UPDATE_HERE' for d in collection) \
        and response_u.status_code == 204, 'Update for the record failed'
def test_post_comments_category():
    """
        Add a new record
        Verify status code and content of the response.
    """
    # Data to be sent to api
    payload = {'name': 'Tibetan Monk'}

    category = CateGory()
    response_p = category.post_comments_category(payload, headers=HEADERS)
    # Verify - POST record is not added to the collection
    response = category.get_all_categories_from_collection()
    collection = response.json()
    assert any(d.get('name', None) == payload['name'] for d in collection)\
           and response_p.status_code == 201, 'Post was not successful'
def test_delete_comments_category_byid_asso_wt_post():
    """
        Verify:
            1]Status code
            2] Category is not deleted
    """
    # Randomly generated id from the existing collection
    post = Post()
    category = CateGory()
    cat_id = post.get_category_assoc_wth_post()
    response = category.delete_comments_category_byid(cat_id)
    # Verify the status code, and the delete was not allowed
    # Do not know the error code for illegal delete. So negating a success code
    response = category.get_all_categories_from_collection()
    collection = response.json()
    assert any(d.get('id', None) == cat_id for d in collection) \
        and response.status_code != 204, 'Category associated with a post was incorrectly deleted'
def test_post_comm_categ_limit_of_101():
    """
    1]Add up to 101 records with unique names.
    2]Verify no more than 100 categories can be added
    to the collection
    """
    category = CateGory()
    # Get collection and length
    response = category.get_all_categories_from_collection()
    collection = response.json()
    index_lm = len(collection) + 1
    while index_lm <= 101:
        category_name = 'unique_' + str(index_lm)
        if not any(d.get('name', None) == category_name for d in collection):
            payload = {'name': category_name}
            category.post_comments_category(payload, headers=HEADERS)
            # Delay for post to occur gracefully
            time.sleep(1)
            index_lm += 1
    # Deleting the records added - from above. Need to have open slots for other test cases.
    # print('deleting records')
    response = category.get_all_categories_from_collection()
    collection = response.json()
    print(list(collection))
    end = len(collection)
    print(end)
    for index in range(0, end):
        if 'unique' in collection[index]['name']:
            print(collection[index])
            response = category.delete_comments_category_byid(collection[index]['id'])
            assert response.status_code == 204
    # The 100th record should 201 and 101th should not.
    assert end > 100, '100 limit not enforced'
def test_post_comm_categ_nm_unique():
    """
        Verify:
            Status code of Success is not returned
            Category Name is not added to the collection.
    """
    category = CateGory()
    # Record randomly picked from the existing collection
    # The Name of this record is passed in the Payload to test
    # for name uniqueness
    a_category = category.get_rand_category_from_collection()
    # Value for key Name: from the randomly selected record to be passed
    # in PAYLOAD
    category_name = a_category['name']
    payload = {'name': category_name}
    response_p = category.post_comments_category(payload, headers=HEADERS)
    # Verify - POST record is not added to the collection
    response = category.get_all_categories_from_collection()
    collection = response.json()
    assert not any(d.get('name', None) == a_category['name'] for d in collection)\
        and response_p.status_code != 201, 'Category name not unique'
def test_post_comments_category_nmgr140():
    """
        Verify:
            Status code of Success is not returned
            Category Name is not added to the collection.
    """
    # Value for key Name: has 141 characters in the string
    payload = {
        'name':
        'categorynameisuntest_post_comments_category.pyiqueacrossallexis'
        'tingcategoriesinthesystemcategoryname'
        'isuniqueacrossallexistingcategoriesinthes'
    }

    # Sending POST request and saving response as response object
    category = CateGory()
    response_p = category.post_comments_category(payload, headers=HEADERS)
    # Verify - POST record is not added to the collection
    response = category.get_all_categories_from_collection()
    collection = response.json()
    assert not any(d.get('name', None) == payload['name'] for d in collection)\
        and response_p.status_code != 201, 'Error: Record > 140 characters added to collection'
def test_delete_comments_category_byid():
    """
        Verify:
            1]Status code for a successful delete
            2] Category is deleted
    """
    category = CateGory()
    # Adding a new id (not associated with a post) by calling a POST
    category.post_comments_category(PAYLOAD, HEADER)
    cat_id = category.get_last_category_in_collection()['id']
    print(cat_id)
    response = category.delete_comments_category_byid(cat_id)
    assert response.status_code == 204
    # Performing a Delete on the added record
    # Verify the status code, and the delete is allowed
    response = category.get_all_categories_from_collection()
    collection = response.json()
    # Verify category is no longer in the collection
    assert not any(d.get('id', None) == cat_id for d in collection) \
           and response.status_code == 204, 'Delete error occurred'