示例#1
0
    def test_interpolated_value_string(self):
        arbitrary_query = QueryDefinition.parse_obj({
            "select": ['{Maiden Name} as "mn"'],
            "from":
            "issues",
        })
        self.mock_jira.fields = Mock(return_value=[
            {
                "name": "Maiden Name",
                "id": "customfield10011"
            },
        ])

        query = Executor(self.mock_jira, arbitrary_query, True)

        actual_results = list(query)
        expected_results = [
            {
                "mn": "Ivanovna"
            },
            {
                "mn": "Jackson"
            },
            {
                "mn": "Chartreuse"
            },
        ]

        assert expected_results == actual_results
示例#2
0
    def test_interpolated_value_resource(self):
        arbitrary_query = QueryDefinition.parse_obj({
            "select": ['{Result Object}.ok as "ro"'],
            "from":
            "issues",
        })
        self.mock_jira.fields = Mock(return_value=[
            {
                "name": "Result Object",
                "id": "customfield10012"
            },
        ])

        query = Executor(self.mock_jira, arbitrary_query, True)

        actual_results = list(query)
        expected_results = [
            {
                "ro": "yes"
            },
            {
                "ro": "no"
            },
            {
                "ro": "maybe"
            },
        ]

        assert expected_results == actual_results
示例#3
0
    def test_interpolated_value_nonstring(self):
        arbitrary_query = QueryDefinition.parse_obj({
            "select": ['{Jellybean Guess} as "jb"'],
            "from":
            "issues",
        })
        self.mock_jira.fields = Mock(return_value=[
            {
                "name": "Jellybean Guess",
                "id": "customfield10010"
            },
        ])

        query = Executor(self.mock_jira, arbitrary_query, True)

        actual_results = list(query)
        expected_results = [
            {
                "jb": 50
            },
            {
                "jb": 55
            },
            {
                "jb": 56
            },
        ]

        assert expected_results == actual_results
示例#4
0
    def test_cap(self):
        query = QueryDefinition.parse_obj({
            "select": ["key"],
            "from": "issues",
            "cap": 1,
        })

        query = Executor(self.mock_jira, query)

        actual_results = list(query)
        assert len(actual_results) == 1
示例#5
0
    def test_autoextract_sum(self):
        query = QueryDefinition.parse_obj({
            "select": ['sum(transactions.byCurrency.usd) as "value"'],
            "from":
            "issues",
            "group_by": ["True"],
        })
        query = Executor(self.mock_jira, query)

        actual_results = list(query)[0]["value"]
        expected_results = 110

        assert expected_results == actual_results
示例#6
0
    def test_autoextract_internal_array(self):
        query = QueryDefinition.parse_obj({
            "select": [
                'sum(extract(flatten_list(worklogs.worklogs), "timespentSeconds")) as "value"'
            ],
            "from":
            "issues",
            "group_by": ["True"],
        })
        query = Executor(self.mock_jira, query)

        actual_results = list(query)[0]["value"]
        expected_results = 105

        assert expected_results == actual_results
示例#7
0
    def test_interpolated_value_nonresource(self):
        arbitrary_query = QueryDefinition.parse_obj({
            "select": ['{Beep Boop} as "bb"'],
            "from":
            "issues",
        })
        self.mock_jira.fields = Mock(return_value=[
            {
                "name": "Beep Boop",
                "id": "customfield10013"
            },
        ])

        query = Executor(self.mock_jira, arbitrary_query, True)

        actual_results = list(query)
        for result in actual_results:
            assert isinstance(result["bb"], NonResource)
示例#8
0
    def test_filter(self):
        query = QueryDefinition.parse_obj({
            "select": ["key"],
            "from":
            "issues",
            "filter": ["summary != 'My Ticket #2'"],
        })

        query = Executor(self.mock_jira, query)

        actual_results = list(query)
        expected_results = [
            {
                "key": "ALPHA-1",
            },
            {
                "key": "ALPHA-3",
            },
        ]

        assert expected_results == actual_results
示例#9
0
    def test_simple_wprogress(self):
        query = QueryDefinition.parse_obj({
            "select": ["key"],
            "from": "issues",
        })

        query = Executor(self.mock_jira, query, True)

        actual_results = list(query)
        expected_results = [
            {
                "key": "ALPHA-1",
            },
            {
                "key": "ALPHA-3",
            },
            {
                "key": "ALPHA-2",
            },
        ]

        assert expected_results == actual_results
示例#10
0
    def test_group_by_aggregation(self):
        query = QueryDefinition.parse_obj({
            "select": ["issuetype", "len(key)"],
            "from": "issues",
            "group_by": ["issuetype"],
            "sort_by": ["len(key)"],
        })

        query = Executor(self.mock_jira, query)

        actual_results = list(query)
        expected_results = [
            {
                "issuetype": "Bug",
                "len(key)": 1,
            },
            {
                "issuetype": "Issue",
                "len(key)": 2,
            },
        ]

        assert expected_results == actual_results
示例#11
0
    def test_field_name_map(self):
        arbitrary_query = QueryDefinition.parse_obj({
            "select": ["key"],
            "from": "issues",
        })
        self.mock_jira.fields = Mock(return_value=[
            {
                "name": "Story Points",
                "id": "customfield10010"
            },
            {
                "name": "Sprint",
                "id": "customfield10011"
            },
        ])
        query = Executor(self.mock_jira, arbitrary_query, True)

        expected_result = {
            "Story Points": "customfield10010",
            "Sprint": "customfield10011",
        }
        actual_result = query.field_name_map

        assert expected_result == actual_result
示例#12
0
    def test_sort_by(self):
        query = QueryDefinition.parse_obj({
            "select": ["key"],
            "from":
            "issues",
            "sort_by": ["story_points desc", "key"],
        })

        query = Executor(self.mock_jira, query)

        actual_results = list(query)
        expected_results = [
            {
                "key": "ALPHA-3",
            },
            {
                "key": "ALPHA-1",
            },
            {
                "key": "ALPHA-2",
            },
        ]

        assert expected_results == actual_results
示例#13
0
 def get_query(self, issues: List[Dict], query: QueryDefinition):
     return Executor(Mock(search_issues=Mock(return_value=issues)), query)