示例#1
0
    def verify_file(
        self, filename: str, parser: QueryParser, renderer: DataclassesRenderer
    ) -> None:
        root, _s = os.path.splitext(filename)
        target_filename = "".join([root, ".py"])
        dir_name = os.path.dirname(target_filename)

        with open(filename, "r") as fin:
            query = fin.read()
            parsed = parser.parse(query)
            rendered = renderer.render(parsed)
            with open(target_filename, "r") as f:
                file_content = f.read()
                self.assert_rendered_file(target_filename, file_content, rendered)
            enums = renderer.render_enums(parsed)
            for enum_name, code in enums.items():
                target_enum_filename = os.path.join(
                    dir_name, "".join([get_enum_filename(enum_name), ".py"])
                )
                with open(target_enum_filename, "r") as f:
                    file_content = f.read()
                    self.assert_rendered_file(target_enum_filename, file_content, code)
            input_objects = renderer.render_input_objects(parsed)
            for input_object_name, code in input_objects.items():
                target_input_object_filename = os.path.join(
                    dir_name, "".join([get_input_filename(input_object_name), ".py"])
                )
                with open(target_input_object_filename, "r") as f:
                    file_content = f.read()
                    self.assert_rendered_file(
                        target_input_object_filename, file_content, code
                    )
示例#2
0
    def test_simple_query_with_missing_enums(self):
        query = """
            query MyIssues {
              viewer {
                issues(first: 5) {
                  edges {
                    node {
                      author { login }
                      authorAssociation
                    }
                  }
                }
              }
            }
        """
        parsed = self.github_parser.parse(query)

        rendered_enums = self.github_dataclass_renderer.render_enums(parsed)
        for enum_name, enum_code in rendered_enums.items():
            self.load_module(enum_code,
                             module_name=get_enum_filename(enum_name))

        rendered = self.github_dataclass_renderer.render(parsed)
        # TODO T66492306
        rendered = remove_dirname_in_import(dirname=ENUM_DIRNAME,
                                            rendered=rendered)
        m = self.load_module(rendered)

        response = m.MyIssues.from_json("""
            {
                "data": {
                    "viewer": {
                        "issues": {
                            "edges": [
                                {
                                    "node": {
                                        "author": { "login": "******" },
                                        "authorAssociation": "VALUE_THAT_DOES_NOT_EXIST"
                                    }
                                }
                            ]
                        }
                    }
                }
            }
            """)

        assert response

        node = response.data.viewer.issues.edges[0].node
        assert node
        assert node.author.login == "whatever"
        assert node.authorAssociation == m.CommentAuthorAssociation.MISSING_ENUM
示例#3
0
    def test_simple_query_with_enums(self):
        query = """
            query MyIssues {
              viewer {
                issues(first: 5) {
                  edges {
                    node {
                      author { login }
                      authorAssociation
                    }
                  }
                }
              }
            }
        """
        parsed = self.github_parser.parse(query)

        rendered_enums = self.github_dataclass_renderer.render_enums(parsed)
        for enum_name, enum_code in rendered_enums.items():
            self.load_module(enum_code,
                             module_name=get_enum_filename(enum_name))

        rendered = self.github_dataclass_renderer.render(parsed)
        m = self.load_module(rendered)

        response = m.MyIssues.from_json("""
            {
                "data": {
                    "viewer": {
                        "issues": {
                            "edges": [
                                {
                                    "node": {
                                        "author": { "login": "******" },
                                        "authorAssociation": "FIRST_TIMER"
                                    }
                                }
                            ]
                        }
                    }
                }
            }
            """)

        assert response

        node = response.data.viewer.issues.edges[0].node
        assert node
        assert node.author.login == "whatever"
        assert node.authorAssociation == m.CommentAuthorAssociation.FIRST_TIMER