diff --git a/circle.yml b/circle.yml index b564ac8..5c12a71 100644 --- a/circle.yml +++ b/circle.yml @@ -1,9 +1,12 @@ machine: python: version: 3.5.2 +general: + artifacts: + - ".coverage" dependencies: post: - pip install -r ./deps/testing.txt test: override: - - ./src/manage.py test ./src \ No newline at end of file + - coverage run --source='.' ./src/manage.py test ./src \ No newline at end of file diff --git a/src/ango/settings/dev.py b/src/ango/settings/dev.py index 3084f6a..011815f 100644 --- a/src/ango/settings/dev.py +++ b/src/ango/settings/dev.py @@ -4,6 +4,7 @@ DEBUG = True +MIDDLEWARE.remove('django.middleware.csrf.CsrfViewMiddleware') DATABASES = { 'default': { diff --git a/src/todos/readme.md b/src/todos/readme.md new file mode 100644 index 0000000..650c0cb --- /dev/null +++ b/src/todos/readme.md @@ -0,0 +1,71 @@ +# Todos App +You may use graphiql or curl to try out some of the queries. + +## Queries +The following is an example query to get the first ten todos and +return the id and text of each one. +``` +query { + allTodos(first: 10){ + edges{ + node{ + id, + text + } + } + } +} +``` +The response +``` +{ + "data": { + "allTodos": { + "edges": [ + { + "node": { + "id": "VG9kb05vZGU6MQ==", + "text": "adfasdfdsa" + } + } + ] + } + } +} +``` + +### Queries with Variables +``` +query getSomeTodos($todos_count: Int!) { + allTodos(first: $todos_count) { + edges { + node { + id + text + } + } + } +} +``` + +### Using Curl +The actual post request is a json string to be careful of empty space or new lines. +Running the example query again would look like this +``` +curl -XPOST -H 'Content-Type:application/graphql' \ + -d '{ allTodos(first: 10){edges{node{id,text}}}}' \ + http://localhost:8000/graphql +``` +And return the following data. +``` +{"data":{"allTodos":{"edges":[{"node":{"id":"VG9kb05vZGU6MQ==","text":"adsfasdfasdfsd"}},{"node":{"id":"VG9kb05vZGU6Mg==","text":"adsfadsfa"}}]}}} + +``` + +### Using CocoaRestClient GUI /JSON Body +This is a valid json body you can paste into the raw input of the coca rest client. +`{"query": "query {allTodos(first: 10){edges{node{id,text}}}}"}` + +## Mutations + + diff --git a/src/todos/tests.py b/src/todos/tests.py index be04377..c2ded53 100644 --- a/src/todos/tests.py +++ b/src/todos/tests.py @@ -1,5 +1,8 @@ +import json + from django.contrib.auth.models import User -from django.test import TestCase, RequestFactory +from django.test import TestCase, Client + from .models import TodoModel @@ -14,7 +17,35 @@ def setUp(self): password='top_secret' ) - TodoModel.objects.create(user=self.user, text="roar") + TodoModel.objects.create(user=self.user, text="My todo") + + def test_all_todos_graphql_endpoint(self): + """Test all_todos graphql query""" + + # Sanity Checks + todo = TodoModel.objects.get(text="My todo") + self.assertEqual(todo.text, 'My todo') + + # Setup query and response + query = { + "query": "query {allTodos(first: 10){edges{node{id,text}}}}" + } + expected_response = { + "data": { + "allTodos": { + "edges": [ + { + "node": { + "id": "VG9kb05vZGU6MQ==", + "text": "My todo" + }} + ]} + } + } + # Make the post request + c = Client() + response = c.post('/graphql', query) - def test_animals_can_speak(self): - todo = TodoModel.objects.get(text="roar") + # Decode byte code response.content and load the json + graphql_response = json.loads(response.content.decode('ascii')) + self.assertEqual(graphql_response, expected_response)