Exemplo n.º 1
0
def create_sample_template():
    template = {
        "label":
        "SensorModel",
        "attrs": [{
            "label": "temperature",
            "type": "dynamic",
            "value_type": "float"
        }, {
            "label": "position",
            "type": "dynamic",
            "value_type": "geopoint"
        }, {
            "label": "model-id",
            "type": "static",
            "value_type": "string",
            "static_value": "model-001"
        }, {
            "label": "shared_key",
            "type": "static",
            "value_type": "psk"
        }]
    }
    req = {
        'headers': {
            'authorization': generate_token(),
            'Content-Type': 'application/json'
        },
        'args': {},
        'body': json.dumps(template)
    }

    result = TemplateHandler.create_template(Request(req))
    template_id = result['template']['id']
    return template_id
Exemplo n.º 2
0
    def test_create_tempĺate(self, db_mock):
        db_mock.session = AlchemyMagicMock()
        token = generate_token()

        data = """{
            "label": "SensorModel",
            "attrs": [
                {
                    "label": "temperature",
                    "type": "dynamic",
                    "value_type": "float"
                },
                {
                    "label": "model-id",
                    "type": "static",
                    "value_type": "string",
                    "static_value": "model-001"
                }
            ]
        }"""

        params_query = {'content_type': 'application/json', 'data': data}
        result = TemplateHandler.create_template(params_query, token)
        self.assertIsNotNone(result)
        self.assertEqual(result['result'], 'ok')
        self.assertIsNotNone(result['template'])