Exemplo n.º 1
0
 def test_bad_password(self, mock_post):
     '''todo: this is currently not implemented in plantpredict.Api'''
     mock_post.return_value.ok = False
     mock_post.return_value.content = '{"error":"invalid_grant","error_description":"The credentials provided were invalid."}'
     api = plantpredict.Api(
         username="******",
         password="******",
         client_id="0oakq",
         client_secret="IEdpr")
     mock_post.assert_called()
Exemplo n.º 2
0
    def test_init(self, mock_post):
        mock_post.return_value.ok = True
        mock_post.return_value.content = '''{"access_token":"dummy_access_token",
                                            "refresh_token":"dummy_refresh_token"}'''
        api = plantpredict.Api(
            username="******",
            password="******",
            client_id="0oakq",
            client_secret="IEdpr")

        mock_post.assert_called()
        api.refresh_access_token()
        self.assertTrue(mock_post.call_count == 2)
    def test_init(self, mock_api_post):
        mock_api_post.return_value.ok = True
        mock_api_post.return_value.content = '''{"access_token":"dummy_access_token",
                                            "refresh_token":"dummy_refresh_token"}'''
        api = plantpredict.Api(
            username="******",
            password="******",
            client_id="0oakq",
            client_secret="IEdpr")

        geo = Geo(api=api, latitude=39.67, longitude=-105.21)
        self.assertIsInstance(geo, Geo)
        self.assertIsInstance(geo.api, plantpredict.Api)
        self.assertEqual(geo.latitude, 39.67)
        self.assertEqual(geo.longitude, -105.21)
"""This file contains the code for "Create project from scratch" in the "Example Usage" section of the
documentation located at https://plantpredict-python.readthedocs.io."""

import plantpredict
from plantpredict.enumerations import PredictionStatusEnum, TranspositionModelEnum, SpectralShiftModelEnum, \
    DiffuseDirectDecompositionModelEnum, ModuleTemperatureModelEnum, IncidenceAngleModelTypeEnum, \
    AirMassModelTypeEnum, DirectBeamShadingModelEnum, SoilingModelTypeEnum, DegradationModelEnum, \
    TrackingTypeEnum, BacktrackingTypeEnum, DiffuseShadingModelEnum

# authenticate using API credentials
api = plantpredict.Api(username="******",
                       password="******",
                       client_id="insert client_id here",
                       client_secret="insert client_secret here")

# instantiate a local instance of Project, assigning name, latitude, and longitude
project = api.project(name="Area 51 Alien Power Plant",
                      latitude=37.23,
                      longitude=-115.80)

# assign location attributes with helper method, and create in the PlantPredict database
project.assign_location_attributes()
project.create()

# instantiate a local instance of Prediction, assigning project_id (from the newly created project) and name
prediction = api.prediction(project_id=project.id, name="Area 51 - Contracted")

# assign the weather_id corresponding to the weather file you want to use (assuming it already exists in the
# PlantPredict database).
prediction.weather_id = 13628