# Path: example/dj/apps/app/tests/factories.py
# class UserFactory(factory.django.DjangoModelFactory):
# 
#     first_name = factory.Sequence(lambda n: 'John{0}'.format(n))
#     last_name = factory.Sequence(lambda n: 'Doe{0}'.format(n))
#     email = factory.Sequence(lambda n: 'customer_{0}@example.com'.format(n).lower())
# 
#     class Meta:
#         model = models.User
# 
# class IssueFactory(factory.django.DjangoModelFactory):
# 
#     name = factory.fuzzy.FuzzyText(length=100)
#     created_by = factory.SubFactory('app.tests.factories.UserFactory')
#     leader = factory.SubFactory('app.tests.factories.UserFactory')
# 
#     class Meta:
#         model = models.Issue
# 
# 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.utils import override_settings
from germanium.decorators import data_consumer
from germanium.tools.trivials import assert_in, assert_equal, assert_true
from germanium.tools.http import (assert_http_bad_request, assert_http_not_found, assert_http_method_not_allowed,
                                  assert_http_accepted)
from germanium.tools.rest import assert_valid_JSON_created_response, assert_valid_JSON_response
from .factories import UserFactory, IssueFactory
from .test_case import PystonTestCase
            assert_true(accept_type in resp['Content-Type'])
            assert_http_not_found(resp)

    @data_consumer('get_issues_data')
    def test_issue_resource_should_support_only_xml_and_json_converters(self, number, data):
        for accept_type in self.ACCEPT_TYPES:
            resp = self.get('%s?_accept=%s' % (self.ISSUE_API_URL, accept_type))
            if accept_type in self.ACCEPT_TYPES[:2]:
                assert_in(accept_type, resp['Content-Type'])
            else:
                assert_in(self.ACCEPT_TYPES[0], resp['Content-Type'])

    @data_consumer('get_users_data')
    def test_head_requests(self, number, data):
        resp = self.post(self.USER_API_URL, data=data)
        pk = self.get_pk(resp)

        resp = self.head(self.USER_API_URL)
        assert_equal(resp.content.decode('utf-8'), '')

        resp = self.head('%s%s/' % (self.USER_API_URL, pk))
        assert_equal(resp.content.decode('utf-8'), '')

    @data_consumer('get_users_data')
    def test_options_requests(self, number, data):
        resp = self.post(self.USER_API_URL, data=data)
        pk = self.get_pk(resp)

        resp = self.options(self.USER_API_URL)
        assert_equal(resp.content.decode('utf-8'), '')

# Path: example/dj/apps/app/tests/factories.py
# class UserFactory(factory.django.DjangoModelFactory):
# 
#     first_name = factory.Sequence(lambda n: 'John{0}'.format(n))
#     last_name = factory.Sequence(lambda n: 'Doe{0}'.format(n))
#     email = factory.Sequence(lambda n: 'customer_{0}@example.com'.format(n).lower())
# 
#     class Meta:
#         model = models.User
# 
# class IssueFactory(factory.django.DjangoModelFactory):
# 
#     name = factory.fuzzy.FuzzyText(length=100)
#     created_by = factory.SubFactory('app.tests.factories.UserFactory')
#     leader = factory.SubFactory('app.tests.factories.UserFactory')
# 
#     class Meta:
#         model = models.Issue
# 
# 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/standard_operations.py
from six.moves.urllib.parse import urlencode
from django.test.utils import override_settings
from germanium.decorators import data_consumer
from germanium.tools.trivials import assert_in, assert_equal, assert_true
from germanium.tools.http import (assert_http_bad_request, assert_http_not_found, assert_http_method_not_allowed,
                                  assert_http_accepted)
from germanium.tools.rest import assert_valid_JSON_created_response, assert_valid_JSON_response
from .factories import UserFactory, IssueFactory
from .test_case import PystonTestCase

            assert_true(accept_type in resp['Content-Type'])
            assert_http_not_found(resp)

    @data_consumer('get_issues_data')
    def test_issue_resource_should_support_only_xml_and_json_converters(self, number, data):
        for accept_type in self.ACCEPT_TYPES:
            resp = self.get('%s?_accept=%s' % (self.ISSUE_API_URL, accept_type))
            if accept_type in self.ACCEPT_TYPES[:2]:
                assert_in(accept_type, resp['Content-Type'])
            else:
                assert_in(self.ACCEPT_TYPES[0], resp['Content-Type'])

    @data_consumer('get_users_data')
    def test_head_requests(self, number, data):
        resp = self.post(self.USER_API_URL, data=data)
        pk = self.get_pk(resp)

        resp = self.head(self.USER_API_URL)
        assert_equal(resp.content.decode('utf-8'), '')

        resp = self.head('%s%s/' % (self.USER_API_URL, pk))
        assert_equal(resp.content.decode('utf-8'), '')

    @data_consumer('get_users_data')
    def test_options_requests(self, number, data):
        resp = self.post(self.USER_API_URL, data=data)
        pk = self.get_pk(resp)

        resp = self.options(self.USER_API_URL)
        assert_equal(resp.content.decode('utf-8'), '')

        assert_equal(set(resp['Allow'].split(',')), {'OPTIONS', 'HEAD', 'POST', 'GET'})