Ejemplo n.º 1
0
    def test_blueprint(self):

        class MyModel(types.Model):
            pass

        class MyParamSet(ParameterSet):
            pass

        param_set = MyParamSet()
        response_template = MyModel()
        parameter_sets = [param_set, param_set]
        body_template = MyModel()
        attribute_filter = AttributeFilter({"name": True})

        verb_config = VerbConfig(
            response_template=response_template,
            parameter_sets=parameter_sets,
            body_template=body_template,
            request_attribute_filter=attribute_filter
        )
        blueprint = verb_config.blueprint()
        self.assertEqual(blueprint["response_template"], response_template.blueprint())
        self.assertEqual(blueprint["parameter_sets"], [param_set.blueprint(), param_set.blueprint()])
        self.assertEqual(blueprint["body_template"], body_template.blueprint())
        self.assertEqual(blueprint["request_attribute_filter"], attribute_filter.blueprint())
Ejemplo n.º 2
0
 def test_init(self):
     # check that invalid config raises exception
     self.assertRaises(TypeError, Config, GET="string")
     self.assertRaises(TypeError, Config, GET=VerbConfig(), HEAD="string")
     self.assertRaises(TypeError, Config, HEAD="string")
     self.assertRaises(TypeError, Config, POST="string")
     self.assertRaises(TypeError, Config, PUT="string")
     self.assertRaises(TypeError, Config, PATCH="string")
     self.assertRaises(TypeError, Config, DELETE="string")
     self.assertRaises(TypeError,
                       Config,
                       OPTIONS="string",
                       PATCH=VerbConfig())
Ejemplo n.º 3
0
    def test_init_parameter_sets_single(self):
        param_set = ParameterSet()

        self.assertRaises(TypeError, VerbConfig, parameter_sets="string")

        verb_config = VerbConfig(parameter_sets=param_set)
        self.assertEqual(verb_config.parameter_sets, [param_set])
Ejemplo n.º 4
0
    def test_body_template(self):
        class MyModel(types.Model):
            pass

        model = MyModel()
        verb_config = VerbConfig(body_template=model)
        self.assertEqual(verb_config.body_template, model)
Ejemplo n.º 5
0
    def test_init_parameter_sets_array(self):
        param_set1 = ParameterSet()
        param_set2 = ParameterSet()

        self.assertRaises(TypeError, VerbConfig, parameter_sets=[param_set1, "string"])

        verb_config = VerbConfig(parameter_sets=[param_set1, param_set2])
        self.assertEqual(verb_config.parameter_sets, [param_set1, param_set2])
Ejemplo n.º 6
0
    def test_response_template(self):

        class MyModel(types.Model):
            pass

        model = MyModel()
        verb_config = VerbConfig(response_template=model)
        self.assertEqual(verb_config.response_template, model)
Ejemplo n.º 7
0
    def test_init_body_template(self):
        class MyModel(types.Model):
            pass

        my_model = MyModel()
        self.assertEqual(VerbConfig(body_template=my_model).body_template, my_model)

        self.assertRaises(TypeError, VerbConfig, body_template="string")
Ejemplo n.º 8
0
    def test_get_config_for_verb(self):
        get_verb_config = VerbConfig()
        head_verb_config = VerbConfig()
        post_verb_config = VerbConfig()
        put_verb_config = VerbConfig()
        patch_verb_config = VerbConfig()
        delete_verb_config = VerbConfig()
        options_verb_config = VerbConfig()

        config = Config(GET=get_verb_config,
                        HEAD=head_verb_config,
                        POST=post_verb_config,
                        PUT=put_verb_config,
                        PATCH=patch_verb_config,
                        DELETE=delete_verb_config,
                        OPTIONS=options_verb_config)
        self.assertEqual(config.get_config_for_verb(VERB.GET), get_verb_config)
        self.assertEqual(config.get_config_for_verb(VERB.HEAD),
                         head_verb_config)
        self.assertEqual(config.get_config_for_verb(VERB.POST),
                         post_verb_config)
        self.assertEqual(config.get_config_for_verb(VERB.PUT), put_verb_config)
        self.assertEqual(config.get_config_for_verb(VERB.PATCH),
                         patch_verb_config)
        self.assertEqual(config.get_config_for_verb(VERB.DELETE),
                         delete_verb_config)
        self.assertEqual(config.get_config_for_verb(VERB.OPTIONS),
                         options_verb_config)
Ejemplo n.º 9
0
    def test_init_response_template(self):
        class MyModel(types.Model):
            pass

        my_model = MyModel()
        verb_config = VerbConfig(response_template=my_model)
        self.assertEqual(verb_config.response_template, my_model)

        # todo: check correct attribute filter template is generated
        # self.assertEqual(verb_config.response_attribute_filter_template, AttributeFilter.from_model(
        #     model_instance=MyModel(),
        #     default_value=False
        # ))

        binary_response = types.BinaryResponse()
        self.assertEqual(VerbConfig(response_template=binary_response).response_template, binary_response)

        self.assertRaises(TypeError, VerbConfig, response_template="string")
Ejemplo n.º 10
0
    def test_delete(self):
        verb_config = VerbConfig()

        config = Config(DELETE=verb_config)
        self.assertEqual(config.delete, verb_config)
Ejemplo n.º 11
0
    def test_options(self):
        verb_config = VerbConfig()

        config = Config(OPTIONS=verb_config)
        self.assertEqual(config.options, verb_config)
Ejemplo n.º 12
0
    def test_patch(self):
        verb_config = VerbConfig()

        config = Config(PATCH=verb_config)
        self.assertEqual(config.patch, verb_config)
Ejemplo n.º 13
0
 def test_boolean_array(self):
     boolean_array = types.Array(element_template=types.Boolean())
     verb_config = VerbConfig(response_template=boolean_array)
     self.assertEqual(verb_config.response_template, boolean_array)
Ejemplo n.º 14
0
    def test_post(self):
        verb_config = VerbConfig()

        config = Config(POST=verb_config)
        self.assertEqual(config.post, verb_config)
Ejemplo n.º 15
0
    def test_put(self):
        verb_config = VerbConfig()

        config = Config(PUT=verb_config)
        self.assertEqual(config.put, verb_config)
Ejemplo n.º 16
0
    def test_get(self):
        verb_config = VerbConfig()

        config = Config(GET=verb_config)
        self.assertEqual(config.get, verb_config)
Ejemplo n.º 17
0
    def test_head(self):
        verb_config = VerbConfig()

        config = Config(HEAD=verb_config)
        self.assertEqual(config.head, verb_config)
Ejemplo n.º 18
0
 def test_float_array(self):
     float_array = types.Array(element_template=types.Float())
     verb_config = VerbConfig(response_template=float_array)
     self.assertEqual(verb_config.response_template, float_array)
Ejemplo n.º 19
0
 def test_integer_array(self):
     integer_array = types.Array(element_template=types.Integer())
     verb_config = VerbConfig(response_template=integer_array)
     self.assertEqual(verb_config.response_template, integer_array)
Ejemplo n.º 20
0
 def test_string_array(self):
     string_array = types.Array(element_template=types.String())
     verb_config = VerbConfig(response_template=string_array)
     self.assertEqual(verb_config.response_template, string_array)
Ejemplo n.º 21
0
 def test_blueprint_default(self):
     blueprint = VerbConfig().blueprint()
     self.assertIsNone(blueprint["response_template"])
     self.assertEqual(blueprint["parameter_sets"], [])
     self.assertIsNone(blueprint["body_template"])
     self.assertIsNone(blueprint["request_attribute_filter"])
Ejemplo n.º 22
0
    def test_init_request_attribute_filter(self):
        self.assertIsNone(VerbConfig().request_attribute_filter)

        attribute_filter = AttributeFilter()
        self.assertEqual(VerbConfig(request_attribute_filter=attribute_filter).request_attribute_filter, attribute_filter)
        self.assertRaises(TypeError, VerbConfig, request_attribute_filter="string")