Fix Unit Tests
This commit is contained in:
parent
92a6997ba5
commit
55683da3ed
|
|
@ -1,4 +1,4 @@
|
||||||
from django.test import TestCase
|
from django.test import TestCase, RequestFactory
|
||||||
from graphene.test import Client
|
from graphene.test import Client
|
||||||
from graphql_relay import to_global_id
|
from graphql_relay import to_global_id
|
||||||
|
|
||||||
|
|
@ -6,24 +6,29 @@ from api.schema import schema
|
||||||
from api.utils import get_graphql_mutation, get_object
|
from api.utils import get_graphql_mutation, get_object
|
||||||
from books.factories import ContentBlockFactory, ModuleFactory
|
from books.factories import ContentBlockFactory, ModuleFactory
|
||||||
from books.models import ContentBlock
|
from books.models import ContentBlock
|
||||||
|
from core.factories import UserFactory
|
||||||
|
|
||||||
|
|
||||||
class NewContentBlockMutationTest(TestCase):
|
class NewContentBlockMutationTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
module = ModuleFactory()
|
module = ModuleFactory()
|
||||||
|
user = UserFactory(username='aschi')
|
||||||
content_block = ContentBlockFactory(module=module)
|
content_block = ContentBlockFactory(module=module)
|
||||||
|
|
||||||
|
request = RequestFactory().get('/')
|
||||||
|
request.user = user
|
||||||
|
self.client = Client(schema=schema, context_value=request)
|
||||||
|
|
||||||
self.sibling_id = to_global_id('ContentBlock', content_block.pk)
|
self.sibling_id = to_global_id('ContentBlock', content_block.pk)
|
||||||
|
|
||||||
def test_add_new_content_block(self):
|
def test_add_new_content_block(self):
|
||||||
self.assertEqual(ContentBlock.objects.count(), 1)
|
self.assertEqual(ContentBlock.objects.count(), 1)
|
||||||
client = Client(schema=schema)
|
|
||||||
|
|
||||||
mutation = get_graphql_mutation('addContentBlock.gql')
|
mutation = get_graphql_mutation('addContentBlock.gql')
|
||||||
|
|
||||||
title = "Hello World"
|
title = "Hello World"
|
||||||
|
|
||||||
result = client.execute(mutation, variables={
|
result = self.client.execute(mutation, variables={
|
||||||
'input': {
|
'input': {
|
||||||
"contentBlock": {
|
"contentBlock": {
|
||||||
"title": title,
|
"title": title,
|
||||||
|
|
@ -53,13 +58,12 @@ class NewContentBlockMutationTest(TestCase):
|
||||||
|
|
||||||
def test_addNewContentBlock_withImageUrlBlock(self):
|
def test_addNewContentBlock_withImageUrlBlock(self):
|
||||||
self.assertEqual(ContentBlock.objects.count(), 1)
|
self.assertEqual(ContentBlock.objects.count(), 1)
|
||||||
client = Client(schema=schema)
|
|
||||||
|
|
||||||
mutation = get_graphql_mutation('addContentBlock.gql')
|
mutation = get_graphql_mutation('addContentBlock.gql')
|
||||||
|
|
||||||
title = "Hello World"
|
title = "Hello World"
|
||||||
|
|
||||||
result = client.execute(mutation, variables={
|
result = self.client.execute(mutation, variables={
|
||||||
'input': {
|
'input': {
|
||||||
"contentBlock": {
|
"contentBlock": {
|
||||||
"title": title,
|
"title": title,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue