-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_projects_api.py
More file actions
159 lines (119 loc) · 5.66 KB
/
Copy pathtest_projects_api.py
File metadata and controls
159 lines (119 loc) · 5.66 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# coding: utf-8
"""
Patch API V1
The core API used to integrate with Patch's service # noqa: E501
The version of the OpenAPI document: v1
Contact: [email protected]
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import unittest
import os
from patch_api.api_client import ApiClient
class TestProjectsApi(unittest.TestCase):
"""ProjectsApi unit test stubs"""
def setUp(self):
api_client = ApiClient(api_key=os.environ.get("SANDBOX_API_KEY"))
self.api = api_client.projects # noqa: E501
def tearDown(self):
self.api = None
def test_retrieve_project(self):
"""Test case for retrieve_project
Retrieves a project # noqa: E501
"""
project_id = "pro_test_2b67b11a030b66e0a6dd61a56b49079a"
project = self.api.retrieve_project(id=project_id).data
self.assertTrue(project)
self.assertEqual(project.production, False)
self.assertTrue(isinstance(project.photos, list))
self.assertTrue(hasattr(project, "tagline"))
self.assertTrue(hasattr(project, "latitude"))
self.assertTrue(hasattr(project, "longitude"))
self.assertTrue(hasattr(project, "highlights"))
self.assertTrue(isinstance(project.mechanism, str))
self.assertTrue(isinstance(project.state, str))
technology_type = project.technology_type
self.assertTrue(isinstance(technology_type.name, str))
self.assertTrue(isinstance(technology_type.slug, str))
parent_technology_type = technology_type.parent_technology_type
self.assertTrue(isinstance(parent_technology_type.name, str))
self.assertTrue(isinstance(parent_technology_type.slug, str))
inventory = project.inventory
self.assertTrue(isinstance(inventory, list))
self.assertTrue(isinstance(inventory[0].vintage_year, int))
self.assertTrue(isinstance(inventory[0].vintage_start_year, int))
self.assertTrue(isinstance(inventory[0].vintage_end_year, int))
self.assertTrue(isinstance(inventory[0].amount_available, int))
self.assertTrue(isinstance(inventory[0].price, int))
self.assertTrue(isinstance(inventory[0].currency, str))
self.assertTrue(isinstance(inventory[0].unit, str))
issuance_type = project.issuance_type
self.assertTrue(isinstance(issuance_type, str))
disclaimers = project.disclaimers
self.assertTrue(isinstance(disclaimers, list))
self.assertTrue(isinstance(disclaimers[0].header, str))
self.assertTrue(isinstance(disclaimers[0].body, str))
self.assertTrue(isinstance(disclaimers[0].severity, str))
self.assertTrue(isinstance(disclaimers[0].link_text, str))
self.assertTrue(isinstance(disclaimers[0].link_destination, str))
def test_retrieve_project_language(self):
"""Test case for retrieve_project
Retrieves a project # noqa: E501
"""
project_id = "pro_test_2b67b11a030b66e0a6dd61a56b49079a"
project = self.api.retrieve_project(id=project_id, accept_language="fr").data
self.assertIn("Démo", project.name) # French
def test_retrieve_projects(self):
"""Test case for retrieve_projects
Retrieves a list of projects # noqa: E501
"""
projects = self.api.retrieve_projects().data
self.assertTrue(isinstance(projects, list))
if len(projects) > 0:
project = projects[0]
self.assertEqual(project.production, False)
self.assertIsInstance(project.standard, object)
self.assertIsInstance(project.name, str)
self.assertTrue(project.description)
self.assertIsInstance(project.country, str)
self.assertIsInstance(project.project_partner, str)
self.assertIsInstance(project.photos, list)
def test_retrieve_biomass_projects(self):
"""Test case for retrieve_projects with a type filter
Retrieves a list of projects # noqa: E501
"""
project_type = "biomass"
projects = self.api.retrieve_projects(type=project_type).data
self.assertTrue(isinstance(projects, list))
for project in projects:
self.assertEqual(project.technology_type.slug, project_type)
def test_retrieve_american_projects(self):
"""Test case for retrieve_projects with a country filter
Retrieves a list of projects # noqa: E501
"""
project_country = "US"
projects = self.api.retrieve_projects(country=project_country).data
self.assertTrue(isinstance(projects, list))
for project in projects:
self.assertEqual(project.country, project_country)
def test_retrieve_projects_with_more_than_100_grams_of_inventory(self):
"""Test case for retrieve_projects with a country filter
Retrieves a list of projects # noqa: E501
"""
minimum_available_mass = 100
projects = self.api.retrieve_projects(
minimum_available_mass=minimum_available_mass
).data
self.assertTrue(isinstance(projects, list))
for project in projects:
remaining_amount = sum(inv.amount_available for inv in project.inventory)
self.assertTrue(remaining_amount >= minimum_available_mass)
def test_retrieve_projects_language(self):
"""Test case for retrieve_projects with a type filter
Retrieves a list of projects # noqa: E501
"""
projects = self.api.retrieve_projects(accept_language="fr").data
for project in projects:
self.assertIn("Démo", project.name) # French
if __name__ == "__main__":
unittest.main()