Align unit and int tests w.r.t. AC xapp
[ric-plt/a1.git] / tests / conftest.py
1 """
2 pytest conftest
3 """
4 # ==================================================================================
5 #       Copyright (c) 2019 Nokia
6 #       Copyright (c) 2018-2019 AT&T Intellectual Property.
7 #
8 #   Licensed under the Apache License, Version 2.0 (the "License");
9 #   you may not use this file except in compliance with the License.
10 #   You may obtain a copy of the License at
11 #
12 #          http://www.apache.org/licenses/LICENSE-2.0
13 #
14 #   Unless required by applicable law or agreed to in writing, software
15 #   distributed under the License is distributed on an "AS IS" BASIS,
16 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 #   See the License for the specific language governing permissions and
18 #   limitations under the License.
19 # ==================================================================================
20 import tempfile
21 import os
22 import pytest
23 from a1 import app
24
25
26 @pytest.fixture
27 def client():
28     """
29     http://flask.pocoo.org/docs/1.0/testing/
30     """
31
32     db_fd, app.app.config["DATABASE"] = tempfile.mkstemp()
33     app.app.config["TESTING"] = True
34     cl = app.app.test_client()
35
36     yield cl
37
38     os.close(db_fd)
39     os.unlink(app.app.config["DATABASE"])
40
41
42 @pytest.fixture
43 def adm_type_good():
44     """
45     represents a good put for adm control type
46     """
47     return {
48         "name": "Policy for Rate Control",
49         "policy_type_id": 6660666,
50         "description": "This policy is associated with rate control. An instance of the policy specifies the traffic class to which it applies and parameters to use to control how much it must be throttled in case of an overload. Each instance of the policy that is created MUST be associated with a unique class ID (identifyed by the key 'class', which is used by the xAPP to differentiate traffic. If an agent tries to create a policy with the SAME class id, it will be rejected by the xAPP, even if it has a unique policy instance id. ",
51         "create_schema": {
52             "$schema": "http://json-schema.org/draft-07/schema#",
53             "type": "object",
54             "additionalProperties": False,
55             "properties": {
56                 "class": {
57                     "type": "integer",
58                     "minimum": 1,
59                     "maximum": 256,
60                     "description": "integer id representing class to which we are applying policy",
61                 },
62                 "enforce": {
63                     "type": "boolean",
64                     "description": "Whether to enable or disable enforcement of policy on this class",
65                 },
66                 "window_length": {
67                     "type": "integer",
68                     "minimum": 15,
69                     "maximum": 300,
70                     "description": "Sliding window length in seconds",
71                 },
72                 "trigger_threshold": {"type": "integer", "minimum": 1},
73                 "blocking_rate": {"type": "number", "minimum": 0, "maximum": 100},
74             },
75             "required": ["class", "enforce", "blocking_rate", "trigger_threshold", "window_length"],
76         },
77     }
78
79
80 @pytest.fixture
81 def adm_instance_good():
82     """
83     represents a good put for adm control instance
84     """
85     return {"class": 12, "enforce": True, "window_length": 20, "blocking_rate": 20, "trigger_threshold": 10}