From de1831bf39d15ae1c33cf6bec6d0598e2c4b90cf Mon Sep 17 00:00:00 2001 From: Matt Griswold Date: Mon, 1 Jan 2018 16:49:03 +0000 Subject: [PATCH] rename RequestsData --- README.md | 27 ++ pytest_filedata/__init__.py | 4 +- tests/data/req/test0/data.200 | 459 ++++++++++++++++++++++++++++++++++ tests/test_requests.py | 9 +- 4 files changed, 494 insertions(+), 5 deletions(-) create mode 100644 tests/data/req/test0/data.200 diff --git a/README.md b/README.md index 6851a4a..7a5280c 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,33 @@ easily load test data from files +### Introduction + +This was created to save the tediousness of working with sets of data for +testing inside the test files. + +### Installing + +```sh +pip install pytest-filedata +``` + +### Using + +Add this to your `conftest.py` file: + +```python +pytest.setup_filedata(os.path.dirname(__file__)) + + +def pytest_generate_tests(metafunc): + for fixture in metafunc.fixturenames: + if fixture.startswith('data_'): + data = pytest.get_filedata(fixture) + metafunc.parametrize(fixture, data.values(), ids=data.keys()) +``` + + ### License Copyright 2016 20C, LLC diff --git a/pytest_filedata/__init__.py b/pytest_filedata/__init__.py index 0a61374..1a1c9cc 100644 --- a/pytest_filedata/__init__.py +++ b/pytest_filedata/__init__.py @@ -100,7 +100,7 @@ def get_filedata(name): return data -class RequestData(object): +class RequestsData(object): """ class to use test data from requests """ @@ -145,6 +145,6 @@ def pytest_namespace(): """Register pytest plugin.""" return dict( get_filedata=get_filedata, - RequestData=RequestData, + RequestsData=RequestsData, setup_filedata=setup_filedata, ) diff --git a/tests/data/req/test0/data.200 b/tests/data/req/test0/data.200 new file mode 100644 index 0000000..1173371 --- /dev/null +++ b/tests/data/req/test0/data.200 @@ -0,0 +1,459 @@ +[ + { + "_id": "5a4a580a0c912af0f37e0c90", + "index": 0, + "guid": "0962bf7e-3740-4e89-9b46-70ae0be4f191", + "isActive": true, + "balance": "$3,133.24", + "picture": "http://placehold.it/32x32", + "age": 33, + "eyeColor": "brown", + "name": { + "first": "Tabatha", + "last": "Burch" + }, + "company": "VERBUS", + "email": "tabatha.burch@verbus.biz", + "phone": "+1 (810) 427-2220", + "address": "777 Pineapple Street, Williamson, West Virginia, 5791", + "about": "Lorem veniam sunt excepteur esse ad consectetur id ut labore. Enim nulla nulla occaecat velit laboris voluptate ut ullamco id culpa amet mollit laboris ad. Laboris qui in officia esse proident minim. Eiusmod cupidatat ipsum enim proident Lorem minim magna nulla ipsum ullamco. Aute nisi labore enim ut officia in esse irure. Voluptate nisi culpa aliquip esse.", + "registered": "Friday, March 7, 2014 12:06 AM", + "latitude": "17.214286", + "longitude": "144.533821", + "tags": [ + "proident", + "proident", + "non", + "do", + "occaecat" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Wendy Leblanc" + }, + { + "id": 1, + "name": "Evangeline Goodwin" + }, + { + "id": 2, + "name": "Contreras Whitney" + } + ], + "greeting": "Hello, Tabatha! You have 9 unread messages.", + "favoriteFruit": "apple" + }, + { + "_id": "5a4a580a765a75a04460ab21", + "index": 1, + "guid": "a1abbb4a-42df-4335-931f-d95118e6ff6d", + "isActive": true, + "balance": "$3,772.41", + "picture": "http://placehold.it/32x32", + "age": 40, + "eyeColor": "green", + "name": { + "first": "Heath", + "last": "Puckett" + }, + "company": "SNACKTION", + "email": "heath.puckett@snacktion.us", + "phone": "+1 (881) 521-2112", + "address": "524 Anchorage Place, Joppa, New York, 2672", + "about": "Do ex ullamco exercitation officia non aliqua ad incididunt et tempor. Duis in irure sunt mollit et anim ex incididunt consequat. Irure do ad in ea ad aliqua do veniam est in quis voluptate.", + "registered": "Saturday, June 14, 2014 1:00 PM", + "latitude": "-61.264717", + "longitude": "-148.845539", + "tags": [ + "dolor", + "ullamco", + "Lorem", + "ad", + "quis" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Wood Cooke" + }, + { + "id": 1, + "name": "Molly Henderson" + }, + { + "id": 2, + "name": "Madden Flores" + } + ], + "greeting": "Hello, Heath! You have 9 unread messages.", + "favoriteFruit": "strawberry" + }, + { + "_id": "5a4a580aad9f80006cdf10af", + "index": 2, + "guid": "34eb1a42-c9d6-47a0-bef9-1a39d8c9d3e3", + "isActive": false, + "balance": "$3,246.48", + "picture": "http://placehold.it/32x32", + "age": 26, + "eyeColor": "green", + "name": { + "first": "Morin", + "last": "Copeland" + }, + "company": "DATACATOR", + "email": "morin.copeland@datacator.io", + "phone": "+1 (865) 466-3084", + "address": "716 Ross Street, Healy, South Dakota, 4255", + "about": "Ea mollit do voluptate ipsum. Veniam occaecat sint amet veniam non magna ad dolore esse deserunt sint ut officia. Ea exercitation aute do fugiat reprehenderit qui nostrud dolor amet tempor. Est adipisicing cillum ullamco in deserunt proident qui eiusmod eiusmod veniam elit exercitation non nisi.", + "registered": "Monday, September 21, 2015 1:57 PM", + "latitude": "-38.785254", + "longitude": "-154.992394", + "tags": [ + "duis", + "anim", + "occaecat", + "anim", + "laborum" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Kathie Chase" + }, + { + "id": 1, + "name": "Anne Wong" + }, + { + "id": 2, + "name": "Alexander Lee" + } + ], + "greeting": "Hello, Morin! You have 5 unread messages.", + "favoriteFruit": "strawberry" + }, + { + "_id": "5a4a580af71694d16fed521d", + "index": 3, + "guid": "91778e07-79d1-44f1-9499-f3df9b991d9e", + "isActive": false, + "balance": "$2,269.05", + "picture": "http://placehold.it/32x32", + "age": 34, + "eyeColor": "brown", + "name": { + "first": "Dina", + "last": "Hernandez" + }, + "company": "NAMEGEN", + "email": "dina.hernandez@namegen.co.uk", + "phone": "+1 (890) 467-3197", + "address": "417 Knapp Street, Gouglersville, Palau, 3690", + "about": "Excepteur minim tempor et sint irure adipisicing ex do reprehenderit labore. Est aute ea amet consequat laboris veniam ea tempor amet elit enim. Pariatur sunt laboris tempor ea eu in.", + "registered": "Tuesday, April 29, 2014 8:39 PM", + "latitude": "88.93652", + "longitude": "122.04518", + "tags": [ + "eu", + "nulla", + "mollit", + "adipisicing", + "irure" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Brianna Cochran" + }, + { + "id": 1, + "name": "Herman Mendoza" + }, + { + "id": 2, + "name": "Rose Mcclain" + } + ], + "greeting": "Hello, Dina! You have 6 unread messages.", + "favoriteFruit": "strawberry" + }, + { + "_id": "5a4a580ab638604600c06bc7", + "index": 4, + "guid": "f929b261-4b0f-492f-bed9-2956720348de", + "isActive": false, + "balance": "$2,982.27", + "picture": "http://placehold.it/32x32", + "age": 40, + "eyeColor": "green", + "name": { + "first": "Underwood", + "last": "Mcintosh" + }, + "company": "DIGIFAD", + "email": "underwood.mcintosh@digifad.name", + "phone": "+1 (866) 561-3235", + "address": "701 Green Street, Sattley, Virgin Islands, 9364", + "about": "Magna amet occaecat cillum consequat do deserunt. Voluptate tempor quis quis dolore anim qui duis. Mollit id adipisicing officia eiusmod irure nulla cillum qui. Ad pariatur esse laboris cillum pariatur sit nulla proident nisi ad. Eu sint pariatur pariatur voluptate quis reprehenderit incididunt et. Ex sint qui magna magna exercitation aliquip proident.", + "registered": "Saturday, November 12, 2016 8:16 PM", + "latitude": "-22.025971", + "longitude": "11.665505", + "tags": [ + "ipsum", + "nisi", + "culpa", + "nostrud", + "fugiat" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Blair Sellers" + }, + { + "id": 1, + "name": "Cassandra Hogan" + }, + { + "id": 2, + "name": "Leigh Bates" + } + ], + "greeting": "Hello, Underwood! You have 6 unread messages.", + "favoriteFruit": "apple" + }, + { + "_id": "5a4a580b373021ad119b0930", + "index": 5, + "guid": "c1975c9b-fdb7-4f9c-895e-57b72ac47d0d", + "isActive": true, + "balance": "$1,818.80", + "picture": "http://placehold.it/32x32", + "age": 29, + "eyeColor": "blue", + "name": { + "first": "Bridget", + "last": "Duran" + }, + "company": "XUMONK", + "email": "bridget.duran@xumonk.org", + "phone": "+1 (896) 458-3115", + "address": "209 Joval Court, Bannock, California, 6346", + "about": "Aliqua minim excepteur commodo enim culpa ad. Aliqua eu dolor veniam velit occaecat aliqua elit tempor. Incididunt adipisicing ipsum cupidatat tempor commodo qui cupidatat et aute. Commodo elit consectetur Lorem excepteur laborum quis commodo magna esse dolore do eiusmod consectetur. Et ut occaecat eiusmod excepteur minim irure elit do ipsum veniam. Et dolore qui commodo qui est aliquip reprehenderit consectetur. Adipisicing laborum occaecat labore ipsum consectetur.", + "registered": "Tuesday, April 8, 2014 2:40 PM", + "latitude": "-58.522426", + "longitude": "-57.612181", + "tags": [ + "dolor", + "aute", + "anim", + "ea", + "et" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Good Neal" + }, + { + "id": 1, + "name": "Hebert Medina" + }, + { + "id": 2, + "name": "Hubbard Ashley" + } + ], + "greeting": "Hello, Bridget! You have 10 unread messages.", + "favoriteFruit": "strawberry" + }, + { + "_id": "5a4a580b92443d6539174cf1", + "index": 6, + "guid": "7262a62f-8665-4d8d-a940-25e9ccab8dbe", + "isActive": true, + "balance": "$3,555.71", + "picture": "http://placehold.it/32x32", + "age": 39, + "eyeColor": "brown", + "name": { + "first": "Corinne", + "last": "Morin" + }, + "company": "BLEEKO", + "email": "corinne.morin@bleeko.info", + "phone": "+1 (944) 490-2121", + "address": "358 Stockholm Street, Kanauga, Massachusetts, 8772", + "about": "Officia magna elit occaecat non nostrud. Enim ipsum nostrud culpa ullamco officia excepteur Lorem est deserunt. Incididunt labore irure adipisicing nostrud aliqua do tempor occaecat voluptate magna et non. Deserunt minim dolor veniam elit qui anim nisi excepteur ut velit adipisicing ullamco tempor.", + "registered": "Tuesday, December 19, 2017 1:05 PM", + "latitude": "-34.833629", + "longitude": "-16.77381", + "tags": [ + "aliquip", + "aliquip", + "eu", + "aute", + "in" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Stein Vang" + }, + { + "id": 1, + "name": "Janette Mcintyre" + }, + { + "id": 2, + "name": "Gena Sullivan" + } + ], + "greeting": "Hello, Corinne! You have 10 unread messages.", + "favoriteFruit": "banana" + }, + { + "_id": "5a4a580b49c79d3d1ea8eedf", + "index": 7, + "guid": "51ea29aa-9980-47da-ac84-7d8d26b4e19c", + "isActive": true, + "balance": "$2,332.99", + "picture": "http://placehold.it/32x32", + "age": 25, + "eyeColor": "brown", + "name": { + "first": "Acosta", + "last": "Hoffman" + }, + "company": "LUNCHPAD", + "email": "acosta.hoffman@lunchpad.biz", + "phone": "+1 (812) 450-2665", + "address": "487 Raleigh Place, Alamo, Maine, 6979", + "about": "Ut sint minim irure dolor duis in sit esse consectetur officia minim. Proident duis consectetur culpa occaecat. Do elit aliqua eiusmod minim.", + "registered": "Sunday, October 15, 2017 7:31 PM", + "latitude": "55.181807", + "longitude": "41.036547", + "tags": [ + "ipsum", + "exercitation", + "eiusmod", + "quis", + "mollit" + ], + "range": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "friends": [ + { + "id": 0, + "name": "Margie Lucas" + }, + { + "id": 1, + "name": "Pearlie Mcmahon" + }, + { + "id": 2, + "name": "Kaye Mcdowell" + } + ], + "greeting": "Hello, Acosta! You have 9 unread messages.", + "favoriteFruit": "banana" + } +] + diff --git a/tests/test_requests.py b/tests/test_requests.py index 3c682d2..8f147ae 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -3,6 +3,9 @@ import requests import pytest -@pytest.RequestData("req") -def test_request(): - pass + +@pytest.RequestsData("req") +def test_requests(data_json): + res = requests.get('https://example.com/test0') + assert res.status_code == 200 + assert data_json.expected == res.json()