def setUp(self):
        req = POST(config.ui_host, config.ui_port, "/auth")
        req.body(config.PERMIT_LOGIN)
        response, content = req()

        self.assertEqual(200, response.status)

        result = json.loads(content)
        self.assertEqual("success", result["status"])
        self.session = result["data"]["id"]

        req = POST(config.ui_host, config.ui_port, "/gateways")
        req.authorize(self.session)
        req.body(
            json.dumps({
                "id": config.gateway_id,
                "name": "Testing Gateway",
                "timezone_id": "Europe/Prague"
            }))
        response, _ = req()

        self.assertEqual(201, response.status)
    def test9_create_properties(self):
        properties = {"ip-address": "10.0.0.1", "password": "******"}

        for key, value in properties.items():
            req = POST(
                config.ui_host, config.ui_port,
                "/gateways/" + config.gateway_id +
                "/devices/0xa371959aad24618e/properties/" + key)
            req.authorize(self.session)
            req.body(json.dumps({"value": "10.0.0.1"}))
            response, content = req()

            self.assertEqual(200, response.status)

            req = DELETE(
                config.ui_host, config.ui_port,
                "/gateways/" + config.gateway_id +
                "/devices/0xa371959aad24618e/properties/" + key)
            req.authorize(self.session)
            response, content = req()

            self.assertEqual(204, response.status)
Exemplo n.º 3
0
    def test1_assign_unassign(self):
        # assign a prepared gateway
        req = POST(config.ui_host, config.ui_port, "/gateways")
        req.authorize(self.session)
        req.body(
            json.dumps({
                "id": config.gateway_id,
                "name": "My Home",
                "timezone_id": "Europe/Prague"
            }))

        response, content = req()
        self.assertEqual(201, response.status)
        self.assertEqual("/gateways/" + config.gateway_id,
                         response.getheader("Location"))

        # check the gateway's contents
        resultLink = response.getheader("Location")
        req = GET(config.ui_host, config.ui_port, resultLink)
        req.authorize(self.session)

        response, content = req()
        self.assertEqual(200, response.status)

        result = json.loads(content)
        self.assertEqual("success", result["status"])
        self.assertEqual("My Home", result["data"]["name"])
        self.assertEqual(config.gateway_id, result["data"]["id"])
        self.assertEqual("Europe/Prague", result["data"]["timezone"]["id"])

        # unassign the gateway
        req = DELETE(config.ui_host, config.ui_port,
                     "/gateways/" + config.gateway_id)
        req.authorize(self.session)
        response, content = req()

        self.assertEqual(204, response.status)

        # test the gateway is inaccessible
        req = GET(config.ui_host, config.ui_port, resultLink)
        req.authorize(self.session)

        response, content = req()
        self.assertEqual(403, response.status)
        result = json.loads(content)
        self.assertEqual(403, result["code"])
        self.assertEqual("not enough permission to access the resource",
                         result["message"])