# Path: pyston/resource.py
# ACCESS_CONTROL_ALLOW_ORIGIN = 'Access-Control-Allow-Origin'
# 
# ACCESS_CONTROL_EXPOSE_HEADERS = 'Access-Control-Expose-Headers'
# 
# ACCESS_CONTROL_ALLOW_CREDENTIALS = 'Access-Control-Allow-Credentials'
# 
# ACCESS_CONTROL_ALLOW_HEADERS = 'Access-Control-Allow-Headers'
# 
# ACCESS_CONTROL_ALLOW_METHODS = 'Access-Control-Allow-Methods'
# 
# ACCESS_CONTROL_MAX_AGE = 'Access-Control-Max-Age'
# 
# Path: example/dj/apps/app/tests/test_case.py
# class PystonTestCase(RestTestCase):
# 
#     USER_API_URL = '/api/user/'
#     USER_WITH_FORM_API_URL = '/api/user-form/'
#     ISSUE_API_URL = '/api/issue/'
#     ISSUE_WITH_FORM_API_URL = '/api/issue-form/'
#     EXTRA_API_URL = '/api/extra/'
#     COUNT_ISSUES_PER_USER = '/api/count-issues-per-user/'
#     COUNT_WATCHERS_PER_ISSUE = '/api/count-watchers-per-issue/'
#     TEST_CC_API_URL = '/api/test-cc/'
# 
#     user_id = 0
#     issue_id = 0
# 
#     DATA_AMOUNT = 10
# 
#     def get_pk(self, resp):
#         return self.deserialize(resp).get('id')
# 
#     def get_pk_list(self, resp, only_pks=None):
#         return [obj.get('id') for obj in self.deserialize(resp) if not only_pks or obj.get('id') in only_pks]
# 
#     def get_user_data(self, prefix='', **kwargs):
#         result = {'email': '%suser_%s@test.cz' % (prefix, self.user_id)}
#         self.user_id += 1
#         result.update(kwargs)
#         return result
# 
#     def get_issue_data(self, prefix='', **kwargs):
#         result = {'name': 'Issue %s' % self.issue_id, 'created_by': self.get_user_data(prefix),
#                   'leader': self.get_user_data(prefix)}
#         self.issue_id += 1
#         result.update(kwargs)
#         return result
# 
#     def get_users_data(self, prefix='', flat=False):
#         result = []
#         for i in range(self.DATA_AMOUNT):
#             if flat:
#                 result.append(self.get_user_data(prefix))
#             else:
#                 result.append((i, self.get_user_data(prefix)))
#         return result
# 
#     def get_issues_data(self, prefix='', flat=False):
#         result = []
#         for i in range(self.DATA_AMOUNT):
#             result.append((i, self.get_issue_data(prefix)))
#         return result
# 
#     def get_issues_and_users_data(self, prefix=''):
#         result = []
#         for i in range(self.DATA_AMOUNT):
#             issue_data = self.get_issue_data(prefix)
#             user_data = issue_data['created_by']
#             del issue_data['created_by']
#             result.append((i, issue_data, user_data))
#         return result


from six.moves.urllib.parse import urlencode
from django.test import TestCase
from django.test.utils import override_settings
from germanium.test_cases.rest import RestTestCase
from germanium.tools.trivials import assert_true, assert_false, assert_equal
from germanium.decorators import data_consumer
from pyston.resource import (ACCESS_CONTROL_ALLOW_ORIGIN, ACCESS_CONTROL_EXPOSE_HEADERS,
                             ACCESS_CONTROL_ALLOW_CREDENTIALS, ACCESS_CONTROL_ALLOW_HEADERS,
                             ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_MAX_AGE)
from .test_case import PystonTestCase
        assert_false(resp.has_header(ACCESS_CONTROL_ALLOW_METHODS))
        assert_true(resp.has_header(ACCESS_CONTROL_MAX_AGE))

        resp = self.options(self.USER_API_URL, headers={'HTTP_ORIGIN': FOO_DOMAIN})
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_ORIGIN))
        assert_true(resp.has_header(ACCESS_CONTROL_EXPOSE_HEADERS))
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_CREDENTIALS))
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_HEADERS))
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_METHODS))
        assert_true(resp.has_header(ACCESS_CONTROL_MAX_AGE))

        resp = self.options(self.USER_API_URL, headers={'HTTP_ORIGIN': BAR_DOMAIN})
        assert_false(resp.has_header(ACCESS_CONTROL_ALLOW_ORIGIN))
        assert_true(resp.has_header(ACCESS_CONTROL_EXPOSE_HEADERS))
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_CREDENTIALS))
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_HEADERS))
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_METHODS))

    @override_settings(PYSTON_CORS=True, PYSTON_CORS_WHITELIST=[FOO_DOMAIN[7:]])
    @data_consumer('get_users_data')
    def test_with_turned_on_cors_headers_is_included_with_valid_origin(self, number, data):
        resp = self.options(self.USER_API_URL, headers={'HTTP_ORIGIN': FOO_DOMAIN})
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_ORIGIN))
        assert_true(resp.has_header(ACCESS_CONTROL_EXPOSE_HEADERS))
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_CREDENTIALS))
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_HEADERS))
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_METHODS))
        assert_true(resp.has_header(ACCESS_CONTROL_MAX_AGE))

        resp = self.get(self.USER_API_URL, headers={'HTTP_ORIGIN': FOO_DOMAIN})

# Path: pyston/resource.py
# ACCESS_CONTROL_ALLOW_ORIGIN = 'Access-Control-Allow-Origin'
# 
# ACCESS_CONTROL_EXPOSE_HEADERS = 'Access-Control-Expose-Headers'
# 
# ACCESS_CONTROL_ALLOW_CREDENTIALS = 'Access-Control-Allow-Credentials'
# 
# ACCESS_CONTROL_ALLOW_HEADERS = 'Access-Control-Allow-Headers'
# 
# ACCESS_CONTROL_ALLOW_METHODS = 'Access-Control-Allow-Methods'
# 
# ACCESS_CONTROL_MAX_AGE = 'Access-Control-Max-Age'
# 
# Path: example/dj/apps/app/tests/test_case.py
# class PystonTestCase(RestTestCase):
# 
#     USER_API_URL = '/api/user/'
#     USER_WITH_FORM_API_URL = '/api/user-form/'
#     ISSUE_API_URL = '/api/issue/'
#     ISSUE_WITH_FORM_API_URL = '/api/issue-form/'
#     EXTRA_API_URL = '/api/extra/'
#     COUNT_ISSUES_PER_USER = '/api/count-issues-per-user/'
#     COUNT_WATCHERS_PER_ISSUE = '/api/count-watchers-per-issue/'
#     TEST_CC_API_URL = '/api/test-cc/'
# 
#     user_id = 0
#     issue_id = 0
# 
#     DATA_AMOUNT = 10
# 
#     def get_pk(self, resp):
#         return self.deserialize(resp).get('id')
# 
#     def get_pk_list(self, resp, only_pks=None):
#         return [obj.get('id') for obj in self.deserialize(resp) if not only_pks or obj.get('id') in only_pks]
# 
#     def get_user_data(self, prefix='', **kwargs):
#         result = {'email': '%suser_%s@test.cz' % (prefix, self.user_id)}
#         self.user_id += 1
#         result.update(kwargs)
#         return result
# 
#     def get_issue_data(self, prefix='', **kwargs):
#         result = {'name': 'Issue %s' % self.issue_id, 'created_by': self.get_user_data(prefix),
#                   'leader': self.get_user_data(prefix)}
#         self.issue_id += 1
#         result.update(kwargs)
#         return result
# 
#     def get_users_data(self, prefix='', flat=False):
#         result = []
#         for i in range(self.DATA_AMOUNT):
#             if flat:
#                 result.append(self.get_user_data(prefix))
#             else:
#                 result.append((i, self.get_user_data(prefix)))
#         return result
# 
#     def get_issues_data(self, prefix='', flat=False):
#         result = []
#         for i in range(self.DATA_AMOUNT):
#             result.append((i, self.get_issue_data(prefix)))
#         return result
# 
#     def get_issues_and_users_data(self, prefix=''):
#         result = []
#         for i in range(self.DATA_AMOUNT):
#             issue_data = self.get_issue_data(prefix)
#             user_data = issue_data['created_by']
#             del issue_data['created_by']
#             result.append((i, issue_data, user_data))
#         return result


# Path: example/dj/apps/app/tests/cors.py
from six.moves.urllib.parse import urlencode
from django.test import TestCase
from django.test.utils import override_settings
from germanium.test_cases.rest import RestTestCase
from germanium.tools.trivials import assert_true, assert_false, assert_equal
from germanium.decorators import data_consumer
from pyston.resource import (ACCESS_CONTROL_ALLOW_ORIGIN, ACCESS_CONTROL_EXPOSE_HEADERS,
                             ACCESS_CONTROL_ALLOW_CREDENTIALS, ACCESS_CONTROL_ALLOW_HEADERS,
                             ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_MAX_AGE)
from .test_case import PystonTestCase

        assert_false(resp.has_header(ACCESS_CONTROL_ALLOW_METHODS))
        assert_true(resp.has_header(ACCESS_CONTROL_MAX_AGE))

        resp = self.options(self.USER_API_URL, headers={'HTTP_ORIGIN': FOO_DOMAIN})
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_ORIGIN))
        assert_true(resp.has_header(ACCESS_CONTROL_EXPOSE_HEADERS))
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_CREDENTIALS))
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_HEADERS))
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_METHODS))
        assert_true(resp.has_header(ACCESS_CONTROL_MAX_AGE))

        resp = self.options(self.USER_API_URL, headers={'HTTP_ORIGIN': BAR_DOMAIN})
        assert_false(resp.has_header(ACCESS_CONTROL_ALLOW_ORIGIN))
        assert_true(resp.has_header(ACCESS_CONTROL_EXPOSE_HEADERS))
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_CREDENTIALS))
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_HEADERS))
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_METHODS))

    @override_settings(PYSTON_CORS=True, PYSTON_CORS_WHITELIST=[FOO_DOMAIN[7:]])
    @data_consumer('get_users_data')
    def test_with_turned_on_cors_headers_is_included_with_valid_origin(self, number, data):
        resp = self.options(self.USER_API_URL, headers={'HTTP_ORIGIN': FOO_DOMAIN})
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_ORIGIN))
        assert_true(resp.has_header(ACCESS_CONTROL_EXPOSE_HEADERS))
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_CREDENTIALS))
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_HEADERS))
        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_METHODS))
        assert_true(resp.has_header(ACCESS_CONTROL_MAX_AGE))

        resp = self.get(self.USER_API_URL, headers={'HTTP_ORIGIN': FOO_DOMAIN})

        assert_true(resp.has_header(ACCESS_CONTROL_ALLOW_ORIGIN))