def test_list(self): """Test case to list all IKEPolicies""" 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_put(self): """Test case to update an IPsecPolicy""" self.url = self.url_prefix + self.uuid + '/' print(self.url) self._update_values = [ {'name': 'new_ipsecpolicy1'}, {'description': 'new_myipsecpolicy1'}, {'transform_protocol': 'esp'}, {'encryption_algorithm': ['3des']}, {'integrity_algorithm': ['sha1']}, {'dh_group': ['modp2048']}, {'encapsulation_mode': 'tunnel'}, {'lifetime_value': 8100}, {'lifetime_units': 'hours'}, ] for update_value in self._update_values: print(self.url) print(update_value) 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.ipsecpolicy with the new attribute value for key, value in update_value.items(): setattr(self.ipsecpolicy, key, value) 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_get(self): """Test case to get or show an IKEPolicy""" self.url = self.url_prefix + self.uuid + '/' print(self.url) response = self.client.get(self.url) 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_post(self): """Test case to create an IKEPolicy""" # 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') 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 test_patch(self): """Test case to update an IKEPolicy""" self.url = self.url_prefix + self.uuid + '/' self._update_values = [ { 'name': 'new_ikepolicy1' }, { 'description': 'new_myikepolicy1' }, { 'ike_version': 'v2' }, { 'encryption_algorithm': ['3des'] }, { 'integrity_algorithm': ['sha1'] }, { 'dh_group': ['modp2048'] }, { 'phase1_negotiation_mode': 'main' }, { 'lifetime_value': 8100 }, { 'lifetime_units': 'hours' }, { 'rekey': 'no' }, { 'reauth': 'yes' }, ] for update_value in self._update_values: response = self.client.patch(self.url, update_value, format='json') 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.ikepolicy, key, value) self.assertEqual(unicode_to_ascii_dict(response.data), unicode_to_ascii_dict(self.data))
def test_put_with_invalid_values(self): """Test case to update an IPsecPolicy with invalid value of attributes""" self.url = self._url_prefix + self.uuid + '/' self._invalid_values = [ {'id': generate_uuid()}, # 'id' update not allowed {'transform_protocol': 'ahesp'}, {'transform_protocol': '500'}, {'integrity_algorithm': 'md5'}, {'integrity_algorithm': '200'}, {'encryption_algorithm': 'des'}, {'encryption_algorithm': '100'}, {'dh_group': 'modp2000'}, {'dh_group': '120'}, {'encapsulation_mode': 'dynamic'}, {'encapsulation_mode': 'tun'}, {'lifetime_units': 'Megabytes'}, {'lifetime_units': '20000'}, {'lifetime_value': -20}, {'lifetime_value': 'Megabytes'} ] for update_value in self._invalid_values: response = self.client.put(self.url, update_value, format='json') self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) LOG.debug(unicode_to_ascii_dict(response.data))
def test_put_with_invalid_values(self): """Test case to update an VPNEndpointRemoteSite with invalid value of attributes""" self.url = self._url_prefix + self.uuid + '/' self._invalid_values = [ { 'id': generate_uuid() }, # 'id' update not allowed { 'name': '' }, { 'peer_cidrs': '' }, { 'peer_cidrs': '10.1.23.45/24' }, { 'vpncertificate_id': generate_uuid() } ] for update_value in self._invalid_values: response = self.client.put(self.url, update_value, format='json') print response.data self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) LOG.debug(unicode_to_ascii_dict(response.data))
def test_patch_with_invalid_values(self): """Test case to update an IKEpolicy with invalid value of attributes""" self.url = self._url_prefix + self.uuid + '/' self._invalid_values = [ #{'id': generate_uuid()}, # 'id' update not allowed { 'integrity_algorithm': 'md5' }, { 'integrity_algorithm': '200' }, { 'encryption_algorithm': 'des' }, { 'encryption_algorithm': '100' }, { 'phase1_negotiation_mode': '100' }, { 'ike_version': 'v6' }, { 'ike_version': '500' }, { 'dh_group': 'modp2000' }, { 'dh_group': '120' }, { 'lifetime_units': 'Megabytes' }, { 'lifetime_units': '20000' }, { 'lifetime_value': -20 }, { 'lifetime_value': 'Megabytes' } ] for update_value in self._invalid_values: response = self.client.patch(self.url, update_value, format='json') self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) LOG.debug(unicode_to_ascii_dict(response.data))
def test_put(self): """Test case to update an VPNEndpointGroup""" self.url = self.url_prefix + self.uuid + '/' self._update_values = [ { 'name': 'new_group1' }, { 'description': 'new_mygroup1' }, ] for update_value in self._update_values: response = self.client.put(self.url, update_value, format='json') 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.vpnendpointgroup, key, value) self.assertEqual(unicode_to_ascii_dict(response.data), unicode_to_ascii_dict(self.data))