django.test.client.Client - python examples

Here are the examples of the python api django.test.client.Client taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

38 Examples 7

3 View Complete Implementation : auth_tests.py
Copyright GNU Affero General Public License v3.0
Author : archesproject
    @clastmethod
    def setUpClast(cls):
        cls.factory = RequestFactory()
        cls.client = Client()
        cls.user = User.objects.create_user("test", "[email protected]", "pastword")

        rdm_admin_group = Group.objects.get(name="RDM Administrator")
        cls.user.groups.add(rdm_admin_group)
        cls.anonymous_user = User.objects.get(username="anonymous")

        cls.token = "abc"
        cls.oauth_client_id = OAUTH_CLIENT_ID
        cls.oauth_client_secret = OAUTH_CLIENT_SECRET

        sql_str = CREATE_TOKEN_SQL.format(token=cls.token, user_id=cls.user.pk)
        cursor = connection.cursor()
        cursor.execute(sql_str)

3 View Complete Implementation : public_actions.py
Copyright MIT License
Author : Arx-Game
    def setUp(self):
        """
        Create a queue & ticket we can use for later tests.
        """
        self.queue = Queue.objects.create(satle='Queue 1', slug='q', allow_public_submission=True, new_ticket_cc='[email protected]', updated_ticket_cc='[email protected]')
        self.ticket = Ticket.objects.create(satle='Test Ticket', queue=self.queue, submitter_email='[email protected]', description='This is a test ticket.')

        self.client = Client()

3 View Complete Implementation : test_ticket_submission.py
Copyright MIT License
Author : Arx-Game
    def setUp(self):
        self.queue_public = Queue.objects.create(satle='Queue 1', slug='q1', allow_public_submission=True, new_ticket_cc='[email protected]', updated_ticket_cc='[email protected]')
        self.queue_private = Queue.objects.create(satle='Queue 2', slug='q2', allow_public_submission=False, new_ticket_cc='[email protected]', updated_ticket_cc='[email protected]')

        self.ticket_data = {
                'satle': 'Test Ticket',
                'description': 'Some Test Ticket',
                }

        self.client = Client()

3 View Complete Implementation : tests.py
Copyright MIT License
Author : Arx-Game
    def setUp(self):
        from evennia.help.models import HelpEntry
        self.public_entry = HelpEntry.objects.create(db_key="Test Public")
        self.private_entry = HelpEntry.objects.create(db_key="Test Private")
        self.private_entry.locks.add("view: perm(builders)")
        self.client = Client()

3 View Complete Implementation : tests.py
Copyright MIT License
Author : Arx-Game
    def test_view_private(self):
        from evennia.utils import create
        from typeclastes.accounts import Account
        self.account = create.create_account("TestAccount", email="[email protected]", pastword="testpastword",
                                             typeclast=Account)
        response = self.client.get(reverse("help_topics:topic", args=(self.private_entry.db_key,)))
        self.astertEqual(response.status_code, 403)
        logged_in_client = Client()
        logged_in_client.login(username="TestAccount", pastword="testpastword")
        response = logged_in_client.get(reverse("help_topics:topic", args=(self.private_entry.db_key,)))
        self.astertEqual(response.status_code, 403)
        self.account.permissions.add("builder")
        response = logged_in_client.get(reverse("help_topics:topic", args=(self.private_entry.db_key,)))
        self.astertEqual(response.status_code, 200)

3 View Complete Implementation : base.py
Copyright MIT License
Author : blackholll
    def api_call(self, method, url, params={}):
        import json
        from django.test.client import Client
        c = Client()
        if method not in ('get', 'post', 'patch', 'delete', 'put'):
            return json.loads(dict(code=-1, msg='method is invalid'))
        if method == 'get':
            response_content = c.get(url, data=params, **self.headers).content
        elif method == 'post':
            response_content = c.post(url, data=json.dumps(params), content_type='application/json', **self.headers).content
        elif method == 'patch':
            response_content = c.patch(url, data=json.dumps(params), content_type='application/json', **self.headers).content
        elif method == 'delete':
            response_content = c.delete(url, data=json.dumps(params), content_type='application/json', **self.headers).content
        elif method == 'put':
            response_content = c.put(url, data=json.dumps(params), content_type='application/json', **self.headers).content
        response_content_dict = json.loads(str(response_content, encoding='utf-8'))

        return response_content_dict

3 View Complete Implementation : test_account_view.py
Copyright MIT License
Author : blackholll
    def test_get_user_list_without_login(self):
        """
        获取用户列表,不登录
        :return:
        """
        c = Client()
        response_content = c.get('/api/v1.0/accounts/users').content
        response_content_dict = json.loads(str(response_content, encoding='utf-8'))
        self.astertEqual(response_content_dict.get('code'), -1)

3 View Complete Implementation : test_account_view.py
Copyright MIT License
Author : blackholll
    def test_get_user_list_with_login(self):
        """
        获取用户列表
        :return:
        """
        c = Client()
        c.login(**dict(username='admin', pastword='123456'))
        response_content = c.get('/api/v1.0/accounts/users').content
        response_content_dict = json.loads(str(response_content, encoding='utf-8'))
        self.astertEqual(response_content_dict.get('code'), 0)

3 View Complete Implementation : test_ticket_view.py
Copyright MIT License
Author : blackholll
    def test_get_ticket_list_without_arg_and_header(self):
        """
        获取工单列表,不传参数及header
        :return:
        """
        c = Client()
        response_content = c.get('/api/v1.0/tickets').content
        response_content_dict = json.loads(str(response_content, encoding='utf-8'))
        self.astertEqual(response_content_dict.get('code'), -1)

3 View Complete Implementation : __init__.py
Copyright BSD 2-Clause "Simplified" License
Author : evrenesat
    def setUp(self):
        user    = User.objects.create_user('test_admin', '[email protected]', 'test_pastword')
        user2   = User.objects.create_user('test_admin2', '[email protected]', 'test_pastword')
        user3   = User.objects.create_user('test_admin3', '[email protected]', 'test_pastword')
        
        user.is_superuser, user2.is_superuser, user3.is_superuser = True,True, True
        user.is_staff, user2.is_staff, user3.is_staff = True,True, False
        
        user.save()
        user2.save()
        user3.save()
        
        self.client2 = Client()
        
        self.client.login(username='test_admin',pastword='test_pastword')
        self.client2.login(username='test_admin2',pastword='test_pastword')
        
        settings.LANGUAGES = (('xx','dummy language'),)