def test_can_summarize_model_mutations(self):


        # summarize the service
        summarized = self.service.summarize()

        # the target summary
        target = {
            'mutations': [
                {
                    'name': api_conventions.crud_mutation_name(action='create', model=self.model),
                    'event': conventions.get_crud_action(method='create', model=self.model),
                    'isAsync': False,
                    'inputs': api_conventions.create_mutation_inputs(self),
                    'outputs': api_conventions.create_mutation_outputs(self),
                },
                {
                    'name': api_conventions.crud_mutation_name(action='update', model=self.model),
                    'event': conventions.get_crud_action(method='update', model=self.model),
                    'isAsync': False,
                    'inputs': api_conventions.update_mutation_inputs(self),
                    'outputs': api_conventions.update_mutation_outputs(self),
                },
                {
                    'name': api_conventions.crud_mutation_name(action='delete', model=self.model),
                    'event': conventions.get_crud_action(method='delete', model=self.model),
                    'isAsync': False,
                    'inputs': api_conventions.delete_mutation_inputs(self),
                    'outputs': api_conventions.delete_mutation_outputs(self),
                },
            ]
        }

        # make sure the mutations match
        assert len(target['mutations']) == len(summarized['mutations']), (
            "Incorrect number of mutations in summary."
        )

        # go over every mutation in the
        for summarized_mutation in summarized['mutations']:

            # grab the corresponding entry in the target
            equiv = [mut for mut in target['mutations'] \
                                if mut['name'] == summarized_mutation['name']][0]
            # make sure the fields match up
            assert equiv['event'] == summarized_mutation['event'], (
                "Summarized mutation has the wrong event value"
            )
            assert equiv['isAsync'] == summarized_mutation['isAsync'], (
                "Summarized mutation has the wrong isAsync value"
            )
Beispiel #2
0
def summarize_crud_mutation(method, model, isAsync=False):
    """
        This function provides the standard form for crud mutations.
    """

    # create the approrpriate action type
    action_type = get_crud_action(method=method, model=model)
    # the name of the mutation
    name = crud_mutation_name(model=model, action=method)
    # a mapping of methods to input factories
    input_map = {
        'create': create_mutation_inputs,
        'update': update_mutation_inputs,
        'delete': delete_mutation_inputs,
    }
    # a mappting of methods to output factories
    output_map = {
        'create': create_mutation_outputs,
        'update': update_mutation_outputs,
        'delete': delete_mutation_outputs,
    }
    # the inputs for the mutation
    inputs = input_map[method](model)
    # the mutation outputs
    outputs = output_map[method](model)

    # return the appropriate summary
    return summarize_mutation(mutation_name=name,
                              event=action_type,
                              isAsync=isAsync,
                              inputs=inputs,
                              outputs=outputs)
Beispiel #3
0
    def test_crud_mutation_name(self):
        # import the utility
        from nautilus.conventions.api import crud_mutation_name

        # make sure we can generate a mutation name, and that it's a string
        assert isinstance(
            crud_mutation_name(self.model_service, 'create'),
            str), ("Could not generate string name for model service mutation")
Beispiel #4
0
    def test_crud_mutation_name(self):
        # import the utility
        from nautilus.conventions.api import crud_mutation_name

        # make sure we can generate a mutation name, and that it's a string
        assert isinstance(crud_mutation_name(self.model_service, 'create'), str), (
            "Could not generate string name for model service mutation"
        )
Beispiel #5
0
 def _verify_crud_mutation(self, model, action):
     # create the mutation
     summarized = summarize_crud_mutation(model=model, method=action)
     # make sure the name matches the convention
     assert summarized['name'] == crud_mutation_name(model=model, action=action), (
         "Summarized %s mutation did not have the right name." % action
     )
     # make sure the event is what we expect
     assert summarized['event'] == get_crud_action(model=model, method=action), (
         "Summarized %s mutation did not have the right event type." % action
     )
Beispiel #6
0
 def _verify_crud_mutation(self, model, action):
     # create the mutation
     summarized = summarize_crud_mutation(model=model, method=action)
     # make sure the name matches the convention
     assert summarized['name'] == crud_mutation_name(
         model=model, action=action), (
             "Summarized %s mutation did not have the right name." % action)
     # make sure the event is what we expect
     assert summarized['event'] == get_crud_action(
         model=model, method=action), (
             "Summarized %s mutation did not have the right event type." %
             action)
def summarize_crud_mutation(method, model, isAsync=False):
    """
        This function provides the standard form for crud mutations.
    """

    # create the approrpriate action type
    action_type = get_crud_action(method=method, model=model)
    # the name of the mutation
    name = crud_mutation_name(model=model, action=method)
    # a mapping of methods to input factories
    input_map = {"create": create_mutation_inputs, "update": update_mutation_inputs, "delete": delete_mutation_inputs}
    # a mappting of methods to output factories
    output_map = {
        "create": create_mutation_outputs,
        "update": update_mutation_outputs,
        "delete": delete_mutation_outputs,
    }
    # the inputs for the mutation
    inputs = input_map[method](model)
    # the mutation outputs
    outputs = output_map[method](model)

    # return the appropriate summary
    return summarize_mutation(mutation_name=name, event=action_type, isAsync=isAsync, inputs=inputs, outputs=outputs)