Exemplo n.º 1
0
def test_issue_8():

    client = Client()

    expected_response = {
        "data": {"issue8Create": {"ok": True, "result": {"text": "test_1"}}}
    }
    response = client.query(gql_1).json()
    verify_response(expected_response, response)

    expected_response = {"data": {"issue8Create": {"ok": True}}}
    response = client.query(gql_2).json()
    verify_response(expected_response, response)

    expected_response = {
        "data": {"issue8Update": {"ok": True, "result": {"id": "1", "text": "test_1_bis1"}}}
    }
    response = client.query(gql_3).json()
    verify_response(expected_response, response)

    expected_response = {
        "data": {"issue8Update": {"ok": True}}
    }
    response = client.query(gql_4).json()
    verify_response(expected_response, response)
Exemplo n.º 2
0
 def test_field(self):
     user = factories.UserFactory()
     client = Client()
     response = client.query(queries.ALL_USERS2)
     self.assertEqual(response.status_code, 200)
     data = response.json()
     self.assertIn("allUsers2", data["data"])
     self.assertTrue(data["data"]["allUsers2"])
     self.assertEqual(data["data"]["allUsers2"][0]["id"], str(user.id))
Exemplo n.º 3
0
 def test_filter_charfield_iexact(self):
     user = factories.UserFactory()
     query = queries.ALL_USERS3_WITH_FILTER % {
         "filter": 'email_Iexact: "%s"' % user.email,
         "fields": "username",
     }
     client = Client()
     response = client.query(query)
     self.assertEqual(response.status_code, 200, response.content)
     data = response.json()
     self.assertIn("allUsers3", data["data"])
     self.assertIn("results", data["data"]["allUsers3"])
     self.assertTrue(data["data"]["allUsers3"]["results"])
     self.assertEqual(data["data"]["allUsers3"]["results"][0]["username"],
                      user.username)
Exemplo n.º 4
0
def test_main():

    client = Client()
    variables = {
        "file": {
            "filename": "lorem1.txt",
            "content": b64_lorem
        },
        "image": {
            "filename": "fork1.jpg",
            "content": b64_img
        },
    }
    expected_response = json.loads("""
        {
        "data": {
            "testFileCreate": {
                "ok": true,
                "result": {
                    "id": "1",
                    "file": {
                        "filename": "lorem1.txt",
                        "size": 2941,
                        "url": "/media/lorem1.txt"
                    },
                    "image": {
                        "url": "/media/fork1.jpg",
                        "size": 39116,
                        "filename": "fork1.jpg"
                    }
                }
            }
        }
    }
    """)

    response = client.query(QUERY, variables=variables).json()
    verify_response(expected_response, response)
    assert response["data"]["testFileCreate"]["result"]["file"][
        "content"].startswith("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIG")
    assert response["data"]["testFileCreate"]["result"]["image"][
        "content"].startswith("/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAMCAg")
Exemplo n.º 5
0
class ParentTest:
    expected_status_code = 200
    expected_return_payload = {}

    @property
    def query(self):
        raise NotImplementedError()

    def setUp(self):
        self.user = factories.UserFactory()
        self.client = Client()
        self.response = self.client.query(self.query)
        self.data = self.response.json()

    def test_should_return_expected_status_code(self):
        self.assertEqual(self.response.status_code, self.expected_status_code)

    def test_should_return_expected_payload(self):
        self.assertEqual(self.response.json(), self.expected_return_payload,
                         self.response.content)
Exemplo n.º 6
0
def test_main():

    client = Client()

    for i in range(10):
        b = TestRelayB(text=str(i))
        b.save()
        for j in range(10):
            TestRelayA(text=str(i) + "-" + str(j), test_relay_b=b).save()

    query = """
    {
        testRelayBs(offset: 5, first: 1) {
            pageInfo {
            hasNextPage
            hasPreviousPage
            startCursor
            endCursor
            }
            edges {
            cursor
            node {
                id
                text
                testRelayAs(offset: 5, first: 1) {
                pageInfo {
                    hasNextPage
                    hasPreviousPage
                    startCursor
                    endCursor
                }
                edges {
                    cursor
                    node {
                    id
                    text
                    }
                }
                }
            }
            }
        }
    }
    """

    expected_response = json.loads(
        """
            {
                "data": {
                    "testRelayBs": {
                        "pageInfo": {
                            "hasNextPage": true,
                            "hasPreviousPage": false,
                            "startCursor": "YXJyYXljb25uZWN0aW9uOjU=",
                            "endCursor": "YXJyYXljb25uZWN0aW9uOjU="
                        },
                        "edges": [
                            {
                                "cursor": "YXJyYXljb25uZWN0aW9uOjU=",
                                "node": {
                                    "id": "VGVzdFJlbGF5QlR5cGU6Ng==",
                                    "text": "5",
                                    "testRelayAs": {
                                        "pageInfo": {
                                            "hasNextPage": true,
                                            "hasPreviousPage": false,
                                            "startCursor": "YXJyYXljb25uZWN0aW9uOjU=",
                                            "endCursor": "YXJyYXljb25uZWN0aW9uOjU="
                                        },
                                        "edges": [
                                            {
                                                "cursor": "YXJyYXljb25uZWN0aW9uOjU=",
                                                "node": {
                                                    "id": "VGVzdFJlbGF5QVR5cGU6NTY=",
                                                    "text": "5-5"
                                                }
                                            }
                                        ]
                                    }
                                }
                            }
                        ]
                    }
                }
            }
        """
    )

    response = client.query(query).json()
    verify_response(expected_response, response)

    b5_id = response["data"]["testRelayBs"]["edges"][0]["node"]["id"]
    a5_5_id = response["data"]["testRelayBs"]["edges"][0]["node"]["testRelayAs"][
        "edges"
    ][0]["node"]["id"]

    query = """
        query node ($id: ID!){
            node(id:$id){
                ... on TestRelayAType{
                id
                text
                testRelayB{
                    id
                    text
                }
                }
            }
        } 
    """
    expected_response = json.loads(
        """
        {
            "data": {
                "node": {
                    "id": "VGVzdFJlbGF5QVR5cGU6NTY=",
                    "text": "5-5",
                    "testRelayB": {
                        "id": "VGVzdFJlbGF5QlR5cGU6Ng==",
                        "text": "5"
                    }
                }
            }
        }
    """
    )
    response = client.query(query, variables={"id": a5_5_id}).json()
    verify_response(expected_response, response)

    query = """
        mutation testRelayACreate($input: TestRelayACreateInput!){
            testRelayACreate(input:$input){
                ok
                result{
                id
                text
                testRelayB{
                    id
                    text
                }
                }
            }
        }
    """
    variables = {"input": {"text": "11", "testRelayB": {"create": {"text": "11"}}}}

    expected_response = json.loads(
        """
    {
        "data": {
            "testRelayACreate": {
                "ok": true,
                "result": {
                    "id": "VGVzdFJlbGF5QVR5cGU6MTAx",
                    "text": "11",
                    "testRelayB": {
                        "id": "VGVzdFJlbGF5QlR5cGU6MTE=",
                        "text": "11"
                    }
                }
            }
        }
    }
    """
    )
    response = client.query(query, variables=variables).json()
    verify_response(expected_response, response)
    a_11_id = response["data"]["testRelayACreate"]["result"]["id"]
    b_11_id = response["data"]["testRelayACreate"]["result"]["testRelayB"]["id"]
    query = """
        mutation testRelayAUpdate($input: TestRelayAUpdateInput!, $where: TestRelayAWhereInput!){
        testRelayAUpdate(input:$input, where:$where){
            ok
            result{
            id
            text
            testRelayB{
                id
                text
            }
            }
        }
        }
    """

    variables = {
        "where": {"id": {"exact": a_11_id}},
        "input": {
            "text": "11-bis",
        },
    }

    expected_response = json.loads(
        """
    {
        "data": {
            "testRelayAUpdate": {
                "ok": true,
                "result": {
                    "id": "VGVzdFJlbGF5QVR5cGU6MTAx",
                    "text": "11-bis",
                    "testRelayB": {
                        "id": "VGVzdFJlbGF5QlR5cGU6MTE=",
                        "text": "11"
                    }
                }
            }
        }
    }

    """
    )
    response = client.query(query, variables=variables).json()
    verify_response(expected_response, response)
Exemplo n.º 7
0
def test_main():

    for i in range(10):
        a = TestConnA()
        a.text = str(i)
        a.nb = i
        a.save()
        for j in range(10):
            b = TestConnB()
            b.text = str(j)
            b.nb = j
            b.test_conn_a = a
            b.save()
            c = TestConnC()
            c.text = str(j)
            c.nb = j
            c.test_conn_a = a
            c.save()

    client = Client()

    query = """
        query{
            testConnAs(limit:2, offset:2){
            count
            nbAvg
            data{
            id
            nb
            text
            testConnBs(first:2, offset:2){
                totalCount
                nbAvg
                edges{
                node{
                    id
                    nb
                    text
                }
                }
            }
            testConnCs(limit:2, offset:2){
                id
                nb
                text
            }
            }
        }
        }
    """
    variables = {
        "input": {
            "text": "a1",
            "testFkB": {
                "create": {
                    "text": "b1",
                    "testFkC": {
                        "create": {
                            "text": "c1"
                        }
                    }
                }
            },
        }
    }
    expected_response = json.loads("""
    {
        "data": {
            "testConnAs": {
                "count": 10,
                "nbAvg": 4.5,
                "data": [
                    {
                        "id": "3",
                        "nb": 2,
                        "text": "2",
                        "testConnBs": {
                            "totalCount": 10,
                            "nbAvg": 4.5,
                            "edges": [
                                {
                                    "node": {
                                        "id": "VGVzdENvbm5CVHlwZToyMw==",
                                        "nb": 2,
                                        "text": "2"
                                    }
                                },
                                {
                                    "node": {
                                        "id": "VGVzdENvbm5CVHlwZToyNA==",
                                        "nb": 3,
                                        "text": "3"
                                    }
                                }
                            ]
                        },
                        "testConnCs": [
                            {
                                "id": "23",
                                "nb": 2,
                                "text": "2"
                            },
                            {
                                "id": "24",
                                "nb": 3,
                                "text": "3"
                            }
                        ]
                    },
                    {
                        "id": "4",
                        "nb": 3,
                        "text": "3",
                        "testConnBs": {
                            "totalCount": 10,
                            "nbAvg": 4.5,
                            "edges": [
                                {
                                    "node": {
                                        "id": "VGVzdENvbm5CVHlwZTozMw==",
                                        "nb": 2,
                                        "text": "2"
                                    }
                                },
                                {
                                    "node": {
                                        "id": "VGVzdENvbm5CVHlwZTozNA==",
                                        "nb": 3,
                                        "text": "3"
                                    }
                                }
                            ]
                        },
                        "testConnCs": [
                            {
                                "id": "33",
                                "nb": 2,
                                "text": "2"
                            },
                            {
                                "id": "34",
                                "nb": 3,
                                "text": "3"
                            }
                        ]
                    }
                ]
            }
        }
    }
    """)
    response = client.query(query, variables=variables).json()
    verify_response(expected_response, response)
Exemplo n.º 8
0
def test_relation_old():

    client = Client()

    variables = {
        "input": {
            "name": "p1",
            "childs": {
                "create": [{
                    "name": "p2"
                }, {
                    "name": "p3"
                }]
            },
            "father": {
                "create": {
                    "name": "p4"
                },
            },
            "friends": {
                "create": [{
                    "name": "p5"
                }, {
                    "name": "p6"
                }]
            },
        }
    }
    expected_response = {
        "data": {
            "personCreate": {
                "ok": True,
                "errors": [],
                "result": {
                    "name": "p1",
                    "childs": {
                        "data": [{
                            "name": "p2"
                        }, {
                            "name": "p3"
                        }]
                    },
                    "father": {
                        "name": "p4"
                    },
                    "friends": {
                        "data": [{
                            "name": "p5"
                        }, {
                            "name": "p6"
                        }]
                    },
                },
            }
        }
    }

    response = client.query(MUTATION_CREATE_TEST_A, variables=variables).json()
    verify_response(expected_response, response)

    p1_id = response["data"]["personCreate"]["result"]["id"]
    p2_id = response["data"]["personCreate"]["result"]["childs"]["data"][0][
        "id"]
    p3_id = response["data"]["personCreate"]["result"]["childs"]["data"][1][
        "id"]
    p4_id = response["data"]["personCreate"]["result"]["father"]["id"]
    p5_id = response["data"]["personCreate"]["result"]["friends"]["data"][0][
        "id"]
    p6_id = response["data"]["personCreate"]["result"]["friends"]["data"][1][
        "id"]