<s> from neutron_lib import constants <EOL> from neutron . objects . qos import policy <EOL> from neutron . objects . qos import rule <EOL> from neutron . services . qos import qos_consts <EOL> from neutron . tests import base as neutron_test_base <EOL> from neutron . tests . unit . objects import test_base <EOL> from neutron . tests . unit import testlib_api <EOL> POLICY_ID_A = '<STR_LIT>' <EOL> POLICY_ID_B = '<STR_LIT>' <EOL> DEVICE_OWNER_COMPUTE = constants . DEVICE_OWNER_COMPUTE_PREFIX + '<STR_LIT>' <EOL> class QosRuleObjectTestCase ( neutron_test_base . BaseTestCase ) : <EOL> def _test_should_apply_to_port ( self , rule_policy_id , port_policy_id , <EOL> device_owner , expected_result ) : <EOL> test_rule = rule . QosRule ( qos_policy_id = rule_policy_id ) <EOL> port = { qos_consts . QOS_POLICY_ID : port_policy_id , <EOL> '<STR_LIT>' : device_owner } <EOL> self . assertEqual ( expected_result , test_rule . should_apply_to_port ( port ) ) <EOL> def test_should_apply_to_port_with_network_port_and_net_policy ( self ) : <EOL> self . _test_should_apply_to_port ( <EOL> rule_policy_id = POLICY_ID_B , <EOL> port_policy_id = POLICY_ID_A , <EOL> device_owner = constants . DEVICE_OWNER_ROUTER_INTF , <EOL> expected_result = False ) <EOL> def test_should_apply_to_port_with_network_port_and_port_policy ( self ) : <EOL> self . _test_should_apply_to_port ( <EOL> rule_policy_id = POLICY_ID_A , <EOL> port_policy_id = POLICY_ID_A , <EOL> device_owner = constants . DEVICE_OWNER_ROUTER_INTF , <EOL> expected_result = True ) <EOL> def test_should_apply_to_port_with_compute_port_and_net_policy ( self ) : <EOL> self . _test_should_apply_to_port ( <EOL> rule_policy_id = POLICY_ID_B , <EOL> port_policy_id = POLICY_ID_A , <EOL> device_owner = DEVICE_OWNER_COMPUTE , <EOL> expected_result = True ) <EOL> def test_should_apply_to_port_with_compute_port_and_port_policy ( self ) : <EOL> self . _test_should_apply_to_port ( <EOL> rule_policy_id = POLICY_ID_A , <EOL> port_policy_id = POLICY_ID_A , <EOL> device_owner = DEVICE_OWNER_COMPUTE , <EOL> expected_result = True ) <EOL> class QosBandwidthLimitRuleObjectTestCase ( test_base . BaseObjectIfaceTestCase ) : <EOL> _test_class = rule . QosBandwidthLimitRule <EOL> def test_to_dict_returns_type ( self ) : <EOL> obj = rule . QosBandwidthLimitRule ( self . context , ** self . db_obj ) <EOL> dict_ = obj . to_dict ( ) <EOL> self . assertEqual ( qos_consts . RULE_TYPE_BANDWIDTH_LIMIT , dict_ [ '<STR_LIT:type>' ] ) <EOL> class QosBandwidthLimitRuleDbObjectTestCase ( test_base . BaseDbObjectTestCase , <EOL> testlib_api . SqlTestCase ) : <EOL> _test_class = rule . QosBandwidthLimitRule <EOL> def setUp ( self ) : <EOL> super ( QosBandwidthLimitRuleDbObjectTestCase , self ) . setUp ( ) <EOL> generated_qos_policy_id = self . db_obj [ '<STR_LIT>' ] <EOL> policy_obj = policy . QosPolicy ( self . context , <EOL> id = generated_qos_policy_id ) <EOL> policy_obj . create ( ) <EOL> class QosDscpMarkingRuleObjectTestCase ( test_base . BaseObjectIfaceTestCase ) : <EOL> _test_class = rule . QosDscpMarkingRule <EOL> class QosDscpMarkingRuleDbObjectTestCase ( test_base . BaseDbObjectTestCase , <EOL> testlib_api . SqlTestCase ) : <EOL> _test_class = rule . QosDscpMarkingRule <EOL> def setUp ( self ) : <EOL> super ( QosDscpMarkingRuleDbObjectTestCase , self ) . setUp ( ) <EOL> generated_qos_policy_id = self . db_obj [ '<STR_LIT>' ] <EOL> policy_obj = policy . QosPolicy ( self . context , <EOL> id = generated_qos_policy_id ) <EOL> policy_obj . create ( ) </s>
