Skip to content

Commit

Permalink
Migrating to pytest to improve ordering of the executed methods.
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Pinto <christian.pinto@ibm.com>
  • Loading branch information
christian-pinto committed Oct 25, 2023
1 parent 45a682d commit 0db6101
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 15 deletions.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ typing_extensions==4.7.1
urllib3==2.0.4
Werkzeug==2.3.7
zipp==3.16.2
pytest
pytest-ordering
32 changes: 19 additions & 13 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test_templates
import unittest
import json
import pytest
from api_emulator.resource_manager import ResourceManager
from api_emulator.redfish.constants import PATHS

Expand All @@ -9,9 +9,9 @@
REST_BASE = '/redfish/v1/'
g.rest_base = REST_BASE

class TestOFMF(unittest.TestCase):
class TestOFMF():
@classmethod
def setUpClass(cls):
def setup_class(cls):
global resource_manager
global REST_BASE
global TRAYS
Expand All @@ -26,26 +26,29 @@ def test_create_computer_system(self):
system_url = f"{REST_BASE}Systems"
response = self.client.post(system_url, json=test_templates.test_system)
status_code = response.status_code
self.assertEqual(status_code, 200)

assert status_code == 200

def test_create_chassis(self):
chassis_url = f"{REST_BASE}Chassis"
response = self.client.post(chassis_url, json=test_templates.test_chassis)
status_code = response.status_code
self.assertEqual(status_code, 200)


assert status_code == 200

def test_agent_registration(self):
events_url = f"/EventListener"
response = self.client.post(events_url, json=test_templates.test_aggregation_source_event)
status_code = response.status_code
self.assertEqual(status_code, 200)


assert status_code == 200

manager_name = test_templates.test_aggregation_source_event["Events"][0]["OriginOfCondition"]["@odata.id"].split('/')[-1]
conn_method = test_templates.test_aggregation_source_event["Events"][0]["OriginOfCondition"]
aggr_source_url = f"{REST_BASE}AggregationService/AggregationSources"
response = self.client.get(aggr_source_url)

# validate the generation of a new AggregationSource related to the new Agent
# validate the generation of a new AggregationSource related to the new Agent
aggr_source_collection = json.loads(response.data)
aggr_source_found = False
for aggr_source in aggr_source_collection['Members']:
Expand All @@ -54,8 +57,11 @@ def test_agent_registration(self):
if conn_method == aggr_source_data['Links']['ConnectionMethod']:
aggr_source_found=True

self.assertTrue(aggr_source_found)
assert aggr_source_found

if __name__ == '__main__':
unittest.main()
# main()
@pytest.mark.run(after="test_agent_registration")
def test_agent_registration_create_fabric(self):
events_url = f"/EventListener"
response = self.client.post(events_url, json=test_templates.test_fabric_event)
status_code = response.status_code
assert status_code == 200
4 changes: 2 additions & 2 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ echo "Script dir: $SCRIPT_DIR"
cd ${SCRIPT_DIR}/..


python emulator.py -p 5002 -redfish-path ./Resources/CXLAgent/ &
python emulator.py -p 5002 -redfish-path ./Resources/CXLAgent/ > agent_logs 2>&1 &

sleep 10

python -m unittest discover -s tests
python -m pytest tests/test.py -vvvv
19 changes: 19 additions & 0 deletions tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,22 @@
}
}
]}

test_fabric_event = {
"@odata.type": "#Event.v1_7_0.Event",
"Id": "1",
"Name": "Fabric Created",
"Context": "",
"Events": [ {
"EventType": "Other",
"EventId": "4595",
"Severity": "Ok",
"Message": "New Fabric Created ",
"MessageId": "Resource.1.0.ResourceCreated",
"MessageArgs": [],
"OriginOfCondition": {
"@odata.id": "/redfish/v1/Fabrics/CXL"
}
}
]
}

0 comments on commit 0db6101

Please sign in to comment.