def test_tag_keys_dynamic_field_validation_success(self): """Test that tag keys are validated as fields.""" tag_keys = ["valid_tag"] query_params = {"valid_tag": "*"} serializer = OCPGCPGroupBySerializer(data=query_params, tag_keys=tag_keys) self.assertTrue(serializer.is_valid())
def test_tag_keys_dynamic_field_validation_failure(self): """Test that invalid tag keys are not valid fields.""" tag_keys = ["valid_tag"] query_params = {"bad_tag": "*"} serializer = OCPGCPGroupBySerializer(data=query_params, tag_keys=tag_keys) with self.assertRaises(serializers.ValidationError): serializer.is_valid(raise_exception=True)
def test_group_by_params_string_list_fields(self): """Test group_by params for handling string to list fields.""" group_params = {"instance_type": FAKE.word()} serializer = OCPGCPGroupBySerializer(data=group_params) validation = serializer.is_valid() self.assertTrue(validation) result = serializer.data.get("instance_type") self.assertIsInstance(result, list)
def test_all_group_by_op_fields(self): """Test that the allowed fields pass.""" for field in OCPGCPGroupBySerializer._opfields: field = "and:" + field filter_param = {field: ["1", "2"]} serializer = OCPGCPGroupBySerializer(data=filter_param) self.assertTrue(serializer.is_valid()) for field in OCPGCPGroupBySerializer._opfields: field = "or:" + field filter_param = {field: ["1", "2"]} serializer = OCPGCPGroupBySerializer(data=filter_param) self.assertTrue(serializer.is_valid())
def test_group_by_node(self): """Test group by node.""" group_params = {"node": ["*"]} serializer = OCPGCPGroupBySerializer(data=group_params) self.assertTrue(serializer.is_valid())
def test_group_by_cluster(self): """Test group by cluster.""" group_params = {"cluster": ["*"]} serializer = OCPGCPGroupBySerializer(data=group_params) self.assertTrue(serializer.is_valid())
def test_parse_group_by_project(self): """Test group by project.""" group_params = {"project": ["*"]} serializer = OCPGCPGroupBySerializer(data=group_params) self.assertTrue(serializer.is_valid())
def test_group_by_params_invalid_fields(self): """Test parse of group_by params for invalid fields.""" group_params = {"account": [FAKE.word()], "invalid": "param"} serializer = OCPGCPGroupBySerializer(data=group_params) with self.assertRaises(serializers.ValidationError): serializer.is_valid(raise_exception=True)
def test_parse_group_by_params_success(self): """Test parse of a group_by param successfully.""" group_params = {"region": [FAKE.uuid4()]} serializer = OCPGCPGroupBySerializer(data=group_params) self.assertTrue(serializer.is_valid())