calibsunapi 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.1
2
+ Name: calibsunapi
3
+ Version: 0.0.2
4
+ Summary: Lightweight client to interact with Calibsun's API
5
+ Author-email: Calibsun <rpartouche@calibsun.com>
6
+ Project-URL: Homepage, https://github.com/pypa/sampleproject
7
+ Project-URL: Issues, https://github.com/pypa/sampleproject/issues
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+
14
+ # Welcome to calibsunapi's documentation!
15
+
16
+ Calibsunapi is a Python client for interacting with the CalibSun API. This package allows developers to easily integrate and communicate with the CalibSun services, providing functionalities such as data retrieval, data submission, and various API interactions.
17
+
18
+ It is designed to be simple, efficient, and easy to use, and provides different abstractions making it an ideal choice for developers looking to leverage CalibSun's capabilities in their Python applications.
19
+
20
+
21
+ ## Getting help
22
+
23
+ Having troubles installing or using Calibsunapi ? Feel free to ask questions at any of the contact methods or file an issue on [Calibsunapi's GitHub page](https://github.com/SOLAIS-FORECAST/api-python-client).
24
+
25
+
26
+ Documentation : https://github.com/SOLAIS-FORECAST/api-python-client
@@ -0,0 +1,13 @@
1
+ # Welcome to calibsunapi's documentation!
2
+
3
+ Calibsunapi is a Python client for interacting with the CalibSun API. This package allows developers to easily integrate and communicate with the CalibSun services, providing functionalities such as data retrieval, data submission, and various API interactions.
4
+
5
+ It is designed to be simple, efficient, and easy to use, and provides different abstractions making it an ideal choice for developers looking to leverage CalibSun's capabilities in their Python applications.
6
+
7
+
8
+ ## Getting help
9
+
10
+ Having troubles installing or using Calibsunapi ? Feel free to ask questions at any of the contact methods or file an issue on [Calibsunapi's GitHub page](https://github.com/SOLAIS-FORECAST/api-python-client).
11
+
12
+
13
+ Documentation : https://github.com/SOLAIS-FORECAST/api-python-client
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.1
2
+ Name: calibsunapi
3
+ Version: 0.0.2
4
+ Summary: Lightweight client to interact with Calibsun's API
5
+ Author-email: Calibsun <rpartouche@calibsun.com>
6
+ Project-URL: Homepage, https://github.com/pypa/sampleproject
7
+ Project-URL: Issues, https://github.com/pypa/sampleproject/issues
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+
14
+ # Welcome to calibsunapi's documentation!
15
+
16
+ Calibsunapi is a Python client for interacting with the CalibSun API. This package allows developers to easily integrate and communicate with the CalibSun services, providing functionalities such as data retrieval, data submission, and various API interactions.
17
+
18
+ It is designed to be simple, efficient, and easy to use, and provides different abstractions making it an ideal choice for developers looking to leverage CalibSun's capabilities in their Python applications.
19
+
20
+
21
+ ## Getting help
22
+
23
+ Having troubles installing or using Calibsunapi ? Feel free to ask questions at any of the contact methods or file an issue on [Calibsunapi's GitHub page](https://github.com/SOLAIS-FORECAST/api-python-client).
24
+
25
+
26
+ Documentation : https://github.com/SOLAIS-FORECAST/api-python-client
@@ -0,0 +1,8 @@
1
+ README.md
2
+ pyproject.toml
3
+ calibsunapi.egg-info/PKG-INFO
4
+ calibsunapi.egg-info/SOURCES.txt
5
+ calibsunapi.egg-info/dependency_links.txt
6
+ calibsunapi.egg-info/top_level.txt
7
+ tests/test_client.py
8
+ tests/test_token.py
@@ -0,0 +1,34 @@
1
+ [project]
2
+ name = "calibsunapi"
3
+ version = "0.0.2"
4
+ authors = [
5
+ { name="Calibsun", email="rpartouche@calibsun.com" },
6
+ ]
7
+ description = "Lightweight client to interact with Calibsun's API"
8
+ readme = "README.md"
9
+ requires-python = ">=3.8"
10
+ classifiers = [
11
+ "Programming Language :: Python :: 3",
12
+ "License :: OSI Approved :: MIT License",
13
+ "Operating System :: OS Independent",
14
+ ]
15
+ dynamic = ["dependencies"]
16
+
17
+ [project.urls]
18
+ Homepage = "https://github.com/pypa/sampleproject"
19
+ Issues = "https://github.com/pypa/sampleproject/issues"
20
+
21
+ [build-system]
22
+ requires = ["setuptools"]
23
+ build-backend = "setuptools.build_meta"
24
+
25
+ [metadata]
26
+ name = "calibsunapi"
27
+
28
+ [tool.setuptools.packages.find]
29
+ include = ["calibsun-api-client*"]
30
+ exclude = ["app*", "tests*"]
31
+
32
+ [tool.setuptools.dynamic]
33
+ dependencies = {file = ["requirements-calibsun-api-client.txt"]}
34
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,110 @@
1
+ from datetime import time
2
+ from unittest.mock import MagicMock, patch
3
+
4
+ import pytest
5
+
6
+ from calibsunapi.client import CalibsunApiClient
7
+ from calibsunapi.exceptions import NoCredentialsError, NotAuthenticatedError
8
+ from calibsunapi.models.listplants import Plant
9
+ from calibsunapi.models.uploadmeasurements import UploadMeasurementsFormats
10
+
11
+
12
+ @patch("calibsunapi.client.requests.post")
13
+ def test_authenticate_success(mock_post, client: CalibsunApiClient):
14
+ mock_response = MagicMock()
15
+ mock_response.json.return_value = {"access_token": "test_token", "expires_in": 3600, "token_type": "Bearer"}
16
+ mock_response.raise_for_status = MagicMock()
17
+ mock_post.return_value = mock_response
18
+
19
+ client._authenticate()
20
+
21
+ assert client._token is not None
22
+ assert client._token.access_token == "test_token"
23
+
24
+
25
+ @patch("calibsunapi.client.requests.post")
26
+ def test_authenticate_no_credentials(mock_post):
27
+ client = CalibsunApiClient()
28
+ print(client.calibsun_client_id)
29
+ with pytest.raises(NoCredentialsError):
30
+ client._authenticate()
31
+
32
+
33
+ @patch("calibsunapi.client.requests.get")
34
+ def test_list_plants(mock_get, authentified_client: CalibsunApiClient, plant):
35
+ mock_response = MagicMock()
36
+ site_id = plant.pop("site_id")
37
+ mock_response.json.return_value = {site_id: plant}
38
+ mock_response.raise_for_status = MagicMock()
39
+ mock_get.return_value = mock_response
40
+
41
+ plants = authentified_client.list_plants()
42
+
43
+ assert len(plants) == 1
44
+ assert isinstance(plants[0], Plant)
45
+ assert plants[0].site_id == site_id
46
+
47
+
48
+ @patch("calibsunapi.client.requests.post")
49
+ @patch("calibsunapi.client.requests.get")
50
+ def test_push_measurements(mock_get, mock_post, authentified_client: CalibsunApiClient):
51
+ mock_get_response = MagicMock()
52
+ mock_get_response.json.return_value = {"url": "http://example.com/upload", "fields": {"field1": "value1"}}
53
+ mock_get_response.raise_for_status = MagicMock()
54
+ mock_get.return_value = mock_get_response
55
+
56
+ mock_post_response = MagicMock()
57
+ mock_post_response.raise_for_status = MagicMock()
58
+ mock_post.return_value = mock_post_response
59
+
60
+ response = authentified_client.push_measurements("site_id", UploadMeasurementsFormats.JSON, data={"key": "value"})
61
+
62
+ assert response.raise_for_status.called
63
+
64
+
65
+ @patch("calibsunapi.client.requests.get")
66
+ def test_get_latest_forecast(mock_get, authentified_client: CalibsunApiClient):
67
+ mock_response = MagicMock()
68
+ mock_response.json.return_value = {"forecast": "data"}
69
+ mock_response.raise_for_status = MagicMock()
70
+ mock_get.return_value = mock_response
71
+
72
+ forecast = authentified_client.get_latest_forecast("site_id", "target")
73
+
74
+ assert forecast == {"forecast": "data"}
75
+
76
+
77
+ @patch("calibsunapi.client.requests.get")
78
+ def test_get_latest_forecast_probabilistic(mock_get, authentified_client: CalibsunApiClient):
79
+ mock_response = MagicMock()
80
+ mock_response.json.return_value = {"forecast": "probabilistic_data"}
81
+ mock_response.raise_for_status = MagicMock()
82
+ mock_get.return_value = mock_response
83
+
84
+ forecast = authentified_client.get_latest_forecast_probabilistic("site_id", "target")
85
+
86
+ assert forecast == {"forecast": "probabilistic_data"}
87
+
88
+
89
+ @patch("calibsunapi.client.requests.get")
90
+ def test_get_latest_forecast_deterministic(mock_get, authentified_client: CalibsunApiClient):
91
+ mock_response = MagicMock()
92
+ mock_response.json.return_value = {"forecast": "deterministic_data"}
93
+ mock_response.raise_for_status = MagicMock()
94
+ mock_get.return_value = mock_response
95
+
96
+ forecast = authentified_client.get_latest_forecast_deterministic("site_id", "target")
97
+
98
+ assert forecast == {"forecast": "deterministic_data"}
99
+
100
+
101
+ @patch("calibsunapi.client.requests.get")
102
+ def test_get_forecast(mock_get, authentified_client: CalibsunApiClient):
103
+ mock_response = MagicMock()
104
+ mock_response.json.return_value = {"forecast": "fixed_time_data"}
105
+ mock_response.raise_for_status = MagicMock()
106
+ mock_get.return_value = mock_response
107
+
108
+ forecast = authentified_client.get_forecast(time(0, 0), "site_id", "target")
109
+
110
+ assert forecast == {"forecast": "fixed_time_data"}
@@ -0,0 +1,20 @@
1
+ import time
2
+
3
+ import pytest
4
+
5
+ from calibsunapi.token import Token
6
+
7
+
8
+ def test_token_initialization():
9
+ token = Token(access_token="abc123", token_type="Bearer", expires_in=3600)
10
+ assert token.access_token == "abc123"
11
+ assert token.token_type == "Bearer"
12
+ assert token.expires_in == 3600
13
+ assert isinstance(token.created_at, float)
14
+
15
+
16
+ def test_token_is_expired():
17
+ token = Token(access_token="abc123", token_type="Bearer", expires_in=1.5)
18
+ assert not token.is_expired()
19
+ time.sleep(1.5)
20
+ assert token.is_expired()