Skip to content

Commit 73e0da9

Browse files
Merge pull request #71 from jaredhendrickson13/v120
v1.2.0
2 parents 40c1757 + e8aa6cd commit 73e0da9

137 files changed

Lines changed: 17125 additions & 2118 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.idea
2-
*/__pycache__/
2+
tests/unit_test_framework/__pycache__/
33
*.DS_Store
44
.phplint-cache
55

README.md

Lines changed: 1336 additions & 54 deletions
Large diffs are not rendered by default.

docs/CONTRIBUTING.md

Lines changed: 100 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -371,43 +371,68 @@ class NewAPIUnitTest(unit_test_framework.APIUnitTest):
371371
#### Overriding Base Model Properties ####
372372
The APIUnitTest class requires you to override a some properties to function correctly:
373373

374-
- `url` : A string specifying the URL this unit test will be testing<br>
375-
- `get_payloads` : A list of dictionary formatted API payloads to use when testing GET requests. If this endpoint does not
376-
support GET requests, you do not need to override this property. If this endpoint does support GET request, but does not
377-
require any payload data to receive a valid response you must set this value to `[{}]`
378-
- `post_payloads` : A list of dictionary formatted API payloads to use when testing POST requests. If this endpoint does
379-
not support POST requests, you do not need to override this property.
380-
- `put_payloads` : A list of dictionary formatted API payloads to use when testing PUT requests. If this endpoint does
381-
not support PUT requests, you do not need to override this property.
382-
- `delete_payloads` : A list of dictionary formatted API payloads to use when testing DELETE requests. If this endpoint does
383-
not support DELETE requests, you do not need to override this property.
374+
- `url` : A string specifying the URL this unit test will be testing
375+
- `time_delay` : An integer specifying how many seconds should be waited between requests. Defaults to `1`.
376+
- `get_tests` : A list of dictionary formatted test parameters for GET requests. If this endpoint does not support
377+
GET requests, you do not need to override this property. If this endpoint does support GET request, but does not require
378+
any payload data to receive a valid response you must set this value to `[{}]`. Each dictionary can contain:
379+
- `name` : set a descriptive name to be printed alongside test results (defaults to `unnamed test`)
380+
- `payload` : a nested dictionary that contains the request payload to use when running the test (defaults to `{}`)
381+
- `status` : an integer that specifies the tests expected HTTPS status code (defaults to `200`)
382+
- `return` : an integer that specifies the tests expected API return code (defaults to `0`)
383+
- `resp_time` : a float that specifies the tests maximum response time expected from the API endpoint
384+
- `auth_payload` : a dictionary containing authentication payload values (typically `client-id` and `client-token`)
385+
to use with the corresponding request (defaults the username and password passed into the command)
386+
387+
- `post_tests` : A list of dictionary formatted test parameters for POST requests. If this endpoint does not support
388+
POST requests, you do not need to override this property. If this endpoint does support POST request, but does not require
389+
any payload data to receive a valid response you must set this value to `[{}]`. Each dictionary can contain:
390+
- `name` : set a descriptive name to be printed alongside test results (defaults to `unnamed test`)
391+
- `payload` : a nested dictionary that contains the request payload to use when running the test (defaults to `{}`)
392+
- `status` : an integer that specifies the tests expected HTTPS status code (defaults to `200`)
393+
- `return` : an integer that specifies the tests expected API return code (defaults to `0`)
394+
- `resp_time` : a float that specifies the tests maximum response time expected from the API endpoint
395+
- `auth_payload` : a dictionary containing authentication payload values (typically `client-id` and `client-token`)
396+
to use with the corresponding request (defaults the username and password passed into the command)
397+
398+
- `put_tests` : A list of dictionary formatted test parameters for PUT requests. If this endpoint does not support
399+
PUT requests, you do not need to override this property. If this endpoint does support PUT request, but does not require
400+
any payload data to receive a valid response you must set this value to `[{}]`. Each dictionary can contain:
401+
- `name` : set a descriptive name to be printed alongside test results (defaults to `unnamed test`)
402+
- `payload` : a nested dictionary that contains the request payload to use when running the test (defaults to `{}`)
403+
- `status` : an integer that specifies the tests expected HTTPS status code (defaults to `200`)
404+
- `return` : an integer that specifies the tests expected API return code (defaults to `0`)
405+
- `resp_time` : a float that specifies the tests maximum response time expected from the API endpoint
406+
- `auth_payload` : a dictionary containing authentication payload values (typically `client-id` and `client-token`)
407+
to use with the corresponding request (defaults the username and password passed into the command)
408+
409+
- `delete_tests` : A list of dictionary formatted test parameters for DELETE requests. If this endpoint does not support
410+
DELETE requests, you do not need to override this property. If this endpoint does support DELETE request, but does not require
411+
any payload data to receive a valid response you must set this value to `[{}]`. Each dictionary can contain:
412+
- `name` : set a descriptive name to be printed alongside test results (defaults to `unnamed test`)
413+
- `payload` : a nested dictionary that contains the request payload to use when running the test (defaults to `{}`)
414+
- `status` : an integer that specifies the tests expected HTTPS status code (defaults to `200`)
415+
- `return` : an integer that specifies the tests expected API return code (defaults to `0`)
416+
- `resp_time` : a float that specifies the tests maximum response time expected from the API endpoint
417+
- `auth_payload` : a dictionary containing authentication payload values (typically `client-id` and `client-token`)
418+
to use with the corresponding request (defaults the username and password passed into the command)
419+
384420
- `get_responses` : A list of previously executed GET requests in a dictionary format. Failing responses will not be
385421
included.
422+
386423
- `post_responses` : A list of previously executed POST requests in a dictionary format. Failing responses will not be
387424
included.
425+
388426
- `put_responses` : A list of previously executed PUT requests in a dictionary format. Failing responses will not be
389427
included.
428+
390429
- `delete_responses` : A list of previously executed DELETE requests in a dictionary format. Failing responses will not be
391430
included.
392431

393-
```python
394-
import unit_test_framework
432+
#### Other Base Model Properties
433+
The APIUnitTest class also contains a few properties that are not intended to be overridden:
395434

396-
class NewAPIUnitTest(unit_test_framework.APIUnitTest):
397-
url = "/api/v1/your_endpoint"
398-
get_payloads = [{}]
399-
post_payloads = [
400-
{"some_parameter": "some value to create"},
401-
{"some_parameter": "some other value to create"}
402-
]
403-
put_payloads = [
404-
{"some_parameter": "some value to update"},
405-
{"some_parameter": "some other value to update"}
406-
]
407-
delete_payloads = [
408-
{"some_parameter": "some value to delete"},
409-
]
410-
```
435+
- `uid` : a unique ID that can be used for payload fields that required a unique value
411436

412437
#### Overriding Base Model Methods ####
413438
There are methods that will assist you when you need to dynamically format API request data. These are typically used
@@ -432,18 +457,52 @@ import unit_test_framework
432457

433458
class NewAPIUnitTest(unit_test_framework.APIUnitTest):
434459
url = "/api/v1/your_endpoint"
435-
get_payloads = [{}]
436-
post_payloads = [
437-
{"some_parameter": "some value to create"},
438-
{"some_parameter": "some other value to create"}
439-
]
440-
put_payloads = [
441-
{"some_parameter": "some value to update"},
442-
{"some_parameter": "some other value to update"}
460+
get_requests = [{}]
461+
post_requests = [
462+
{
463+
"payload": {
464+
"some_parameter": "some value to create"
465+
},
466+
"status": 400,
467+
"return": 1,
468+
"resp_time": 0.5
469+
},
470+
{
471+
"payload": {
472+
"some_other parameter": "some other value to create"
473+
},
474+
"status": 200,
475+
"return": 0,
476+
"resp_time": 0.6
477+
}, ]
478+
put_requests = [
479+
{
480+
"payload": {
481+
"some_parameter": "some value to update"
482+
},
483+
"status": 400,
484+
"return": 1,
485+
"resp_time": 0.5
486+
},
487+
{
488+
"payload": {
489+
"some_other parameter": "some other value to update"
490+
},
491+
"status": 200,
492+
"return": 0,
493+
"resp_time": 0.6
494+
},
443495
]
444-
delete_payloads = [
445-
{"some_parameter": "some value to delete"},
446-
]
496+
delete_requests = [
497+
{
498+
"payload": {
499+
"some_parameter": "some value to delete"
500+
},
501+
"status": 200,
502+
"return": 0,
503+
"resp_time": 0.5
504+
},
505+
]
447506

448507
NewAPIUnitTest()
449508
```
@@ -457,7 +516,9 @@ Or you may run all the unit tests by running:<br>
457516
Unit tests will check API responses for the following:
458517
- Ability to connect to API endpoint
459518
- API responses properly return data in a JSON format
460-
- API payloads return a 200 OK response
519+
- API responses include the correct HTTP status code
520+
- API responses include the expected API return code
521+
- API responses are received within an acceptable time frame
461522
- CRUD success. POST requests are always run first, then GET requests to check that the creation was successful, then
462523
PUT requests attempt to update the created object, then finally DELETE requests attempt to destroy the object.
463524

docs/documentation.json

Lines changed: 2209 additions & 191 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)