# Path: upcloud_api/firewall.py
# class FirewallRule(UpCloudResource):
#     """
#     Class representation of the API's firewall rule. Extends UpCloudResource.
#     """
# 
#     ATTRIBUTES = {
#         'action': 'drop',
#         'direction': 'in',
#         'family': 'IPv4',
#         'comment': '',
#         'destination_address_end': None,
#         'destination_address_start': None,
#         'destination_port_end': None,
#         'destination_port_start': None,
#         'icmp_type': None,
#         'position': None,
#         'protocol': None,
#         'source_address_end': None,
#         'source_address_start': None,
#         'source_port_end': None,
#         'source_port_start': None,
#     }
# 
#     def destroy(self):
#         """
#         Remove this FirewallRule from the API.
# 
#         This instance must be associated with a server for this method to work,
#         which is done by instantiating via server.get_firewall_rules().
#         """
#         if not hasattr(self, 'server') or not self.server:
#             raise Exception(
#                 """FirewallRule not associated with server;
#                 please use or server.get_firewall_rules() to get objects
#                 that are associated with a server.
#                 """
#             )
#         return self.server.cloud_manager.delete_firewall_rule(self.server.uuid, self.position)


import json
import responses
from conftest import Mock
from upcloud_api import FirewallRule
        Mock.mock_get(target, 'firewall_rules.json')
        firewall_rules = server.get_firewall_rules()

        assert firewall_rules[0].position == '1'

    @responses.activate
    def test_configure_firewall(self, manager):
        Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
        server = manager.get_server('00798b85-efdc-41ca-8021-f6ef457b8531')

        responses.add_callback(
            responses.POST,
            Mock.base_url + '/server/00798b85-efdc-41ca-8021-f6ef457b8531/firewall_rule',
            content_type='application/json',
            callback=firewall_rule_callback,
        )

        returned_firewall = server.configure_firewall(
            [
                FirewallRule(
                    position='1',
                    direction='in',
                    family='IPv4',
                    protocol='tcp',
                    source_address_start='192.168.1.1',
                    source_address_end='192.168.1.255',
                    destination_port_start='22',
                    destination_port_end='22',
                    action='accept',
                ),

# Path: upcloud_api/firewall.py
# class FirewallRule(UpCloudResource):
#     """
#     Class representation of the API's firewall rule. Extends UpCloudResource.
#     """
# 
#     ATTRIBUTES = {
#         'action': 'drop',
#         'direction': 'in',
#         'family': 'IPv4',
#         'comment': '',
#         'destination_address_end': None,
#         'destination_address_start': None,
#         'destination_port_end': None,
#         'destination_port_start': None,
#         'icmp_type': None,
#         'position': None,
#         'protocol': None,
#         'source_address_end': None,
#         'source_address_start': None,
#         'source_port_end': None,
#         'source_port_start': None,
#     }
# 
#     def destroy(self):
#         """
#         Remove this FirewallRule from the API.
# 
#         This instance must be associated with a server for this method to work,
#         which is done by instantiating via server.get_firewall_rules().
#         """
#         if not hasattr(self, 'server') or not self.server:
#             raise Exception(
#                 """FirewallRule not associated with server;
#                 please use or server.get_firewall_rules() to get objects
#                 that are associated with a server.
#                 """
#             )
#         return self.server.cloud_manager.delete_firewall_rule(self.server.uuid, self.position)


# Path: test/test_firewall.py
import json
import responses
from conftest import Mock
from upcloud_api import FirewallRule

        Mock.mock_get(target, 'firewall_rules.json')
        firewall_rules = server.get_firewall_rules()

        assert firewall_rules[0].position == '1'

    @responses.activate
    def test_configure_firewall(self, manager):
        Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
        server = manager.get_server('00798b85-efdc-41ca-8021-f6ef457b8531')

        responses.add_callback(
            responses.POST,
            Mock.base_url + '/server/00798b85-efdc-41ca-8021-f6ef457b8531/firewall_rule',
            content_type='application/json',
            callback=firewall_rule_callback,
        )

        returned_firewall = server.configure_firewall(
            [
                FirewallRule(
                    position='1',
                    direction='in',
                    family='IPv4',
                    protocol='tcp',
                    source_address_start='192.168.1.1',
                    source_address_end='192.168.1.255',
                    destination_port_start='22',
                    destination_port_end='22',
                    action='accept',
                ),

                FirewallRule(