# Path: models/access_key.py
# class AccessKey(ndb.Model):
#     """Models an instance of an API key."""
#     access_key = ndb.StringProperty()
#     description = ndb.TextProperty()
# 
#     @staticmethod
#     def generate_uuid():
#         return uuid4().hex
# 
#     @classmethod
#     def create(cls, description):
#         new_key = cls()
#         new_key.access_key = cls.generate_uuid()
#         new_key.description = description
#         new_key.put()
# 
#         return new_key
# 
# Path: testing/factories/alias.py
# def create_alias_with_employee_username(
#     name='jda',
#     username='jd',
# ):
#     alias = Alias(
#         name=name,
#         owner_key=Employee.get_key_for_username(username),
#     )
#     alias.put()
#     return alias
# 
# Path: testing/factories/employee.py
# def create_employee(
#     username='johndoe',
#     department='Engineering',
#     first_name='John',
#     last_name='Doe',
#     photo_url=None,
#     office=None,
# ):
# 
#     if photo_url is None:
#         photo_url = 'http://example.com/photos/{0}.jpg'.format(username)
# 
#     return Employee.create_from_dict({
#         'username': username,
#         'department': department,
#         'first_name': first_name,
#         'last_name': last_name,
#         'photo_url': photo_url,
#         'office': office,
#     })
# 
# Path: testing/util.py
# class YelpLoveTestCase(unittest.TestCase):
# 
#     app = get_test_app()
# 
#     def assertRequiresLogin(self, response):
#         self.assertEqual(response.status_int, 302)
#         self.assert_(
#             response.headers['Location'].startswith('https://www.google.com/accounts/Login'),
#             'Unexpected Location header: {0}'.format(response.headers['Location']),
#         )
# 
#     def assertRequiresAdmin(self, response):
#         self.assertEqual(response.status_int, 401)
# 
#     def assertHasCsrf(self, form, session):
#         """Make sure the response form contains the correct CSRF token.
# 
#         :param form: a form entry from response.forms
#         :param session: response.session
#         """
#         self.assertIsNotNone(form.get('_csrf_token'))
#         self.assertEqual(
#             form['_csrf_token'].value, session['_csrf_token'],
#         )
# 
#     def addCsrfTokenToSession(self):
#         csrf_token = 'MY_TOKEN'
#         with self.app.session_transaction() as session:
#             session['_csrf_token'] = csrf_token
#         return csrf_token


import unittest
import mock
import logic.employee
import logic.love
from models import AccessKey
from testing.factories import create_alias_with_employee_username
from testing.factories import create_employee
from testing.util import YelpLoveTestCase
from webtest.app import AppError
            'api_key': api_key,
        }
        response = self.app.get('/api/love', query_params)
        response_data = response.json
        self.assertEqual(len(response_data), 1)
        self.assertEqual(response_data[0]['sender'], 'alice')
        self.assertEqual(response_data[0]['recipient'], 'bob')
        return response


class SendLoveTest(_ApiKeyRequiredTestCase):
    successful_response_code = 201

    def setUp(self):
        super(SendLoveTest, self).setUp()
        create_employee(username='alice')
        create_employee(username='bob')

    def do_request(self, api_key):
        form_values = {
            'sender': 'alice',
            'recipient': 'bob',
            'message': 'Care Bear Stare!',
            'api_key': api_key,
        }
        response = self.app.post('/api/love', form_values)
        self.assertTrue('Love sent to bob! Share:' in response.body)
        return response



# Path: models/access_key.py
# class AccessKey(ndb.Model):
#     """Models an instance of an API key."""
#     access_key = ndb.StringProperty()
#     description = ndb.TextProperty()
# 
#     @staticmethod
#     def generate_uuid():
#         return uuid4().hex
# 
#     @classmethod
#     def create(cls, description):
#         new_key = cls()
#         new_key.access_key = cls.generate_uuid()
#         new_key.description = description
#         new_key.put()
# 
#         return new_key
# 
# Path: testing/factories/alias.py
# def create_alias_with_employee_username(
#     name='jda',
#     username='jd',
# ):
#     alias = Alias(
#         name=name,
#         owner_key=Employee.get_key_for_username(username),
#     )
#     alias.put()
#     return alias
# 
# Path: testing/factories/employee.py
# def create_employee(
#     username='johndoe',
#     department='Engineering',
#     first_name='John',
#     last_name='Doe',
#     photo_url=None,
#     office=None,
# ):
# 
#     if photo_url is None:
#         photo_url = 'http://example.com/photos/{0}.jpg'.format(username)
# 
#     return Employee.create_from_dict({
#         'username': username,
#         'department': department,
#         'first_name': first_name,
#         'last_name': last_name,
#         'photo_url': photo_url,
#         'office': office,
#     })
# 
# Path: testing/util.py
# class YelpLoveTestCase(unittest.TestCase):
# 
#     app = get_test_app()
# 
#     def assertRequiresLogin(self, response):
#         self.assertEqual(response.status_int, 302)
#         self.assert_(
#             response.headers['Location'].startswith('https://www.google.com/accounts/Login'),
#             'Unexpected Location header: {0}'.format(response.headers['Location']),
#         )
# 
#     def assertRequiresAdmin(self, response):
#         self.assertEqual(response.status_int, 401)
# 
#     def assertHasCsrf(self, form, session):
#         """Make sure the response form contains the correct CSRF token.
# 
#         :param form: a form entry from response.forms
#         :param session: response.session
#         """
#         self.assertIsNotNone(form.get('_csrf_token'))
#         self.assertEqual(
#             form['_csrf_token'].value, session['_csrf_token'],
#         )
# 
#     def addCsrfTokenToSession(self):
#         csrf_token = 'MY_TOKEN'
#         with self.app.session_transaction() as session:
#             session['_csrf_token'] = csrf_token
#         return csrf_token


# Path: tests/views/api_test.py
import unittest
import mock
import logic.employee
import logic.love
from models import AccessKey
from testing.factories import create_alias_with_employee_username
from testing.factories import create_employee
from testing.util import YelpLoveTestCase
from webtest.app import AppError

            'api_key': api_key,
        }
        response = self.app.get('/api/love', query_params)
        response_data = response.json
        self.assertEqual(len(response_data), 1)
        self.assertEqual(response_data[0]['sender'], 'alice')
        self.assertEqual(response_data[0]['recipient'], 'bob')
        return response


class SendLoveTest(_ApiKeyRequiredTestCase):
    successful_response_code = 201

    def setUp(self):
        super(SendLoveTest, self).setUp()
        create_employee(username='alice')
        create_employee(username='bob')

    def do_request(self, api_key):
        form_values = {
            'sender': 'alice',
            'recipient': 'bob',
            'message': 'Care Bear Stare!',
            'api_key': api_key,
        }
        response = self.app.post('/api/love', form_values)
        self.assertTrue('Love sent to bob! Share:' in response.body)
        return response



class SendLoveFailTest(YelpLoveTestCase):