Ejemplo n.º 1
0
    def test_profile_rule_show_human_readable(self, m_print, m_client_get_profile):
        """
        Test for profile_rule_show function when human_readable=True
        """
        # Set up arguments
        profile_name = 'Profile_1'

        # Set up mock objects
        m_Rule = Mock(spec=Rule)
        m_Rule.pprint = Mock()
        m_Rules = Mock(spec=Rules, id=profile_name, inbound_rules=[m_Rule],
                       outbound_rules=[m_Rule])
        m_Profile = Mock(spec=Profile, name=profile_name, rules=m_Rules)
        m_client_get_profile.return_value = m_Profile

        # Call method under test
        profile_rule_show(profile_name, human_readable=True)

        # Assert
        m_client_get_profile.assert_called_once_with(profile_name)
        m_print.assert_has_calls([
            call.write('Inbound rules:'),
            call.write('\n'),
            call.write(' %3d %s' % (1, m_Rule.pprint())),
            call.write('\n'),
            call.write('Outbound rules:'),
            call.write('\n'),
            call.write(' %3d %s' % (1, m_Rule.pprint())),
            call.write('\n'),
        ])
Ejemplo n.º 2
0
    def test_profile_rule_show_human_readable(self, m_print,
                                              m_client_get_profile):
        """
        Test for profile_rule_show function when human_readable=True
        """
        # Set up arguments
        profile_name = 'Profile_1'

        # Set up mock objects
        m_Rule = Mock(spec=Rule)
        m_Rule.pprint = Mock()
        m_Rules = Mock(spec=Rules,
                       id=profile_name,
                       inbound_rules=[m_Rule],
                       outbound_rules=[m_Rule])
        m_Profile = Mock(spec=Profile, name=profile_name, rules=m_Rules)
        m_client_get_profile.return_value = m_Profile

        # Call method under test
        profile_rule_show(profile_name, human_readable=True)

        # Assert
        m_client_get_profile.assert_called_once_with(profile_name)
        m_print.assert_has_calls([
            call.write('Inbound rules:'),
            call.write('\n'),
            call.write(' %3d %s' % (1, m_Rule.pprint())),
            call.write('\n'),
            call.write('Outbound rules:'),
            call.write('\n'),
            call.write(' %3d %s' % (1, m_Rule.pprint())),
            call.write('\n'),
        ])
Ejemplo n.º 3
0
    def test_profile_rule_show(self, m_client_get_profile):
        """
        Test for profile_rule_show function when human_readable=False
        """
        # Set up arguments
        profile_name = 'Profile_1'

        # Set up mock objects
        m_Rules = Mock(spec=Rules, id=profile_name)
        m_Profile = Mock(spec=Profile, name=profile_name, rules=m_Rules)
        m_client_get_profile.return_value = m_Profile

        # Call method under test
        profile_rule_show(profile_name, human_readable=False)

        # Assert
        m_client_get_profile.assert_called_once_with(profile_name)
        m_Profile.rules.to_json.assert_called_once_with(indent=2)
Ejemplo n.º 4
0
    def test_profile_rule_show(self, m_client_get_profile):
        """
        Test for profile_rule_show function when human_readable=False
        """
        # Set up arguments
        profile_name = 'Profile_1'

        # Set up mock objects
        m_Rules = Mock(spec=Rules, id=profile_name)
        m_Profile = Mock(spec=Profile, name=profile_name, rules=m_Rules)
        m_client_get_profile.return_value = m_Profile

        # Call method under test
        profile_rule_show(profile_name, human_readable=False)

        # Assert
        m_client_get_profile.assert_called_once_with(profile_name)
        m_Profile.rules.to_json.assert_called_once_with(indent=2)