# Path: tests/example_app/api/resources.py
# class DateTimeResource(Resource):
#     """A simple datetime resource used for testing Pale Resources."""
#     _value_type = 'DateTime Resource'
#     _underlying_model = DateTimeModel
# 
# 
#     year = IntegerField("The year of the returned DateTime")
#     month = IntegerField("A month, between 1 and 12")
#     day = IntegerField("The date of the month")
# 
#     hours = IntegerField("The hours time, between 0 and 23")
#     minutes = IntegerField("The minutes, between 0 and 59")
#     seconds = IntegerField("The seconds, between 0 and 59")
# 
#     isoformat = StringField("The DateTime's ISO representation",
#             property_name='iso')
# 
#     eurodate = StringField("The date in DD.MM.YYYY format",
#             value=lambda item: item.timestamp.strftime("%d.%m.%Y"))
# 
#     name = StringField("Your DateTime's name",
#             details="This value will be `null` on most DateTimes.  It's "
#             "only set when the DateTime is created with `/parse_time/` "
#             "and a `name` is passed in.")
# 
# 
#     _default_fields = ('year',
#                        'month',
#                        'day',
#                        'isoformat')
# 
# 
#     def _render_serializable(self, instance, context):
#         """Render a datetime for the context provided"""
#         if not isinstance(instance, DateTimeModel):
#             """This check is here for illustration purposes, but isn't
#             strictly required, as long as you make sure you send the correct
#             objects to their correct serializers."""
#             raise ValueError(("You broke the test app by trying to pass "
#                 "something other than a `DateTimeModel` to the "
#                 "DateTimeResource serializer."))
# 
#         output = super(DateTimeResource, self)._render_serializable(
#                 instance, context)
# 
#         # add fields based on the instance state
#         if instance.include_time:
#             output['hours'] = instance.hours
#             output['minutes'] = instance.minutes
#             output['seconds'] = instance.seconds
# 
#         if instance.name is not None:
#             output['name'] = instance.name
# 
#         # Typically, the context is also used to selectively render (or hide)
#         # specific fields based on the current user, and whether or not they own
#         # the object that they're trying to obtain.
# 
#         # But we're not doing that in this example.
# 
#         return output


import datetime
import unittest
from webtest import TestApp, AppError
from tests.example_app.api.resources import DateTimeResource
        from tests.example_app.flask_app import create_pale_flask_app
        self.assertEqual(resp.headers["Access-Control-Allow-Origin"], '*')

        # the 'time' value was set in the endpoint handler
        self.assertIn('time', resp.json_body)

        # the returned time value should match the resource defined
        # in tests.example_app.api.resources.py
        returned_time = resp.json_body['time']

        # the endpoint specifies `fields=DateTimeResource._all_fields()`
        # so, we should expect to find all of them
        expected_fields = DateTimeResource._all_fields()

        self.assertExpectedFields(returned_time, expected_fields)
        self.assertEqual(returned_time['eurodate'],
                now.strftime("%d.%m.%Y"))


    def test_successful_post_with_required_params(self):
        # month is required in the endpoint definition, so we must pass
        # it in here
        resp = self.app.post('/api/time/parse', {'month': 2})

        self.assertEqual(resp.status_code, 200)
        self.assertIn('time', resp.json_body)

        returned_time = resp.json_body['time']

        # we didn't specify any other fields in the endpoint definition,
        # so this one should only get the defaults

# Path: tests/example_app/api/resources.py
# class DateTimeResource(Resource):
#     """A simple datetime resource used for testing Pale Resources."""
#     _value_type = 'DateTime Resource'
#     _underlying_model = DateTimeModel
# 
# 
#     year = IntegerField("The year of the returned DateTime")
#     month = IntegerField("A month, between 1 and 12")
#     day = IntegerField("The date of the month")
# 
#     hours = IntegerField("The hours time, between 0 and 23")
#     minutes = IntegerField("The minutes, between 0 and 59")
#     seconds = IntegerField("The seconds, between 0 and 59")
# 
#     isoformat = StringField("The DateTime's ISO representation",
#             property_name='iso')
# 
#     eurodate = StringField("The date in DD.MM.YYYY format",
#             value=lambda item: item.timestamp.strftime("%d.%m.%Y"))
# 
#     name = StringField("Your DateTime's name",
#             details="This value will be `null` on most DateTimes.  It's "
#             "only set when the DateTime is created with `/parse_time/` "
#             "and a `name` is passed in.")
# 
# 
#     _default_fields = ('year',
#                        'month',
#                        'day',
#                        'isoformat')
# 
# 
#     def _render_serializable(self, instance, context):
#         """Render a datetime for the context provided"""
#         if not isinstance(instance, DateTimeModel):
#             """This check is here for illustration purposes, but isn't
#             strictly required, as long as you make sure you send the correct
#             objects to their correct serializers."""
#             raise ValueError(("You broke the test app by trying to pass "
#                 "something other than a `DateTimeModel` to the "
#                 "DateTimeResource serializer."))
# 
#         output = super(DateTimeResource, self)._render_serializable(
#                 instance, context)
# 
#         # add fields based on the instance state
#         if instance.include_time:
#             output['hours'] = instance.hours
#             output['minutes'] = instance.minutes
#             output['seconds'] = instance.seconds
# 
#         if instance.name is not None:
#             output['name'] = instance.name
# 
#         # Typically, the context is also used to selectively render (or hide)
#         # specific fields based on the current user, and whether or not they own
#         # the object that they're trying to obtain.
# 
#         # But we're not doing that in this example.
# 
#         return output


# Path: tests/test_flask_adapter.py
import datetime
import unittest
from webtest import TestApp, AppError
from tests.example_app.api.resources import DateTimeResource
        from tests.example_app.flask_app import create_pale_flask_app

        self.assertEqual(resp.headers["Access-Control-Allow-Origin"], '*')

        # the 'time' value was set in the endpoint handler
        self.assertIn('time', resp.json_body)

        # the returned time value should match the resource defined
        # in tests.example_app.api.resources.py
        returned_time = resp.json_body['time']

        # the endpoint specifies `fields=DateTimeResource._all_fields()`
        # so, we should expect to find all of them
        expected_fields = DateTimeResource._all_fields()

        self.assertExpectedFields(returned_time, expected_fields)
        self.assertEqual(returned_time['eurodate'],
                now.strftime("%d.%m.%Y"))


    def test_successful_post_with_required_params(self):
        # month is required in the endpoint definition, so we must pass
        # it in here
        resp = self.app.post('/api/time/parse', {'month': 2})

        self.assertEqual(resp.status_code, 200)
        self.assertIn('time', resp.json_body)

        returned_time = resp.json_body['time']

        # we didn't specify any other fields in the endpoint definition,
        # so this one should only get the defaults

        expected_fields = DateTimeResource._default_fields