def test_get_collector(self): """Test case to get or show Collector.""" self.url = self.url_prefix + self.uuid + '/' 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_collector_with_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_post_collector(self): """Test case to create Collector.""" # 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') self.assertTrue(is_valid_uuid(self.uuid)) self.assertEqual(unicode_to_ascii_dict(response.data), unicode_to_ascii_dict(self.data))
def test_put_collector(self): """Test case to update Collector.""" self.url = self.url_prefix + self.uuid + '/' self._update_values = { 'id': self.uuid, 'name': 'new_collector1', 'ip_address': '10.42.0.12', 'udp_port': 2055, 'col_type': 'netflow', 'encapsulation_protocol': '', } response = self.client.put(self.url, self._update_values, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.data.update(self._update_values) # Update the self.collector with the new attribute value for key, value in self._update_values.items(): setattr(self.collector, key, value) self.assertEqual(unicode_to_ascii_dict(response.data), unicode_to_ascii_dict(self.data))
def test_put_collector_with_invalid_values(self): """Test case to update a Collector with invalid value of attributes""" self.url = self.url_prefix + self.uuid + '/' self._invalid_values = { 'id': generate_uuid(), # 'id' update not allowed 'name': 'new_collector1', 'ip_address': '10.42.0.12', 'udp_port': 70000, 'col_type': 'netflow', 'encapsulation_protocol': '', } response = self.client.put(self.url, self._invalid_values, format='json') self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) LOG.debug(unicode_to_ascii_dict(response.data))
def test_post_collector_with_invalid_values(self): """Test case to create Collector with invalid values""" self._invalid_values = { 'name': 'collector2', 'ip_address': '10.42.0.12', 'udp_port': '80000', 'col_type': 'rawforward', 'encapsulation_protocol': 'sflow', } # for update_value in self._invalid_values: self.data.update(self._invalid_values) response = self.client.post(self.url, self._invalid_values, format='json') self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) LOG.debug(unicode_to_ascii_dict(response.data))
def test_list_collector(self): """Test case to list all Collector.""" 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))