Example #1
0
def test_post_comm_posts_pubdatevalid():
    """
        Verify:
        1]The Status Code of Success is not returned
        2]Record is not added to the collection
    """
    post = Post()
    # Requires an existing Category id
    cat_id = post.get_category_assoc_wth_post()
    # A date of tomorrow
    future_date = str(date.today() + timedelta(days=1)) + 'T15:56:29.200201Z'
    # Payload->pub_date contains a date of tomorrow
    payload = {
        "title": "A post’s publication date is valid.",
        "body": "Testing with a date greater than today",
        "pub_date": future_date,
        "category_id": cat_id,
        "category": "Meditation"
    }

    # sending POST request and saving response as response object
    response = post.post_comments_posts(payload, headers=HEADERS)
    assert response.status_code != 201, "Date/time other than today's should not be allowed"

    # Verify the POST did not add the record by verifying the
    # absence of the ID in the collection
    collection = post.get_all_posts_from_collection()
    assert not any(d.get('id', None) == payload['title'] for d in collection["items"]) \
        and response.status_code != 201,\
        "Date/time other than today's should not be allowed. " \
        "Record incorrectly added to collection for an invalid date"
def test_post_comm_posts_titlelimit():
    """
        Verify:
        1]The Status Code of Success is not in the response
        2]Record is not added to the collection.  A post title does not exceed 100 characters
    """
    post = Post()
    # Requires an existing Category id
    cat_id = post.get_category_assoc_wth_post()
    # Data to be sent to api
    payload = {
        "title": "iqueacrossallexistingcategoriesinthesystemcategor"
                 "ynameisuniqueacrossallexistingcategoriesinthesnot "
                 "exceed 100 characters",
        "body": "This dramatic retelling of the Pearl Harbor attack details everything "
                "in the days that led up to that tragic moment in American history.",
        "pub_date": "2016-06-11T15:56:29.200201",
        "category_id": cat_id,
        "category": "Meditation"
    }
    # sending POST request and saving response as response object
    response = post.post_comments_posts(payload, headers=HEADERS)
    # Verify the POST did not add the record by verifying the
    # absence of the ID in the collection
    collection = post.get_all_posts_from_collection()
    assert not any(d.get('title', None) == payload['title'] for d in collection["items"]) \
        and response.status_code != 201, \
        'Title string limit > 100. Record incorrectly added to collection'
def test_get_comments_posts_arch_by_yrmn():
    """
        Verify status code and content of the response.
    """
    post = Post()
    response = post.get_archived_post(2019, mn=5)
    assert response.status_code == 200, 'Error retrieving posts'
Example #4
0
def test_post_comments_posts_invalid_catid():
    """
    Verify status code and POST did not occur due to invalid Category id.
    """

    # Next id in the collection to be used for POST
    # Data to be sent to api
    payload = {
        "title": "TESTING_INVALID_CATID",
        "body": "This dramatic retelling of the Pearl Harbor attack details everything "
                "in the days that led up to that tragic moment in American history.",
        "pub_date": "2016-06-11T15:56:29.200201",
        "category_id": 000,  # Invalid id
        "category": "Meditation"
    }
    post = Post()
    # sending POST request and saving response as response object
    response = post.post_comments_posts(payload, headers=HEADERS)
    # TODO: Confirm if Status Code should be 404 or 400. Document states 400.
    # However, Status Code returned is 404
    # Verify the POST did not add the record
    collection = post.get_all_posts_from_collection()
    assert not any(d.get('name', None) == 'TESTING_INVALID_CATID' for d in collection["items"]) \
           and response.status_code == 404, \
        'Invalid Category. POST not allowed. Post added for invalid id'
def test_get_comments_posts_arch_datefilter_yyyy():
    """
        Verify status code and content of the response.
    """
    # Invalid year
    yr = 1991

    post = Post()
    response = post.get_archived_post(yr)
    assert response.status_code != 200, 'yyyy > 1992 requirement not enforced'
def test_get_comments_posts_arch_datefilter_mm():
    """
        Verify status code and content of the response.
    """

    yr = 2019
    mn = 13  # Invalid month (1 <= mm <= 12)

    post = Post()
    response = post.get_archived_post(yr, mn)
    assert response.status_code != 200, 'Invalid month'
def test_get_comments_post_byid():
    """
    Verify status code and content of the response.
    """
    post = Post()
    post_id = post.get_arandm_post_from_collection()['id']
    response = post.get_comments_posts_byid(post_id)
    comment_record = response.json()
    # Verify the ID matches the id from the record
    assert comment_record.get('id', None) == post_id \
        and response.status_code == 200, 'Failed to retrieve the post record from the collection'
def test_get_comments_posts_arch_datefilter_day():
    """
        Verify status code and content of the response.
    """

    yr = 2019
    mn = 2
    dy = 32  # Invalid day (1 <= dd <= 31)
    post = Post()
    response = post.get_archived_post(yr, mn, dy)
    print(response.status_code)
    assert response.status_code != 200, 'invalid day'
def test_get_comments_all_posts():
    """
    Verify status code and content of the response.
    """
    post = Post()
    payload = {'page': 1, bool: 'false', 'per_page': 10}  # Default setting
    response = post.get_comments_all_posts(payload)
    collection = response.json()
    # Verifying a record (randomly) from the collection returned
    random_index = (random.randrange(len(collection['items'])))
    id_of_random_index = collection['items'][random_index]['id']
    assert any(d.get('id', None) == id_of_random_index for d in collection["items"]) \
        and response.status_code == 200, 'A record was not returned'
def test_delete_comments_post_byid():
    """
    Verify:
    1]Status code for delete
    2] Post was delete from the collection
    """
    post = Post()
    # Select a post to delete
    a_post_id = post.get_arandm_post_from_collection()['id']
    response = post.delete_comments_post_byid(a_post_id)
    # Verify the deleted record does not exit in the collection
    collection = post.get_all_posts_from_collection()
    assert not any(d.get('id', None) == a_post_id for d in collection["items"]) and \
           response.status_code == 204, 'failed to delete the record'
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'
Example #12
0
def test_put_comments_post_byid():
    """
    Verify status code and content of the response.
    """
    post = Post()
    cat_id = post.get_category_assoc_wth_post()
    post_id = post.get_arandm_post_from_collection()['id']
    # Data to be sent to api
    payload = {
        "id": post_id,
        "title": "Tora Tora Tora",
        "body": "This dramatic retelling of the Pearl Harbor attack details everything "
                "in the days that led up to that tragic moment in American history.",
        "pub_date": "2016-06-11T15:56:29.200201",
        "category_id": cat_id,
        "category": "Meditation"
    }
    headers = {'content-type': 'application/json'}
    # sending POST request and saving response as response object
    response = post.put_comments_post_byid(post_id=post_id, payload=payload, headers=headers)

    # Verify the PUT successfully updated the record by verifying the ID and the Title
    collection = post.get_all_posts_from_collection()
    assert any(d.get('id', None) == post_id and
               d.get('title', None) == 'Tora Tora Tora' for d in collection["items"]) \
           and response.status_code == 204
Example #13
0
def test_post_comments_posts():
    """
        Verify status code and content of the response.
    """
    post = Post()
    cat_id = post.get_category_assoc_wth_post()
    # Data to be sent to api
    payload = {
        "title": "TESTINDG TODAT",
        "body": "This dramatic retelling of the Pearl Harbor attack details everything "
                "in the days that led up to that tragic moment in American history.",
        "pub_date": "2016-06-11T15:56:29.200201",
        "category_id": cat_id,
        "category": "Meditation"
    }

    # sending POST request and saving response as response object
    response = post.post_comments_posts(payload, headers=HEADERS)
    # Verify the POST successfully added the record by verifying the ID in the collection
    collection = post.get_all_posts_from_collection()
    id_post = (collection['items'][-1]).get('id')
    assert any(d.get('id', None) == id_post for d in collection["items"]) \
           and response.status_code == 201, 'post failed to append to collection'
def test_post_comm_posts_bodylimit():
    """
        Verify:
        1]The Status Code of Success is not in the response
        2]Record is not added to the collection
    """

    post = Post()
    # Requires an existing Category id
    cat_id = post.get_category_assoc_wth_post()
    # Payload->pub_date contains a date of tomorrow
    # Payload->tile contains more than 1000 characters
    payload = {
        "title": "testforbigbodygreaterthan1000chars",
        "body": "namedoesnotexceed140characters.iqueacrossallexis" \
                "tingcategoriesinthesystemcategorynameisuniqueacro"
                "ssallexistingcategoriesinthesnot exceed100characte"
                "rsiqueacrossallexistingcategoriesinthesystemcatego"
                "rynameisuniqueacrossallexistingcategoriesinthesnot"
                "exceed 100 characters namedoesnotexceed140characte"
                "rsiqueacrossallexistingcategoriesinthesystemcategor"
                "ynameisuniqueacrossallexisti",
        "pub_date": "2016-06-11T15:56:29.200201",
        "category_id": cat_id,
        "category": "Meditation"
    }

    # sending POST request and saving response as response object
    response = post.post_comments_posts(payload, headers=HEADERS)
    # assert response.status_code != 201, '< 1000 string length not enforced'

    # Verify the POST did not add the record by verifying the
    # absence of the ID in the collection
    collection = post.get_all_posts_from_collection()
    assert not any(d.get('body', None) == payload['body'] for d in collection["items"]) \
        and response.status_code != 201, \
        '< 1000 string length not enforced. Record incorrectly added to the collection'