forked from olga-f/JSPrep
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_unit.py
More file actions
152 lines (133 loc) · 5.15 KB
/
test_unit.py
File metadata and controls
152 lines (133 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import pytest
from django.urls import reverse
from django.test import RequestFactory
from graphene.test import Client
from .schema import schema
from .fixtures import fixtures_data
def test_unit_data_query(fixtures_data):
query = """{
unitList{
title
about
description
imageUrl
}
}"""
expected = {
"data": {
"unitList": [
{
"title": "Unit 1",
"about": ["A", "B", "C", "D"],
"description": "This is a test unit 1",
"imageUrl": "https://example.com/unit1.jpg",
},
{
"title": "UNIT 2",
"about": ["a", "b", "c"],
"description": "THIS IS a test unit 2",
"imageUrl": "https://example.com/unit2.jpg",
},
{
"title": "Functional JavaScript",
"about": ["Higher order functions","reduce, filter","Function composition", "Closure", "Partial application"],
"description": "Functional programming - a paradigm for structuring our complex code",
"imageUrl": "https://cdn.pixabay.com/photo/2015/11/24/10/52/gears-1059756_960_720.png"
},
]
}
}
client = Client(schema)
result = client.execute(query)
assert result == expected
@pytest.mark.django_db
def test_create_unit_mutation():
query = """
mutation {
createUnit(unitData:{
title:"JavaScript basics",
about:["Variables","Data Types Overview","Strings", "Numbers", "Booleans"],
description:"An introduction to core JavaScript functionality",
imageUrl:"https://cdn.pixabay.com/photo/2019/10/03/12/12/javascript-4523100_960_720.jpg"
}) {
unit {
title
about
description
imageUrl
}
}
}
"""
expected = {
"data": {
"createUnit": {
"unit": {
"title": "JavaScript basics",
"about": ["Variables","Data Types Overview","Strings", "Numbers", "Booleans"],
"description": "An introduction to core JavaScript functionality",
"imageUrl": "https://cdn.pixabay.com/photo/2019/10/03/12/12/javascript-4523100_960_720.jpg"
}
}
}
}
factory = RequestFactory()
request = factory.post(reverse("graphql-query"))
client = Client(schema)
result = client.execute(query, context=request)
assert result == expected
def test_update_unit_mutation(fixtures_data):
query = """
mutation {
updateUnit(unitData:{
id: "107f1f77bcf86cd799439011",
title:"Functional JavaScript Updated",
about: ["Higher order functions","reduce, filter","Function composition", "Closure","Pure functions", "Partial application and currying"],
}) {
unit {
title
about
description
imageUrl
}
}
}
"""
expected = {
"data": {
"updateUnit": {
"unit": {
"title":"Functional JavaScript Updated",
"about": ["Higher order functions","reduce, filter","Function composition", "Closure","Pure functions", "Partial application and currying"],
"description": "Functional programming - a paradigm for structuring our complex code",
"imageUrl":"https://cdn.pixabay.com/photo/2015/11/24/10/52/gears-1059756_960_720.png"
}
}
}
}
factory = RequestFactory()
request = factory.post(reverse("graphql-query"))
client = Client(schema)
result = client.execute(query, context=request)
print(result)
assert result == expected
def test_delete_unit_mutation(fixtures_data):
query = """
mutation {
deleteUnit(id: "107f1f77bcf86cd799439011"){
success
}
}
"""
expected = {
"data": {
"deleteUnit": {
"success": True
}
}
}
factory = RequestFactory()
request = factory.post(reverse("graphql-query"))
client = Client(schema)
result = client.execute(query, context=request)
assert result == expected