示例#1
0
    def setUp(self):

        self.data = deepcopy(VPNENDPOINTREMOTESITE_RECORD)

        # Add vpncertificate id to test record
        self.certificates = Certificates()
        self.certificates.prepare_vpncertificate()
        self.data.update({'vpncertificate_id': self.certificates.cert_id})

        self.url_prefix = COMMON_URL_PREFIX + "vpnendpointremotesites/"
        # Store the test record in storage
        if not self._testMethodName.startswith('test_post'):
            self.uuid = generate_uuid()  # Generate an id except for POST
            self.data.update({'id': self.uuid})
            self.vpnendpointremotesite = VPNEndpointRemoteSite(
                **self.data).save()

        # For POST & List,
        # Use the url with name 'vpnendpointremotesites_list' in urls.py file
        if self._testMethodName.startswith('test_post') or \
                self._testMethodName.startswith('test_list'):
            self.url = reverse('vpnendpointremotesites_list',
                               kwargs={
                                   'version': 'v1',
                                   'namespace': 'main'
                               })
class TestIKEPolicyCRUD(APITestCase):
    """Test case for CRUD operations on IKEPolicy"""

    def setUp(self):

        self.data = deepcopy(VPNCACERTIFICATE_RECORD)

        self.certificates = Certificates()
        fp = self.certificates.create_cacertificate()
        self.data.update({'ca_certificate': fp})

        self.url_prefix = COMMON_URL_PREFIX + "vpncacertificates/"
        # Store the test record in storage
        if not self._testMethodName.startswith('test_post'):
            self.uuid = generate_uuid()  # Generate an id except for POST
            self.data.update({'id': self.uuid})
            self.ikepolicy = VPNCACertificate(**self.data).save()

        # For POST & List,
        # Use the url with name 'vpncacertificates_list' in urls.py file
        if self._testMethodName.startswith('test_post') or \
                self._testMethodName.startswith('test_list'):
            self.url = reverse('vpncacertificates_list', kwargs={
                'version': 'v1',
                'namespace': 'main'
                })

    def tearDown(self):
        # Delete the test record in storage and revert storage to original
        # state.
        if self._testMethodName.startswith('test_post'):
            # Use 'id' of POST response
            VPNCACertificate.get(id=self.uuid).delete()
        else:
            self.ikepolicy.delete()

    def test_post(self):
        """Test case to create an IKEPolicy"""
        # No 'id' provided
        print(self.data)
        response = self.client.post(self.url, self.data, format='multipart')
        print(response.data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.uuid = response.data.pop('id')
        print(response.data)
        response.data.pop('ca_certificate')
        self.data.pop('ca_certificate')
        LOG.info(self.data)
        LOG.info(response.data)
        self.assertTrue(is_valid_uuid(self.uuid))
        self.assertEqual(unicode_to_ascii_dict(response.data),
                         unicode_to_ascii_dict(self.data))
    def setUp(self):

        self.data = deepcopy(VPNCACERTIFICATE_RECORD)

        self.certificates = Certificates()
        fp = self.certificates.create_cacertificate()
        self.data.update({'ca_certificate': fp})

        self.url_prefix = COMMON_URL_PREFIX + "vpncacertificates/"
        # Store the test record in storage
        if not self._testMethodName.startswith('test_post'):
            self.uuid = generate_uuid()  # Generate an id except for POST
            self.data.update({'id': self.uuid})
            self.ikepolicy = VPNCACertificate(**self.data).save()

        # For POST & List,
        # Use the url with name 'vpncacertificates_list' in urls.py file
        if self._testMethodName.startswith('test_post') or \
                self._testMethodName.startswith('test_list'):
            self.url = reverse('vpncacertificates_list', kwargs={
                'version': 'v1',
                'namespace': 'main'
                })
示例#4
0
class TestVPNEndpointRemoteSiteCRUD(APITestCase):
    """Test case for CRUD operations on VPNEndpointRemoteSite"""
    def setUp(self):

        self.data = deepcopy(VPNENDPOINTREMOTESITE_RECORD)

        # Add vpncertificate id to test record
        self.certificates = Certificates()
        self.certificates.prepare_vpncertificate()
        self.data.update({'vpncertificate_id': self.certificates.cert_id})

        self.url_prefix = COMMON_URL_PREFIX + "vpnendpointremotesites/"
        # Store the test record in storage
        if not self._testMethodName.startswith('test_post'):
            self.uuid = generate_uuid()  # Generate an id except for POST
            self.data.update({'id': self.uuid})
            self.vpnendpointremotesite = VPNEndpointRemoteSite(
                **self.data).save()

        # For POST & List,
        # Use the url with name 'vpnendpointremotesites_list' in urls.py file
        if self._testMethodName.startswith('test_post') or \
                self._testMethodName.startswith('test_list'):
            self.url = reverse('vpnendpointremotesites_list',
                               kwargs={
                                   'version': 'v1',
                                   'namespace': 'main'
                               })

    def tearDown(self):
        self.certificates.delete_vpncertificate()

        # Delete the test record in storage and revert storage to original
        # state.
        if self._testMethodName.startswith('test_post'):
            # Use 'id' of POST response
            VPNEndpointRemoteSite.get(id=self.uuid).delete()
        else:
            self.vpnendpointremotesite.delete()

    def test_post(self):
        """Test case to create an VPNEndpointRemoteSite"""
        # No 'id' provided
        response = self.client.post(self.url, self.data, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.uuid = response.data.pop('id')
        print(self.data)
        print(response.data)
        self.assertTrue(is_valid_uuid(self.uuid))

        self.assertEqual(unicode_to_ascii_dict(response.data),
                         unicode_to_ascii_dict(self.data))

    def test_post_id(self):
        # 'id' provided
        self.uuid = generate_uuid()
        self.data.update({'id': self.uuid})
        response = self.client.post(self.url, self.data, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(unicode_to_ascii_dict(response.data),
                         unicode_to_ascii_dict(self.data))

    def test_list(self):
        """Test case to list all VPNEndpointRemoteSites"""
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertTrue(
            unicode_to_ascii_dict(self.data) in unicode_to_ascii_dict(
                response.data))

    def test_get(self):
        """Test case to get or show an VPNEndpointRemoteSite"""
        self.url = self.url_prefix + self.uuid + '/'
        print(self.url)
        response = self.client.get(self.url)
        print(response.data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(unicode_to_ascii_dict(response.data),
                         unicode_to_ascii_dict(self.data))

    def test_delete(self):
        """Test case to delete an VPNEndpointRemoteSite"""
        self.url = self.url_prefix + self.uuid + '/'
        response = self.client.delete(self.url)
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

    def test_put(self):
        """Test case to update an VPNEndpointRemoteSite"""
        self.url = self.url_prefix + self.uuid + '/'
        self._update_values = [
            {
                'name': 'new_remotesite1'
            },
            {
                'description': 'new_myremotesite1'
            },
        ]

        for update_value in self._update_values:
            response = self.client.put(self.url, update_value, format='json')
            print(response.data)
            self.assertEqual(response.status_code, status.HTTP_200_OK)
            self.data.update(update_value)

            # Update the self.ikepolicy with the new attribute value
            for key, value in update_value.items():
                setattr(self.vpnendpointremotesite, key, value)

            self.assertEqual(unicode_to_ascii_dict(response.data),
                             unicode_to_ascii_dict(self.data))