|
1 | | -from django.test import TestCase |
| 1 | +import json |
| 2 | +import pytest |
| 3 | +from graphene.test import Client |
| 4 | +from main.schema import schema |
2 | 5 |
|
3 | | -# Create your tests here. |
| 6 | +@pytest.mark.django_db |
| 7 | +def test_municipalities_exists(): |
| 8 | + client = Client(schema) |
| 9 | + result = client.execute(''' |
| 10 | +query { |
| 11 | + municipalities { |
| 12 | + edges { |
| 13 | + node { |
| 14 | + id |
| 15 | + name |
| 16 | + bfsNumber |
| 17 | + } |
| 18 | + } |
| 19 | + } |
| 20 | +}''', |
| 21 | + context={}) |
| 22 | + result = json.loads(json.dumps(result)) # remove OrderedDics, default in python 3.7+ |
| 23 | + assert result == { |
| 24 | + "data": { |
| 25 | + "municipalities": { |
| 26 | + "edges": [ |
| 27 | + { |
| 28 | + "node": { |
| 29 | + "id": "TXVuaWNpcGFsaXR5Tm9kZTo2MjUy", |
| 30 | + "name": "Anniviers", |
| 31 | + "bfsNumber": 6252 |
| 32 | + } |
| 33 | + }, |
| 34 | + { |
| 35 | + "node": { |
| 36 | + "id": "TXVuaWNpcGFsaXR5Tm9kZTo2MDMx", |
| 37 | + "name": "Bagnes", |
| 38 | + "bfsNumber": 6031 |
| 39 | + } |
| 40 | + }, |
| 41 | + { |
| 42 | + "node": { |
| 43 | + "id": "TXVuaWNpcGFsaXR5Tm9kZTozNzky", |
| 44 | + "name": "Bregaglia", |
| 45 | + "bfsNumber": 3792 |
| 46 | + } |
| 47 | + }, |
| 48 | + { |
| 49 | + "node": { |
| 50 | + "id": "TXVuaWNpcGFsaXR5Tm9kZTozODUx", |
| 51 | + "name": "Davos", |
| 52 | + "bfsNumber": 3851 |
| 53 | + } |
| 54 | + }, |
| 55 | + { |
| 56 | + "node": { |
| 57 | + "id": "TXVuaWNpcGFsaXR5Tm9kZToxNjMx", |
| 58 | + "name": "Glarus Süd", |
| 59 | + "bfsNumber": 1631 |
| 60 | + } |
| 61 | + }, |
| 62 | + { |
| 63 | + "node": { |
| 64 | + "id": "TXVuaWNpcGFsaXR5Tm9kZTo3ODQ=", |
| 65 | + "name": "Innertkirchen", |
| 66 | + "bfsNumber": 784 |
| 67 | + } |
| 68 | + }, |
| 69 | + { |
| 70 | + "node": { |
| 71 | + "id": "TXVuaWNpcGFsaXR5Tm9kZTozNzYy", |
| 72 | + "name": "Scuol", |
| 73 | + "bfsNumber": 3762 |
| 74 | + } |
| 75 | + }, |
| 76 | + { |
| 77 | + "node": { |
| 78 | + "id": "TXVuaWNpcGFsaXR5Tm9kZTozNTQz", |
| 79 | + "name": "Surses", |
| 80 | + "bfsNumber": 3543 |
| 81 | + } |
| 82 | + }, |
| 83 | + { |
| 84 | + "node": { |
| 85 | + "id": "TXVuaWNpcGFsaXR5Tm9kZTo2MzAw", |
| 86 | + "name": "Zermatt", |
| 87 | + "bfsNumber": 6300 |
| 88 | + } |
| 89 | + }, |
| 90 | + { |
| 91 | + "node": { |
| 92 | + "id": "TXVuaWNpcGFsaXR5Tm9kZTozNzQ2", |
| 93 | + "name": "Zernez", |
| 94 | + "bfsNumber": 3746 |
| 95 | + } |
| 96 | + } |
| 97 | + ] |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + |
| 103 | +@pytest.mark.django_db |
| 104 | +def test_snapshots_exists(): |
| 105 | + client = Client(schema) |
| 106 | + result = client.execute(''' |
| 107 | +query { |
| 108 | + snapshots(isShowcase: true) { |
| 109 | + edges { |
| 110 | + node { |
| 111 | + id |
| 112 | + pk |
| 113 | + title |
| 114 | + topic |
| 115 | + screenshot |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | +}''', |
| 120 | + context={}) |
| 121 | + result = json.loads( |
| 122 | + json.dumps(result)) # remove OrderedDics, default in python 3.7+ |
| 123 | + assert result == { |
| 124 | + 'data': { |
| 125 | + 'snapshots': { |
| 126 | + 'edges': [{ |
| 127 | + 'node': { |
| 128 | + 'id': 'U25hcHNob3ROb2RlOlI0UlBHQw==', |
| 129 | + 'pk': 'R4RPGC', |
| 130 | + 'title': 'test snapshot', |
| 131 | + 'topic': 'test topic', |
| 132 | + 'screenshot': '' |
| 133 | + } |
| 134 | + }] |
| 135 | + } |
| 136 | + } |
| 137 | + } |
0 commit comments