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_create_mutation_inputs(self):
        # create the list of inputs
        inputs = create_mutation_inputs(self.model_service)
        # make sure the inputs match the model
        from nautilus.api.util import summarize_mutation_io
        # the dictionary of fields corresponding to the service record
        field_dict = self.model_service.model._meta.fields

        # the expected values
        expected = [summarize_mutation_io(name=key, type=_graphql_type_string(value), required=(not value.null)) \
                        for key,value in field_dict.items()]

        # make sure the pk isn't required
        expected.remove([field for field in expected
                         if field['name'] == 'id'][0])

        assert inputs == expected, (
            "Create mutation inputs did not match expecttations")
Example #3
0
    def test_create_mutation_inputs(self):
        # create the list of inputs
        inputs = create_mutation_inputs(self.model_service)
        # make sure the inputs match the model
        from nautilus.api.util import summarize_mutation_io
        # the dictionary of fields corresponding to the service record
        field_dict = self.model_service.model._meta.fields

        # the expected values
        expected = [summarize_mutation_io(name=key, type=_graphql_type_string(value), required=(not value.null)) \
                        for key,value in field_dict.items()]

        # make sure the pk isn't required
        expected.remove([field for field in expected if field['name'] == 'id'][0])

        assert inputs == expected, (
            "Create mutation inputs did not match expecttations"
        )