# Path: app/api/tests/utils.py
# def create_admin_account():
#     return User.objects.create_superuser(*admin_test_credentials)
# 
# def make_request(client, query, method='GET'):
#     header = {
#         'HTTP_X_TAVERNATOKEN': obtain_api_key(client)
#     }
# 
#     if method == 'GET':
#         return client.get(endpoint, data={'query': query}, **header).json()
# 
#     if method == 'POST':
#         return client.post(endpoint, data={'query': query}, **header).json()


from django.test import Client, TestCase
from .utils import create_admin_account, make_request

class DishApiTest(TestCase):
    """Test for Dish API"""

    def setUp(self):
        self.client = Client()
        create_admin_account()
        self.data = {
            'name': 'rice',
            'description': 'white rice'
        }
        self.dishes = (
            ('rice', 'white rice'),
            ('Coconut rice', 'rice with coconut flavor'),
            ('plantain', 'fried plantain'),
        )

    def create_dish(self, name, description):
        query = '''
            mutation{
              createDish(input: {name: "%s", description: "%s"}){
                dish{
                  id,
                  originalId,
                  name
                }
              }
            }
        ''' % (name, description)


# Path: app/api/tests/utils.py
# def create_admin_account():
#     return User.objects.create_superuser(*admin_test_credentials)
# 
# def make_request(client, query, method='GET'):
#     header = {
#         'HTTP_X_TAVERNATOKEN': obtain_api_key(client)
#     }
# 
#     if method == 'GET':
#         return client.get(endpoint, data={'query': query}, **header).json()
# 
#     if method == 'POST':
#         return client.post(endpoint, data={'query': query}, **header).json()


# Path: app/api/tests/test_dish_api.py
from django.test import Client, TestCase
from .utils import create_admin_account, make_request


class DishApiTest(TestCase):
    """Test for Dish API"""

    def setUp(self):
        self.client = Client()
        create_admin_account()
        self.data = {
            'name': 'rice',
            'description': 'white rice'
        }
        self.dishes = (
            ('rice', 'white rice'),
            ('Coconut rice', 'rice with coconut flavor'),
            ('plantain', 'fried plantain'),
        )

    def create_dish(self, name, description):
        query = '''
            mutation{
              createDish(input: {name: "%s", description: "%s"}){
                dish{
                  id,
                  originalId,
                  name
                }
              }
            }
        ''' % (name, description)


        return make_request(self.client, query, 'POST')