# Path: bgpvpn_dashboard/api/bgpvpn.py
# LOG = logging.getLogger(__name__)
# class Bgpvpn(neutron.NeutronAPIDictWrapper):
# class NetworkAssociation(neutron.NeutronAPIDictWrapper):
# class RouterAssociation(neutron.NeutronAPIDictWrapper):
# def bgpvpns_list(request, **kwargs):
# def bgpvpn_get(request, bgpvpn_id, **kwargs):
# def bgpvpn_create(request, **kwargs):
# def bgpvpn_update(request, bgpvpn_id, **kwargs):
# def bgpvpn_delete(request, bgpvpn_id):
# def network_association_get(request, bgpvpn_id, network_assoc_id, **kwargs):
# def network_association_list(request, bgpvpn_id, **kwargs):
# def network_association_create(request, bgpvpn_id, **kwargs):
# def network_association_delete(request, resource_id, bgpvpn_id):
# def router_association_get(request, bgpvpn_id, router_assoc_id, **kwargs):
# def router_association_list(request, bgpvpn_id, **kwargs):
# def router_association_create(request, bgpvpn_id, **kwargs):
# def router_association_update(request, bgpvpn_id, router_association_id,
#                               **kwargs):
# def router_association_delete(request, resource_id, bgpvpn_id):
# 
# Path: bgpvpn_dashboard/dashboards/admin/bgpvpn/forms.py
#     RTRD_REGEX = constants.RTRD_REGEX[1:-1]
# RTRDS_REGEX = '^%s( *, *%s)*$' % (RTRD_REGEX, RTRD_REGEX)
# class CommonData(project_forms.CommonData):
# class CreateBgpVpn(CommonData):
# class EditDataBgpVpn(CommonData):
# class CreateNetworkAssociation(project_forms.CreateNetworkAssociation):
#     def __init__(self, request, *args, **kwargs):
#     def __init__(self, request, *args, **kwargs):
#     def __init__(self, request, *args, **kwargs):
#     def _set_params(self, data):
# 
# Path: bgpvpn_dashboard/dashboards/project/bgpvpn/forms.py
# LOG = logging.getLogger(__name__)
# class CommonData(forms.SelfHandlingForm):
# class EditDataBgpVpn(CommonData):
# class CreateNetworkAssociation(forms.SelfHandlingForm):
#     def __init__(self, request, *args, **kwargs):
#     def _del_attributes(attributes, data):
#     def handle(self, request, data):
#     def __init__(self, request, *args, **kwargs):
#     def __init__(self, request, *args, **kwargs):
#     def handle(self, request, data):
#     def _set_params(self, data):


from unittest import mock
from openstack_dashboard.test import helpers
from bgpvpn_dashboard.api import bgpvpn as bgpvpn_api
from bgpvpn_dashboard.dashboards.admin.bgpvpn import forms as bgpvpn_a_form
from bgpvpn_dashboard.dashboards.project.bgpvpn import forms as bgpvpn_p_form


class Tenant(object):
    def __init__(self, id, name, enabled):
        self.id = id
        self.name = name
        self.enabled = enabled


class TestCreateDataBgpVpn(helpers.APITestCase):

    @mock.patch.object(bgpvpn_a_form, 'api')
    def setUp(self, mock_api):
        super(TestCreateDataBgpVpn, self).setUp()
        self.mock_request = mock.MagicMock()

    @mock.patch.object(bgpvpn_p_form, 'bgpvpn_api')
    @mock.patch.object(bgpvpn_a_form, 'api')
    def test_invalid_rt(self, mock_api, mock_bgpvpn_api):
        mock_api.keystone.tenant_list.return_value = [], False
        mock_bgpvpn_api.list_bgpvpns.return_value = []
        data = {"route_targets": "xyz",
                "import_targets": "0",
                "export_targets": "64512:1000000000000, xyz"}
        self.bgpvpn_form = bgpvpn_a_form.CreateBgpVpn(self.mock_request, data)

        self.assertTrue(self.bgpvpn_form.has_error("route_targets"))
        self.assertTrue(self.bgpvpn_form.has_error("import_targets"))
        self.assertTrue(self.bgpvpn_form.has_error("export_targets"))


# Path: bgpvpn_dashboard/api/bgpvpn.py
# LOG = logging.getLogger(__name__)
# class Bgpvpn(neutron.NeutronAPIDictWrapper):
# class NetworkAssociation(neutron.NeutronAPIDictWrapper):
# class RouterAssociation(neutron.NeutronAPIDictWrapper):
# def bgpvpns_list(request, **kwargs):
# def bgpvpn_get(request, bgpvpn_id, **kwargs):
# def bgpvpn_create(request, **kwargs):
# def bgpvpn_update(request, bgpvpn_id, **kwargs):
# def bgpvpn_delete(request, bgpvpn_id):
# def network_association_get(request, bgpvpn_id, network_assoc_id, **kwargs):
# def network_association_list(request, bgpvpn_id, **kwargs):
# def network_association_create(request, bgpvpn_id, **kwargs):
# def network_association_delete(request, resource_id, bgpvpn_id):
# def router_association_get(request, bgpvpn_id, router_assoc_id, **kwargs):
# def router_association_list(request, bgpvpn_id, **kwargs):
# def router_association_create(request, bgpvpn_id, **kwargs):
# def router_association_update(request, bgpvpn_id, router_association_id,
#                               **kwargs):
# def router_association_delete(request, resource_id, bgpvpn_id):
# 
# Path: bgpvpn_dashboard/dashboards/admin/bgpvpn/forms.py
#     RTRD_REGEX = constants.RTRD_REGEX[1:-1]
# RTRDS_REGEX = '^%s( *, *%s)*$' % (RTRD_REGEX, RTRD_REGEX)
# class CommonData(project_forms.CommonData):
# class CreateBgpVpn(CommonData):
# class EditDataBgpVpn(CommonData):
# class CreateNetworkAssociation(project_forms.CreateNetworkAssociation):
#     def __init__(self, request, *args, **kwargs):
#     def __init__(self, request, *args, **kwargs):
#     def __init__(self, request, *args, **kwargs):
#     def _set_params(self, data):
# 
# Path: bgpvpn_dashboard/dashboards/project/bgpvpn/forms.py
# LOG = logging.getLogger(__name__)
# class CommonData(forms.SelfHandlingForm):
# class EditDataBgpVpn(CommonData):
# class CreateNetworkAssociation(forms.SelfHandlingForm):
#     def __init__(self, request, *args, **kwargs):
#     def _del_attributes(attributes, data):
#     def handle(self, request, data):
#     def __init__(self, request, *args, **kwargs):
#     def __init__(self, request, *args, **kwargs):
#     def handle(self, request, data):
#     def _set_params(self, data):


# Path: bgpvpn_dashboard/test/admin/test_forms.py
from unittest import mock
from openstack_dashboard.test import helpers
from bgpvpn_dashboard.api import bgpvpn as bgpvpn_api
from bgpvpn_dashboard.dashboards.admin.bgpvpn import forms as bgpvpn_a_form
from bgpvpn_dashboard.dashboards.project.bgpvpn import forms as bgpvpn_p_form



class Tenant(object):
    def __init__(self, id, name, enabled):
        self.id = id
        self.name = name
        self.enabled = enabled


class TestCreateDataBgpVpn(helpers.APITestCase):

    @mock.patch.object(bgpvpn_a_form, 'api')
    def setUp(self, mock_api):
        super(TestCreateDataBgpVpn, self).setUp()
        self.mock_request = mock.MagicMock()

    @mock.patch.object(bgpvpn_p_form, 'bgpvpn_api')
    @mock.patch.object(bgpvpn_a_form, 'api')
    def test_invalid_rt(self, mock_api, mock_bgpvpn_api):
        mock_api.keystone.tenant_list.return_value = [], False
        mock_bgpvpn_api.list_bgpvpns.return_value = []
        data = {"route_targets": "xyz",
                "import_targets": "0",
                "export_targets": "64512:1000000000000, xyz"}
        self.bgpvpn_form = bgpvpn_a_form.CreateBgpVpn(self.mock_request, data)

        self.assertTrue(self.bgpvpn_form.has_error("route_targets"))
        self.assertTrue(self.bgpvpn_form.has_error("import_targets"))
        self.assertTrue(self.bgpvpn_form.has_error("export_targets"))


    @mock.patch.object(bgpvpn_p_form, 'bgpvpn_api')