# 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()


import datetime
from django.test import Client, TestCase
from .utils import create_admin_account, make_request
class MealApiTest(TestCase):
    """Test for Meal API"""

    def setUp(self):
        self.client = Client()
        create_admin_account()
        self.data = {
            'name': 'BreakFast',
            'start_time': datetime.time(8, 30, 0),
            'end_time': datetime.time(10, 0, 0)
        }

    def create_meal(self, name, start_time, end_time):
        query = '''
            mutation {
                createMeal(input: {name: "%s", startTime: "%s",  endTime: "%s"}){
                    meal{
                        id,
                        originalId,
                        name
                    }
                }
            }
        ''' % (name, start_time, end_time)

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

    def retrieve_meal(self, id):
        query = 'query {meal(id: "%s" ) {name}}' % (id)


# 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_meal_api.py
import datetime
from django.test import Client, TestCase
from .utils import create_admin_account, make_request

class MealApiTest(TestCase):
    """Test for Meal API"""

    def setUp(self):
        self.client = Client()
        create_admin_account()
        self.data = {
            'name': 'BreakFast',
            'start_time': datetime.time(8, 30, 0),
            'end_time': datetime.time(10, 0, 0)
        }

    def create_meal(self, name, start_time, end_time):
        query = '''
            mutation {
                createMeal(input: {name: "%s", startTime: "%s",  endTime: "%s"}){
                    meal{
                        id,
                        originalId,
                        name
                    }
                }
            }
        ''' % (name, start_time, end_time)

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

    def retrieve_meal(self, id):
        query = 'query {meal(id: "%s" ) {name}}' % (id)


        return make_request(self.client, query)