Example #1
0
    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"
            )
Example #2
0
    def test_delete_mutation_outputs(self):
        # delete the list of inputs
        inputs = delete_mutation_outputs(self.model_service)

        # the output of a delete mutation is a status message indicating wether or
        # not the mutation was successful

        from nautilus.api.util import summarize_mutation_io

        # the only input for delete events is the pk of the service record
        expected = [
            summarize_mutation_io(name='status', type='String', required=True)
        ]

        # make sure the result matches what we expected
        assert inputs == expected, ("Delete mutation outputs were incorrect")
Example #3
0
    def test_delete_mutation_outputs(self):
        # delete the list of inputs
        inputs = delete_mutation_outputs(self.model_service)

        # the output of a delete mutation is a status message indicating wether or
        # not the mutation was successful

        from nautilus.api.util import summarize_mutation_io

        # the only input for delete events is the pk of the service record
        expected = [summarize_mutation_io(name='status', type='String', required=True)]

        # make sure the result matches what we expected
        assert inputs == expected, (
            "Delete mutation outputs were incorrect"
        )