|
| 1 | +import mongoengine |
| 2 | +from graphene.test import Client |
| 3 | +from examples.falcon_mongoengine.schema import schema |
| 4 | +from .fixtures import fixtures_data |
| 5 | + |
| 6 | +mongoengine.connect('graphene-mongo-test', host='mongomock://localhost', alias='default') |
| 7 | + |
| 8 | + |
| 9 | +def test_category_last_1_item_query(fixtures_data): |
| 10 | + query = ''' |
| 11 | + { |
| 12 | + categories(last: 1){ |
| 13 | + edges { |
| 14 | + node { |
| 15 | + name |
| 16 | + color |
| 17 | + } |
| 18 | + } |
| 19 | + } |
| 20 | + }''' |
| 21 | + |
| 22 | + expected = { |
| 23 | + "data": { |
| 24 | + "categories": |
| 25 | + { |
| 26 | + "edges": [ |
| 27 | + { |
| 28 | + "node": { |
| 29 | + "name": "Work", |
| 30 | + "color": "#1769ff", |
| 31 | + } |
| 32 | + } |
| 33 | + ] |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + client = Client(schema) |
| 39 | + result = client.execute(query) |
| 40 | + assert result == expected |
| 41 | + |
| 42 | + |
| 43 | +def test_category_filter_item_query(fixtures_data): |
| 44 | + query = ''' |
| 45 | + { |
| 46 | + categories(name: "Work"){ |
| 47 | + edges { |
| 48 | + node { |
| 49 | + name |
| 50 | + color |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + }''' |
| 55 | + |
| 56 | + expected = { |
| 57 | + "data": { |
| 58 | + "categories": |
| 59 | + { |
| 60 | + "edges": [ |
| 61 | + { |
| 62 | + "node": { |
| 63 | + "name": "Work", |
| 64 | + "color": "#1769ff", |
| 65 | + } |
| 66 | + } |
| 67 | + ] |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + client = Client(schema) |
| 73 | + result = client.execute(query) |
| 74 | + assert result == expected |
| 75 | + |
| 76 | + |
| 77 | +def test_bookmarks_first_2_items_query(fixtures_data): |
| 78 | + query = ''' |
| 79 | + { |
| 80 | + bookmarks(first: 2){ |
| 81 | + edges { |
| 82 | + node { |
| 83 | + name |
| 84 | + url |
| 85 | + category { |
| 86 | + name |
| 87 | + color |
| 88 | + } |
| 89 | + tags |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + }''' |
| 94 | + |
| 95 | + expected = { |
| 96 | + "data": { |
| 97 | + "bookmarks": |
| 98 | + { |
| 99 | + "edges": [ |
| 100 | + { |
| 101 | + "node": { |
| 102 | + "name": "Travel tips", |
| 103 | + "url": "https://www.traveltips.test", |
| 104 | + "category": { |
| 105 | + 'name': 'Travel', |
| 106 | + 'color': '#ed008c' |
| 107 | + }, |
| 108 | + "tags": ["travel", "tips", "howto", ] |
| 109 | + } |
| 110 | + }, |
| 111 | + { |
| 112 | + "node": { |
| 113 | + "name": "DIY vacation", |
| 114 | + "url": "https://www.diyvacation.test", |
| 115 | + "category": { |
| 116 | + 'name': 'Travel', |
| 117 | + 'color': '#ed008c' |
| 118 | + }, |
| 119 | + "tags": ["travel", "diy", "holiday", "vacation", ] |
| 120 | + } |
| 121 | + } |
| 122 | + ] |
| 123 | + } |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + client = Client(schema) |
| 128 | + result = client.execute(query) |
| 129 | + assert result == expected |
| 130 | + |
| 131 | + |
| 132 | +def test_bookmarks_filter_items_query(fixtures_data): |
| 133 | + query = ''' |
| 134 | + { |
| 135 | + bookmarks(first: 1, name: "Awesome python"){ |
| 136 | + edges { |
| 137 | + node { |
| 138 | + name |
| 139 | + url |
| 140 | + category { |
| 141 | + name |
| 142 | + color |
| 143 | + } |
| 144 | + tags |
| 145 | + } |
| 146 | + } |
| 147 | + } |
| 148 | + }''' |
| 149 | + |
| 150 | + expected = { |
| 151 | + "data": { |
| 152 | + "bookmarks": |
| 153 | + { |
| 154 | + "edges": [ |
| 155 | + { |
| 156 | + "node": { |
| 157 | + "name": "Awesome python", |
| 158 | + "url": "https://awesomelists.top/#repos/vinta/awesome-python", |
| 159 | + "category": { |
| 160 | + 'name': 'Work', |
| 161 | + 'color': '#1769ff' |
| 162 | + }, |
| 163 | + "tags": ["python", "dev", "awesome", "tutorial", ] |
| 164 | + } |
| 165 | + } |
| 166 | + ] |
| 167 | + } |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | + client = Client(schema) |
| 172 | + result = client.execute(query) |
| 173 | + assert result == expected |
0 commit comments