Task by CHEN Liang SIR
To Verify the resource configuration of a type of hardware server.
Mentor :-CHEN Liang
Mentee :-Deepanshu Udhwani
Github Directory:-
https://github.com/deepanshu1422/LFN-MENTORSHIP-FINAL
To verify the resource configuration of a type of hardware server. Only the server matching the requested configuration can be passed, otherwise checking will fail with a reason.
Whenever a REST-API is called it returns a JSON. Here the motive of ours is to :
-
Check whether the response from the API/JSON request is the same as we expected or not If all the parameters match then the requested configuration gets passed else it fails.
-
When it fails, we need to show why the test case failed and how can we correct the configuration.
-
Here we take 2 JSON files assuming that same response would be shared by the API call.
**
**
The code comprises of few simple steps:
-
We regard 1.json as a configuration file and 2.json the file that needs to get tested.
-
These files are then imported to the finalfile.py
-
Then the JSON file is dumped and loaded using the methods json.dumps() and JSON.load()
-
By doing this we get a HashMap (dictionary in this case) along with the key-value pairs in sorted order.
-
Now the key-value pairs are matched and length is found out.
-
The answer would be true only if all key-value pairs in 1.json matches with key-value pairs of 2.json irrespective of whether more information is present in 2.json
-
If the response is false , the file is traversed recursively to the lowest key and a dictionary gets stored.
-
Sir, as instructed by you: In this whole exercise, I have used only 1 library “deep diff” in order to calculate the difference between 2 dictionaries.
-
The difference is shown on the screen along with a rejection or the acceptance
**
**
I’ve tried to cover almost all functions/methods in UNIT Testing. Basically most of the tests revolve around assertTrue() assertFalse() assertEqual()
Requirements for the Program
-
Python 3
pip install deepdiff
Clone the repository
git clone https://github.com/deepanshu1422/LFN-MENTORSHIP-FINAL
Check the contents of the file 1.json and 2.json
Open cmd/terminal on your system
Test 1 (Both The Files Matches)
Test 2 (All contents of 1.json are present in 2.json along with other unwanted contents)
Here the main thing to notice is we are always doing changes in 2.json not in 1.json
Test 3(Content in 2.json is changed which is already present in 1.json) :(
3 Base and Most Important cases and screenshots are covered in this file in order to run others please run the unit tests as well as any random modification you would like :)
Now to run the Unit Tests Go inside the directory and run
nose2 -v
Deliverables:-
response JSON includes all the items of required items, then it should pass. which means:
- the order could be ignored
- Done
-many more items may present in response but not in required items as long as the required items present in the response.
-
Done
-
The value for a key can be a number, string, or list or dictionary at any level.
-
Done
-
unit test function code
-
Done
Thank You!