File: test_batch_mutations.py

package info (click to toggle)
strawberry-graphql-django 0.62.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,968 kB
  • sloc: python: 27,530; sh: 17; makefile: 16
file content (117 lines) | stat: -rw-r--r-- 2,438 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"""Tests for batched mutations.

Batched mutations are mutations that mutate multiple objects at once.
Mutations with a filter function or accept a list of objects that return a list.
"""


def test_batch_create(mutation, fruits):
    result = mutation(
        """
        mutation {
          fruits: createFruits(
            data: [{ name: "banana" }, { name: "cherry" }]
          ) {
            id
            name
          }
        }
        """
    )
    assert not result.errors
    assert result.data["fruits"] == [
        {"id": "4", "name": "banana"},
        {"id": "5", "name": "cherry"},
    ]


def test_batch_delete_with_filter(mutation, fruits):
    result = mutation(
        """
        mutation($ids: [ID!]) {
          fruits: deleteFruits(
            filters: {id: {inList: $ids}}
          ) {
            id
            name
          }
        }
        """,
        {"ids": ["2"]},
    )
    assert not result.errors
    assert result.data["fruits"] == [
        {"id": "2", "name": "raspberry"},
    ]


def test_batch_delete_with_filter_empty_list(mutation, fruits):
    result = mutation(
        """
        {
          fruits: deleteFruits(
            filters: {id: {inList: []}}
          ) {
            id
            name
          }
        }
        """
    )
    assert not result.errors


def test_batch_update_with_filter(mutation, fruits):
    result = mutation(
        """
        {
          fruits: updateFruits(
            data: { name: "orange" }
            filters: {id: {inList: [1]}}
          ) {
            id
            name
          }
        }
        """
    )
    assert not result.errors
    assert result.data["fruits"] == [
        {"id": "1", "name": "orange"},
    ]


def test_batch_update_with_filter_empty_list(mutation, fruits):
    result = mutation(
        """
        {
          fruits: updateFruits(
            data: { name: "orange" }
            filters: {id: {inList: []}}
          ) {
            id
            name
          }
        }
        """
    )
    assert not result.errors


def test_batch_patch(mutation, fruits):
    result = mutation(
        """
        {
          fruits: patchFruits(
            data: [{ id: 2, name: "orange" }]
          ) {
            id
            name
          }
        }
        """
    )
    assert not result.errors
    assert result.data["fruits"] == [
        {"id": "2", "name": "orange"},
    ]