Skip to content

Commit

Permalink
further item testing in pytest script
Browse files Browse the repository at this point in the history
  • Loading branch information
benne238 committed Jan 12, 2021
1 parent 6dcad0d commit 8609aee
Showing 1 changed file with 80 additions and 13 deletions.
93 changes: 80 additions & 13 deletions api/pytest/test_api_tester.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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

Expand Down Expand Up @@ -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",
Expand All @@ -91,11 +89,80 @@ 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__():
if not attribute.startswith("_"):
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)

0 comments on commit 8609aee

Please sign in to comment.