Example #1
0
class UnitTestBase(unittest.TestCase):
    """Top level test class for RainCloudy Core."""
    @requests_mock.Mocker()
    def setUp(self, mock):
        """Initialize rdy object for unittests."""
        from raincloudy.core import RainCloudy

        mock.get(LOGIN_ENDPOINT, text=load_fixture('home.html'))
        mock.get(SETUP_ENDPOINT, text=load_fixture('setup.html'))
        mock.get(STATUS_ENDPOINT,
                 text=load_fixture('get_cu_and_fu_status.json'))

        mock.post(LOGIN_ENDPOINT, text=load_fixture('home.html'))
        mock.get(HOME_ENDPOINT, text=load_fixture('home.html'))

        # initialize self.rdy object
        self.rdy = RainCloudy(USERNAME, PASSWORD, ssl_warnings=False)
        self.rdy.update()

    def cleanUp(self):
        """Cleanup any data created from the tests."""
        self.rdy = None

    def tearDown(self):
        """Stop everything initialized."""
        self.cleanUp()
Example #2
0
app = Flask(__name__)
app.config.from_object(__name__)
app.config['SECRET_KEY'] = '326240760871083756038276035325'

valid_commands = ["open", "auto", "close", "status", "rain"]
api_commands = "[controllerid]/[faucetid]/[open|close|status|rain/[zone#]/[time in mins/0/1]"

config = {
    "email": "EMAIL",  # fill in your email
    "password": "******"
}

controllers = {}

rdy = RainCloudy(config['email'], config['password'], ssl_warnings=False)
rdy.update()
for controller in rdy.controllers:
    print("Controller: " + controller.id + "  Status: " + controller.status)
    for faucet in controller.faucets:
        print("> Faucet: " + faucet.id + "  Status: " + faucet.status)


def status(rc):
    rc.update()
    # get controllers
    for controller in rc.controllers:
        if not controllers.get("controllers"):
            controllers['controllers'] = {}
        if not controllers['controllers'].get(controller.id):
            controllers["controllers"][controller.id] = {}
        controllers["controllers"][controller.id]['status'] = controller.status