# 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 VendorApiTest(TestCase):
    """Test for Vendor API."""

    def setUp(self):
        self.client = Client()
        create_admin_account()
        self.first_vendor = self.create_vendor('vendor1', 'info1')['vendor']
        self.vendors = (
            ('vendor2', 'info2'),
            ('vendor3', 'info3')
        )

    def create_vendor(self, name, info):
        query = '''
                mutation{
                    createVendor(input: {name: "%s", info: "%s"}){
                        vendor{
                            id,
                            originalId,
                            name,
                            info
                        }
                    }
                }
                ''' % (name, info)
        return make_request(self.client, query, 'POST')

    def retrieve_vendor(self, vendor_id):
        query = 'query {vendor(id: "%s") {name}}' % (vendor_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_vendor_api.py
from django.test import Client, TestCase
from .utils import create_admin_account, make_request

class VendorApiTest(TestCase):
    """Test for Vendor API."""

    def setUp(self):
        self.client = Client()
        create_admin_account()
        self.first_vendor = self.create_vendor('vendor1', 'info1')['vendor']
        self.vendors = (
            ('vendor2', 'info2'),
            ('vendor3', 'info3')
        )

    def create_vendor(self, name, info):
        query = '''
                mutation{
                    createVendor(input: {name: "%s", info: "%s"}){
                        vendor{
                            id,
                            originalId,
                            name,
                            info
                        }
                    }
                }
                ''' % (name, info)
        return make_request(self.client, query, 'POST')

    def retrieve_vendor(self, vendor_id):
        query = 'query {vendor(id: "%s") {name}}' % (vendor_id)


        return make_request(self.client, query)