# Path: example/generic_social_network/tests/controllers/controller_test_case.py
# class ControllerTestCase(unittest.TestCase):
#     def setUp(self):
#         from generic_social_network.app import my_app, db
# 
#         my_app.config['TESTING'] = True
#         self.app = my_app.test_client()
#         self.db = db
#         from generic_social_network.app.services import db_wrapper
#         db_wrapper.reset(self.db)
# 
#     def tearDown(self):
#         from generic_social_network.app.services import db_wrapper
#         db_wrapper.reset(self.db)
# 
#     def check_response(self, response, expected_code, expected_json):
#         # print('comparing', response.status_code, 'to', expected_code,
#         #       "\nand comparing", json.loads(response.data), 'to', expected_json)
#         if response.status_code != expected_code:
#             print(response.status_code, expected_code)
#         assert response.status_code == expected_code
#         if expected_json is not None:
#             self.assertEqual(json.loads(response.data.decode('utf-8')),expected_json)
# 
#     def check_jsonapi_response(self, response, expected_code, expected_json):
#         # print('comparing', response.status_code, 'to', expected_code,
#         #       "\nand comparing", json.loads(response.data), 'to', expected_json)
#         if response.status_code != expected_code:
#             print(response.status_code, expected_code)
#         assert response.status_code == expected_code
#         if expected_json is not None:
#             response_json = json.loads(response.data.decode('utf-8'))
#             if response_json.get('data') != expected_json.get('data'):
#                 print(response_json.get('data'), 'not equal to', expected_json.get('data'))
#             self.assertEqual(response_json.get('data'), expected_json.get('data'))
#             response_included = response_json.get('included', [])
#             expected_included = expected_json.get('included', [])
#             for i in response_included:
#                 if i not in expected_included:
#                     print(i, 'not in', expected_included)
#                 assert i in expected_included
#             for i in expected_included:
#                 assert i in response_included
# 
#     @classmethod
#     def suite(cls):
#         return unittest.TestLoader().loadTestsFromTestCase(cls)


import json
from copy import deepcopy
from .controller_test_case import ControllerTestCase

    def make_a_user(self, id_=1):
        return self.app.post('/users/{0}'.format(id_),
                             data=json.dumps(self.default_user_json(id_)),
                             content_type='application/json')

    def test_get_user(self):
        id_ = 1
        post_data = self.default_user_json(id_)
        self.make_a_user(id_)

        # get made user
        get_response = self.app.get('/users/{0}'.format(id_))
        self.check_jsonapi_response(get_response, 200, post_data)

    def test_get_nonexistant_user(self):
        response = self.app.get('/users/999')
        self.check_response(response, 404,
                            {
                                'error': 'The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.'})

    def test_create_valid_user(self):
        id_ = 1
        post_data = self.default_user_json(id_)
        create_response = self.app.post('/users/{0}'.format(id_), data=json.dumps(post_data),
                                        content_type='application/json')
        self.check_jsonapi_response(create_response, 201, post_data)

    def test_create_invalid_user(self):
        # missing name

# Path: example/generic_social_network/tests/controllers/controller_test_case.py
# class ControllerTestCase(unittest.TestCase):
#     def setUp(self):
#         from generic_social_network.app import my_app, db
# 
#         my_app.config['TESTING'] = True
#         self.app = my_app.test_client()
#         self.db = db
#         from generic_social_network.app.services import db_wrapper
#         db_wrapper.reset(self.db)
# 
#     def tearDown(self):
#         from generic_social_network.app.services import db_wrapper
#         db_wrapper.reset(self.db)
# 
#     def check_response(self, response, expected_code, expected_json):
#         # print('comparing', response.status_code, 'to', expected_code,
#         #       "\nand comparing", json.loads(response.data), 'to', expected_json)
#         if response.status_code != expected_code:
#             print(response.status_code, expected_code)
#         assert response.status_code == expected_code
#         if expected_json is not None:
#             self.assertEqual(json.loads(response.data.decode('utf-8')),expected_json)
# 
#     def check_jsonapi_response(self, response, expected_code, expected_json):
#         # print('comparing', response.status_code, 'to', expected_code,
#         #       "\nand comparing", json.loads(response.data), 'to', expected_json)
#         if response.status_code != expected_code:
#             print(response.status_code, expected_code)
#         assert response.status_code == expected_code
#         if expected_json is not None:
#             response_json = json.loads(response.data.decode('utf-8'))
#             if response_json.get('data') != expected_json.get('data'):
#                 print(response_json.get('data'), 'not equal to', expected_json.get('data'))
#             self.assertEqual(response_json.get('data'), expected_json.get('data'))
#             response_included = response_json.get('included', [])
#             expected_included = expected_json.get('included', [])
#             for i in response_included:
#                 if i not in expected_included:
#                     print(i, 'not in', expected_included)
#                 assert i in expected_included
#             for i in expected_included:
#                 assert i in response_included
# 
#     @classmethod
#     def suite(cls):
#         return unittest.TestLoader().loadTestsFromTestCase(cls)


# Path: example/generic_social_network/tests/controllers/users_controller_tests.py
import json
from copy import deepcopy
from .controller_test_case import ControllerTestCase


    def make_a_user(self, id_=1):
        return self.app.post('/users/{0}'.format(id_),
                             data=json.dumps(self.default_user_json(id_)),
                             content_type='application/json')

    def test_get_user(self):
        id_ = 1
        post_data = self.default_user_json(id_)
        self.make_a_user(id_)

        # get made user
        get_response = self.app.get('/users/{0}'.format(id_))
        self.check_jsonapi_response(get_response, 200, post_data)

    def test_get_nonexistant_user(self):
        response = self.app.get('/users/999')
        self.check_response(response, 404,
                            {
                                'error': 'The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.'})

    def test_create_valid_user(self):
        id_ = 1
        post_data = self.default_user_json(id_)
        create_response = self.app.post('/users/{0}'.format(id_), data=json.dumps(post_data),
                                        content_type='application/json')
        self.check_jsonapi_response(create_response, 201, post_data)

    def test_create_invalid_user(self):
        # missing name

        post_data = {