From 8609aee7d8e4b56cda02408664c9e0dd34b894ee Mon Sep 17 00:00:00 2001 From: benne238 Date: Tue, 12 Jan 2021 17:02:24 -0500 Subject: [PATCH] further item testing in pytest script --- api/pytest/test_api_tester.py | 93 ++++++++++++++++++++++++++++++----- 1 file changed, 80 insertions(+), 13 deletions(-) diff --git a/api/pytest/test_api_tester.py b/api/pytest/test_api_tester.py index 6350ec8..78264b4 100644 --- a/api/pytest/test_api_tester.py +++ b/api/pytest/test_api_tester.py @@ -1,8 +1,11 @@ -#Importing pytest is not required unless using markers, as demonstrated below +# Importing pytest is not required unless using markers, as demonstrated below import pytest import ECNQueue -import random +# import random import unittest +from dateutil.parser import parse +from dateutil import tz +import datetime @pytest.mark.ECNQueue_getValidQueuesTest def test_ECNQueue_getQueueCounts(): @@ -15,14 +18,16 @@ def test_ECNQueue_getQueueCounts(): # {'name': '_string' # 'number_of_items': _int} + queueKeys = ["name", "number_of_items"] for queue in queueCounts: assert type(queue) is dict + assert all(keys in queue.keys() for keys in queueKeys) - # Ensure that the number of name key exists with a string value + # Ensure that the number of name key occures only once and has a string value assert "name" in queue.keys() assert type(queue['name']) is str - # Ensure that the number_of_items queues key exists with an int value + # Ensure that the number_of_items queues key occures only once and has an int value assert "number_of_items" in queue.keys() assert type(queue['number_of_items']) is int @@ -63,14 +68,7 @@ def test_ECNQueue_isValidItemName(): @pytest.mark.ECNQueue_Item def test_ECNQueue_Item(): - # validQueues = ECNQueue.getValidQueues() - - # Selects a random queue to be tested against - # testQueue = random.choice(validQueues) - - item = ECNQueue.Item("ce", 100) - - itemKeys = [ + validItemAttributes = [ "queue", "number", "lastUpdated", @@ -91,6 +89,75 @@ def test_ECNQueue_Item(): "toJson" ] + # validQueues = ECNQueue.getValidQueues() + + # Selects a random queue to be tested against + # testQueue = random.choice(validQueues) + + item = ECNQueue.Item("ce", 100) + itemAttributes = item.__dir__() + + for attribute in itemAttributes: + if attribute.startswith("_"): + itemAttributes.remove(attribute) + + assert all(attribute in validItemAttributes for attribute in itemAttributes) + + # test the queue attribute of a returned item + assert type(item.queue) is str + + # test the number attribute of a returned item + assert type(item.number) is int + + # test the lastUpdated attribute of a returned item + assert type(item.lastUpdated) is str + assert parse(item.lastUpdated, default=datetime.datetime( + 1970, 1, 1, tzinfo=tz.gettz('EDT'))) # Ensures lastUpdated is a date + + # test the headers attribute of a returned item + validHeaderKeys = ["content", "type"] + + assert type(item.headers) is list + for header in item.headers: + assert type(header) is dict + assert all(key in validHeaderKeys for key in header.keys()) + assert type(header["content"]) is str + assert type(header["type"]) is str + + # test the content attribute of a returned item + contentTypes = ["directory_information", + "initial_message", + "edit", + "status", + "assignment", + "reply_to_user", + "reply_from_user", + "parse_error"] + + directoryKeys = ["type", + "name", + "login", + "computer", + "location", + "email", + "phone", + "office", + "UNIX Dir", + "Zero Dir", + "User ECNDB", + "Host ECNDB", + "Subject" + ] + + assert type(item.content) is list + for content in item.content: + assert "type" in content.keys() + assert content["type"] in contentTypes + + if content["type"] == "directory_information": + print(()) + + # Returns a list of all attributes in the item object, omiting attribute names starting with "_" returnedItemKeys = [] for attribute in item.__dir__(): @@ -98,4 +165,4 @@ def test_ECNQueue_Item(): returnedItemKeys.append(attribute) # Checks that all necessary keys are in the item by comparing it to the itemkeys list - assert all(keys in itemKeys for keys in returnedItemKeys) + # assert all(keys in itemKeys for keys in returnedItemKeys)