-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpytest_fixture_catalog.py
More file actions
105 lines (93 loc) · 4.1 KB
/
Copy pathpytest_fixture_catalog.py
File metadata and controls
105 lines (93 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# pytest_fixture_catalog.py
# This script contains Pytest test cases for catalog API endpoints.
# It tests listing all catalogs, creating new catalogs, getting details of single catalogs,
# deleting catalogs, and listing all catalogs after various operations.
# Authors: Edoardo Sabatini - Data Worker and ChatGPT 3.5 Python Programmer
# Date: May 22, 2024
import pytest
@pytest.mark.usefixtures("client")
class TestCatalogAPI:
def test_list_all_catalogs(self, client):
"""
Test: List all catalogs.
Expectation: A list of catalogs is returned.
"""
response = client.get('/api/catalogs')
assert response.status_code == 200
data = response.get_json()
assert isinstance(data, dict)
assert 'catalogs' in data
assert isinstance(data['catalogs'], list)
assert len(data['catalogs']) >= 0 # Ensure there are catalogs in the list
def test_create_new_catalog(self, client):
"""
Test: Create a new catalog.
Expectation: A new catalog is successfully created.
"""
response = client.post('/api/catalog', json={})
assert response.status_code == 201 # Assuming 201 Created is the expected response code
data = response.get_json()
assert 'catalog_id' in data
assert isinstance(data['catalog_id'], int) # Ensure the catalog_id is an integer
def test_get_single_catalog_6(self, client):
"""
Test: Get details of a single catalog (ID 6).
Expectation: The details of the catalog with ID 6 are returned.
"""
response = client.get('/api/catalogs')
assert response.status_code == 200
data = response.get_json()
assert isinstance(data, dict)
assert 'catalogs' in data
assert isinstance(data['catalogs'], list)
assert len(data['catalogs']) == 6 # Ensure there are catalogs in the list
response = client.get(f'/api/catalog/6')
assert response.status_code == 200
data = response.get_json()
assert data.get('catalog', {}).get('id') == 6
def test_delete_catalog(self, client):
"""
Test: Delete a catalog (ID 3).
Expectation: The catalog with ID 3 is successfully deleted.
"""
# Deleting catalog with ID 3
print("Deleting catalog with ID 3:")
print("DELETE /api/catalog/3")
response = client.delete('/api/catalog/3')
assert response.status_code == 200 # Modify expected status code if necessary
print("------------------------------------------------------")
def test_get_single_catalog_3(self, client):
"""
Test: Get details of a single catalog (ID 3).
Expectation: The details of the catalog with ID 3 are returned.
"""
response = client.get('/api/catalogs')
assert response.status_code == 200
data = response.get_json()
assert isinstance(data, dict)
assert 'catalogs' in data
assert isinstance(data['catalogs'], list)
assert len(data['catalogs']) == 5 # Ensure there are catalogs in the list
response = client.get(f'/api/catalog/3')
assert response.status_code == 404
def test_recreate_catalog(self, client):
"""
Test: Recreate the catalog.
Expectation: A new catalog is successfully created.
"""
response = client.post('/api/catalog', json={})
assert response.status_code == 201 # Assuming 201 Created is the expected response code
data = response.get_json()
assert 'catalog_id' in data
assert isinstance(data['catalog_id'], int) # Ensure the catalog_id is an integer
def test_list_all_catalogs_after_operations(self, client):
"""
Test: List all catalogs after performing create, delete, and recreate operations.
Expectation: A list of catalogs is returned.
"""
response = client.get('/api/catalogs')
assert response.status_code == 200
data = response.get_json()
assert isinstance(data, dict)
assert 'catalogs' in data
assert isinstance(data['catalogs'], list)