예제 #1
0
 def test_execute_query_with_variable(self):
     query = "query ($name: [String!]) { sites(name:$name) {name} }"
     resp = execute_query(query,
                          user=self.user,
                          variables={
                              "name": "Site-1"
                          }).to_dict()
     self.assertFalse(resp.get("error"))
     self.assertEquals(len(resp["data"]["sites"]), 1)
예제 #2
0
    def test_get_graphql_object(self):
        """Test GET with changelogs via GraphQL."""
        site_payload = {
            "name": "Test Site 1",
            "slug": "test-site-1",
            "status": "active",
        }
        self.add_permissions("dcim.add_site")

        sites_url = reverse("dcim-api:site-list")
        new_site_response = self.client.post(sites_url, site_payload, format="json", **self.header)
        self.assertHttpStatus(new_site_response, status.HTTP_201_CREATED)

        gql_payload = '{query: object_changes(q: "") { object_repr } }'
        resp = execute_query(gql_payload, user=self.user).to_dict()
        self.assertFalse(resp["data"].get("error"))
        self.assertEqual(first=site_payload["name"], second=resp["data"]["query"][0].get("object_repr", ""))
예제 #3
0
    def test_graphql_object_gte_filter(self):
        site_payload = {
            "name": "Test Site 1",
            "slug": "test-site-1",
            "status": "active",
        }
        self.add_permissions("dcim.add_site")

        time = "2021-03-14 00:00:00"
        sites_url = reverse("dcim-api:site-list")
        new_site_response = self.client.post(sites_url, site_payload, format="json", **self.header)
        self.assertHttpStatus(new_site_response, status.HTTP_201_CREATED)

        gql_payload = f'{{query: object_changes(time__gte: "{time}") {{ object_repr }} }}'
        resp = execute_query(gql_payload, user=self.user).to_dict()
        self.assertFalse(resp["data"].get("error"))
        self.assertIsInstance(resp["data"].get("query"), list)
        self.assertEqual(first=site_payload["name"], second=resp["data"]["query"][0].get("object_repr", ""))
예제 #4
0
 def test_execute_query_with_error(self):
     query = "THIS TEST WILL ERROR"
     with self.assertRaises(GraphQLError):
         execute_query(query, user=self.user).to_dict()
예제 #5
0
 def test_execute_query(self):
     query = "{ query: sites {name} }"
     resp = execute_query(query, user=self.user).to_dict()
     self.assertFalse(resp["data"].get("error"))
     self.assertEquals(len(resp["data"]["query"]), 3)