Python django.test.Client() Examples

The following are 30 code examples of django.test.Client(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.test , or try the search function .
Example #1
Source File: test_voting.py    From django_reddit with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        self.c = Client()
        self.credentials = {
            'username': 'voteusername',
            'password': 'password'
        }

        author = RedditUser.objects.create(
            user=User.objects.create_user(
                **self.credentials
            )
        )

        submission = Submission.objects.create(
            author=author,
            author_name=author.user.username,
            title="vote testing"
        )

        Comment.create(author=author,
                       raw_comment="root comment",
                       parent=submission).save() 
Example #2
Source File: test_frontpage.py    From django_reddit with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        self.c = Client()
        author = RedditUser.objects.create(
            user=User.objects.create_user(username="username",
                                          password="password"))

        for i in range(50):
            Submission.objects.create(score=50 - i,
                                      title=get_random_string(length=20),
                                      author=author).save()

        for i in range(1, 50, 10):
            # [1, 11, 21] [31, 41] have upvotes (lists demonstrate pages)
            Vote.create(user=author,
                        vote_object=Submission.objects.get(id=i),
                        vote_value=1).save()

        for i in range(2, 50, 15):
            # [2, 17] [32, 47] have downvotes (lists demonstrate pages)
            Vote.create(user=author,
                        vote_object=Submission.objects.get(id=i),
                        vote_value=-1).save() 
Example #3
Source File: tests.py    From pyas2 with GNU General Public License v2.0 6 votes vote down vote up
def testNoEncryptMessageNoMdn(self):
        """ Test Permutation 1: Sender sends un-encrypted data and does NOT request a receipt. """

        # Create the partner with appropriate settings for this case
        partner = models.Partner.objects.create(name='Client Partner',
                                                as2_name='as2server',
                                                target_url='http://localhost:8080/pyas2/as2receive',
                                                compress=False,
                                                mdn=False)

        # Build and send the message to server
        message_id = emailutils.make_msgid().strip('<>')
        in_message, response = self.buildSendMessage(message_id, partner)

        # Check if a 200 response was received
        self.assertEqual(response.status_code, 200)

        # Check if message was processed successfully
        out_message = models.Message.objects.get(message_id=message_id)
        self.assertEqual(out_message.status, 'S')

        # Check if input and output files are the same
        self.assertTrue(AS2SendReceiveTest.compareFiles(self.payload.file, out_message.payload.file)) 
Example #4
Source File: tests.py    From pyas2 with GNU General Public License v2.0 6 votes vote down vote up
def testSignMessageMdn(self):
        """ Test Permutation 8: Sender sends signed data and requests an unsigned receipt. """

        # Create the partner with appropriate settings for this case
        partner = models.Partner.objects.create(name='Client Partner',
                                                as2_name='as2server',
                                                target_url='http://localhost:8080/pyas2/as2receive',
                                                compress=False,
                                                signature='sha1',
                                                signature_key=self.server_crt,
                                                mdn=True)

        # Setup the message object and buid the message
        message_id = emailutils.make_msgid().strip('<>')
        in_message, response = self.buildSendMessage(message_id, partner)

        # Check if a 200 response was received
        self.assertEqual(response.status_code, 200)

        # Check if message was processed successfully
        out_message = models.Message.objects.get(message_id=message_id)
        # AS2SendReceiveTest.printLogs(out_message)
        self.assertEqual(out_message.status, 'S')

        # Process the MDN for the in message and check status
        AS2SendReceiveTest.buildMdn(in_message, response)
        # AS2SendReceiveTest.printLogs(in_message)
        self.assertEqual(in_message.status, 'S')

        # Check if input and output files are the same
        self.assertTrue(AS2SendReceiveTest.compareFiles(self.payload.file, out_message.payload.file)) 
Example #5
Source File: conftest.py    From django-phone-verify with GNU General Public License v3.0 6 votes vote down vote up
def client():
    """Django Test Client, with some convenient overriden methods.
    """
    from django.test import Client

    class _Client(Client):
        @property
        def json(self):
            """Add json method on the client for sending json type request.

            Usages:
            >>> import json
            >>> url = reverse("phone-verify")
            >>> client.json.get(url)
            >>> client.json.post(url, data=json.dumps(payload))
            """
            return PartialMethodCaller(
                obj=self, content_type='application/json;charset="utf-8"'
            )

    return _Client() 
Example #6
Source File: tests.py    From django-simple-forum with MIT License 6 votes vote down vote up
def setUp(self):
        self.client = Client()
        self.user = User.objects.create(
            first_name='Ravi',
            last_name='G',
            email='ravi@micropyramid.com',
            username='ravi@micropyramid.com',
            is_superuser=True
        )
        self.password = 'secret'
        self.user.set_password(self.password)
        self.user.save()
        self.category = ForumCategory.objects.create(
            created_by=self.user,
            title='Python',
            is_active=True,
            slug='python',
            description='dynamic programming language'
        ) 
Example #7
Source File: tests.py    From django-simple-forum with MIT License 6 votes vote down vote up
def setUp(self):
        self.client = Client()
        self.user = User.objects.create(
            first_name='Ravi',
            last_name='G',
            email='ravi@micropyramid.com',
            username='ravi@micropyramid.com',
            is_superuser=True
        )
        self.password = 'secret'
        self.user.set_password(self.password)
        self.user.save()
        self.category = ForumCategory.objects.create(
            created_by=self.user,
            title='Python',
            is_active=True,
            slug='python',
            description='dynamic programming language'
        ) 
Example #8
Source File: tests.py    From django-simple-forum with MIT License 6 votes vote down vote up
def setUp(self):
        self.client = Client()
        self.user = User.objects.create(
            first_name='Ravi',
            last_name='G',
            email='ravi@micropyramid.com',
            username='ravi@micropyramid.com',
            is_superuser=True
        )
        self.profile = UserProfile.objects.create(
            user=self.user,
        )
        self.password = 'secret'
        self.user.set_password(self.password)
        self.user.save()
        self.badge = Badge.objects.create(
            title='Developer',
            slug='developer'
        ) 
Example #9
Source File: tests.py    From django-simple-forum with MIT License 6 votes vote down vote up
def setUp(self):
        self.client = Client()
        self.user = User.objects.create(
            first_name='Ravi',
            last_name='G',
            email='ravi@micropyramid.com',
            username='ravi@micropyramid.com',
            is_superuser=True
        )
        self.password = 'secret'
        self.user.set_password(self.password)
        self.user.save()
        self.badge = Badge.objects.create(
            title='Developer',
            slug='developer'
        ) 
Example #10
Source File: tests.py    From django-simple-forum with MIT License 6 votes vote down vote up
def setUp(self):
        self.client = Client()
        self.user = User.objects.create(
            first_name='Ravi',
            last_name='G',
            email='ravi@micropyramid.com',
            username='ravi@micropyramid.com',
            is_superuser=True
        )
        self.password = 'secret'
        self.user.set_password(self.password)
        self.user.save()
        self.badge = Badge.objects.create(
            title='Developer',
            slug='developer'
        ) 
Example #11
Source File: tests.py    From django-simple-forum with MIT License 6 votes vote down vote up
def setUp(self):
        self.client = Client()
        self.user = User.objects.create(
            first_name='Ravi',
            last_name='G',
            email='ravi@micropyramid.com',
            username='ravi@micropyramid.com',
            is_superuser=True
        )
        self.password = 'secret'
        self.user.set_password(self.password)
        self.user.save()
        self.category = ForumCategory.objects.create(
            created_by=self.user,
            title='Python',
            is_active=True,
            slug='python',
            description='dynamic programming language'
        ) 
Example #12
Source File: simple_views_test.py    From rankedftw with GNU Affero General Public License v3.0 5 votes vote down vote up
def setUp(self):
        super().setUp()
        self.c = Client() 
Example #13
Source File: tests.py    From django-simple-forum with MIT License 5 votes vote down vote up
def setUp(self):
        self.client = Client()
        self.user = User.objects.create(
            first_name='Ravi',
            last_name='G',
            email='ravi@micropyramid.com',
            username='ravi@micropyramid.com',
            is_superuser=True
        )
        self.password = 'secret'
        self.user.set_password(self.password)
        self.user.save() 
Example #14
Source File: team_id_api_test.py    From rankedftw with GNU Affero General Public License v3.0 5 votes vote down vote up
def setUp(self):
        super().setUp()
        self.db.delete_all(keep=[Season])
        self.c = Client() 
Example #15
Source File: test_runner.py    From corruption_tracker with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def perfomance_test(url, request_type='get'):
    c = Client()
    response = getattr(c, request_type)(url)

    print(response.status_code)
    request_started = time.time()
    for x in range(100):
        getattr(c, request_type)(url)
        if x == 50:
            print('\n', '50x ', time.time() - request_started)

    print('\n', '100x ', time.time() - request_started) 
Example #16
Source File: tests.py    From django-simple-forum with MIT License 5 votes vote down vote up
def setUp(self):
        self.client = Client()
        self.user = User.objects.create(
            first_name='Ravi',
            last_name='G',
            email='ravi@micropyramid.com',
            username='ravi@micropyramid.com'
        )
        self.password = 'secret'
        self.user.set_password(self.password)
        self.user.save() 
Example #17
Source File: tests.py    From pyas2 with GNU General Public License v2.0 5 votes vote down vote up
def testCompressEncryptSignMessageSignMdn(self):
        """ Test Permutation 13: Sender sends compressed, encrypted and signed data and requests an signed receipt. """

        # Create the partner with appropriate settings for this case
        partner = models.Partner.objects.create(name='Client Partner',
                                                as2_name='as2server',
                                                target_url='http://localhost:8080/pyas2/as2receive',
                                                compress=True,
                                                encryption='des_ede3_cbc',
                                                encryption_key=self.server_crt,
                                                signature='sha1',
                                                signature_key=self.server_crt,
                                                mdn=True,
                                                mdn_sign='sha1')

        # Setup the message object and buid the message
        message_id = emailutils.make_msgid().strip('<>')
        in_message, response = self.buildSendMessage(message_id, partner)

        # Check if a 200 response was received
        self.assertEqual(response.status_code, 200)

        # Check if message was processed successfully
        out_message = models.Message.objects.get(message_id=message_id)
        # AS2SendReceiveTest.printLogs(out_message)
        self.assertEqual(out_message.status, 'S')

        # Process the MDN for the in message and check status
        AS2SendReceiveTest.buildMdn(in_message, response)
        # AS2SendReceiveTest.printLogs(in_message)
        self.assertEqual(in_message.status, 'S')

        # Check if input and output files are the same
        self.assertTrue(AS2SendReceiveTest.compareFiles(self.payload.file, out_message.payload.file)) 
Example #18
Source File: tests.py    From pyas2 with GNU General Public License v2.0 5 votes vote down vote up
def setUpTestData(cls):
        # Every test needs a client.
        cls.client = Client()
        cls.header_parser = HeaderParser()

        # Load the client and server certificates
        cls.server_key = models.PrivateCertificate.objects.create(
            certificate=os.path.join(TEST_DIR, 'as2server.pem'),
            certificate_passphrase='password'
        )
        cls.si_public_key = models.PublicCertificate.objects.create(
            certificate=os.path.join(TEST_DIR, 'si_public_key.crt'),
            ca_cert=os.path.join(TEST_DIR, 'si_public_key.ca'),
            verify_cert=False
        )

        # Setup the server organization and partner
        cls.organization = models.Organization.objects.create(
            name='Server Organization',
            as2_name='as2server',
            encryption_key=cls.server_key,
            signature_key=cls.server_key
        )

        cls.partner = models.Partner.objects.create(
            name='Sterling B2B Integrator',
            as2_name='SIAS2PRD',
            target_url='http://localhost:8080/pyas2/as2receive',
            compress=False,
            mdn=False,
            signature_key=cls.si_public_key,
            encryption_key=cls.si_public_key
        )

        # Initialise the payload i.e. the file to be transmitted
        cls.payload = models.Payload.objects.create(
            name='testmessage.edi',
            file=os.path.join(TEST_DIR, 'testmessage.edi'),
            content_type='application/edi-consent'
        ) 
Example #19
Source File: tests.py    From django-simple-forum with MIT License 5 votes vote down vote up
def setUp(self):
        self.client = Client()
        self.user = User.objects.create(
            first_name='Ravi',
            last_name='G',
            email='ravi@micropyramid.com',
            username='ravi@micropyramid.com'
        )
        self.password = 'secret'
        self.user.set_password(self.password)
        self.user.save() 
Example #20
Source File: search_view_test.py    From rankedftw with GNU Affero General Public License v3.0 5 votes vote down vote up
def setUp(self):
        super().setUp()
        self.db.delete_all(keep=[Cache, Season, Ranking])
        self.c = Client() 
Example #21
Source File: clan_view_test.py    From rankedftw with GNU Affero General Public License v3.0 5 votes vote down vote up
def setUp(self):
        super().setUp()
        cache.clear()
        self.db.clear_defaults()
        self.db.delete_all(keep=[Season, Cache, Ladder])
        self.c = Client() 
Example #22
Source File: team_view_test.py    From rankedftw with GNU Affero General Public License v3.0 5 votes vote down vote up
def setUp(self):
        super().setUp()
        self.db.delete_all(keep=[Cache, Ladder])
        self.db.create_season(id=36, version=Version.LOTV)
        self.c = Client() 
Example #23
Source File: player_view_test.py    From rankedftw with GNU Affero General Public License v3.0 5 votes vote down vote up
def setUp(self):
        super().setUp()
        cache.clear()
        self.db.delete_all(keep=[Season, Cache, Ranking])
        self.c = Client() 
Example #24
Source File: ladder_view_test.py    From rankedftw with GNU Affero General Public License v3.0 5 votes vote down vote up
def setUp(self):
        super().setUp()
        cache.clear()
        self.db.clear_defaults()
        self.db.delete_all(keep=[Season, Cache, Ladder, Team, Player])
        self.c = Client()

        # Change page size for easier testing.
        main.views.ladder.PAGE_SIZE = 10 
Example #25
Source File: clan_search_view_test.py    From rankedftw with GNU Affero General Public License v3.0 5 votes vote down vote up
def setUp(self):
        super().setUp()
        self.db.delete_all(keep=[Cache, Season, Ranking, Player])
        self.c = Client() 
Example #26
Source File: tests.py    From django-simple-forum with MIT License 5 votes vote down vote up
def setUp(self):
        self.client = Client()
        self.user = User.objects.create(
            first_name='Ravi',
            last_name='G',
            email='ravi@micropyramid.com',
            username='ravi@micropyramid.com',
            is_superuser=True
        )
        self.password = 'secret'
        self.user.set_password(self.password)
        self.user.save() 
Example #27
Source File: test_views.py    From pythonjobs.ie with GNU General Public License v2.0 5 votes vote down vote up
def setUp(self):
        self.client = Client()
        self.job = Job()
        self.job.position = "test"
        self.job.company_name = "company test"
        self.job.website = "pythonjobs.ie"
        self.job.category = "full"
        self.job.description = "Testing"
        self.job.email = "test@test.com"
        self.job.location = "Testing"
        self.job.save() 
Example #28
Source File: test_frontpage.py    From django_reddit with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        self.c = Client()
        author = RedditUser.objects.create(
            user=User.objects.create_user(username="username",
                                          password="password"))

        for i in range(50):
            Submission.objects.create(score=i ** 2,
                                      title=get_random_string(length=20),
                                      author=author) 
Example #29
Source File: test_comments.py    From django_reddit with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        self.c = Client()
        self.credentials = {'username': 'commentposttest',
                            'password': 'password'}
        author = RedditUser.objects.create(
            user=User.objects.create_user(**self.credentials)
        )

        Submission.objects.create(
            id=99,
            score=1,
            title=get_random_string(length=12),
            author=author
        ) 
Example #30
Source File: tests.py    From pyas2 with GNU General Public License v2.0 5 votes vote down vote up
def testNoEncryptMessageSignMdn(self):
        """ Test Permutation 3: Sender sends un-encrypted data and requests an signed receipt. """

        # Create the partner with appropriate settings for this case
        partner = models.Partner.objects.create(name='Client Partner',
                                                as2_name='as2server',
                                                target_url='http://localhost:8080/pyas2/as2receive',
                                                compress=False,
                                                mdn=True,
                                                mdn_mode='SYNC',
                                                mdn_sign='sha1',
                                                signature_key=self.server_crt)

        # Setup the message object and buid the message
        message_id = emailutils.make_msgid().strip('<>')
        in_message, response = self.buildSendMessage(message_id, partner)

        # Check if a 200 response was received
        self.assertEqual(response.status_code, 200)

        # Check if message was processed successfully
        out_message = models.Message.objects.get(message_id=message_id)
        # AS2SendReceiveTest.printLogs(out_message)
        self.assertEqual(out_message.status, 'S')

        # Process the MDN for the in message and check status
        AS2SendReceiveTest.buildMdn(in_message, response)
        # AS2SendReceiveTest.printLogs(in_message)
        self.assertEqual(in_message.status, 'S')

        # Check if input and output files are the same
        self.assertTrue(AS2SendReceiveTest.compareFiles(self.payload.file, out_message.payload.file))