Repository navigation
Expand file tree
/
Copy pathtest_api.py
More file actions
45 lines (38 loc) · 1.58 KB
/
Copy pathtest_api.py
File metadata and controls
45 lines (38 loc) · 1.58 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
import unittest
from flask import Flask
from battery_schedule import app
class TestScheduleAPI(unittest.TestCase):
def setUp(self):
# Set up Flask test client
self.client = app.test_client()
self.client.testing = True
def test_get_schedule(self):
# Test the basic schedule endpoint
response = self.client.get('/schedule?top-up=false')
self.assertEqual(response.status_code, 200)
data = response.get_json()
self.assertIn('costs', data)
self.assertIn('power_schedule', data)
self.assertIn('soc_schedule', data)
def test_get_schedule_top_up(self):
# Test the schedule endpoint with top-up
response = self.client.get('/schedule?top-up=true')
self.assertEqual(response.status_code, 200)
data = response.get_json()
self.assertIn('costs', data)
self.assertIn('power_schedule', data)
self.assertIn('soc_schedule', data)
def test_infeasible_soc_target(self):
# Mock a case where the SOC target is infeasible
response = self.client.get('/schedule?top-up=false&soc-target=150')
data = response.get_json()
self.assertEqual(response.status_code, 400)
self.assertIn('error', data)
def test_invalid_parameters(self):
# Simulate a scenario with invalid parameters
response = self.client.get('/schedule?top-up=false&soc-max=10&soc-min=90')
data = response.get_json()
self.assertEqual(response.status_code, 400)
self.assertIn('error', data)
if __name__ == '__main__':
unittest.main()