# Path: app/timetables/factories.py
# class ServingFactory(TimestampFactory):
#     """Serving model factory."""
# 
#     class Meta:
#         model = models.Serving
# 
#     menu_item = factory.SubFactory(MenuItemFactory)
#     vendor = factory.SubFactory(VendorFactory)
#     date_served = datetime.date(2016, 10, 1)
# 
# 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 app.timetables.factories import ServingFactory
from .utils import create_admin_account, make_request
    def setUp(self):
        self.client = Client()
        create_admin_account()
        self.serving = ServingFactory()
        self.first_review = self.create_review(
            self.serving.public_id.hashid,
            3,
            'Fair meal'
        )['review']
        self.reviews = (
            (self.serving.public_id.hashid, 4, 'Good meal'),
            (self.serving.public_id.hashid, 5, 'Excellent meal')
        )

    def create_review(self, serving_public_id, value, comment):
        query = '''
                mutation{
                    createReview(input: {serving: "%s", value: "%s", comment: "%s"}){
                        review{
                            id,
                            originalId,
                            value,
                            comment,
                            serving{
                                publicId
                            }
                        }
                    }
                }
                ''' % (serving_public_id, value, comment)

# Path: app/timetables/factories.py
# class ServingFactory(TimestampFactory):
#     """Serving model factory."""
# 
#     class Meta:
#         model = models.Serving
# 
#     menu_item = factory.SubFactory(MenuItemFactory)
#     vendor = factory.SubFactory(VendorFactory)
#     date_served = datetime.date(2016, 10, 1)
# 
# 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_review_api.py
from django.test import Client, TestCase
from app.timetables.factories import ServingFactory
from .utils import create_admin_account, make_request

    def setUp(self):
        self.client = Client()
        create_admin_account()
        self.serving = ServingFactory()
        self.first_review = self.create_review(
            self.serving.public_id.hashid,
            3,
            'Fair meal'
        )['review']
        self.reviews = (
            (self.serving.public_id.hashid, 4, 'Good meal'),
            (self.serving.public_id.hashid, 5, 'Excellent meal')
        )

    def create_review(self, serving_public_id, value, comment):
        query = '''
                mutation{
                    createReview(input: {serving: "%s", value: "%s", comment: "%s"}){
                        review{
                            id,
                            originalId,
                            value,
                            comment,
                            serving{
                                publicId
                            }
                        }
                    }
                }
                ''' % (serving_public_id, value, comment)

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