Python django.test.Client() Examples
The following are 30 code examples for showing how to use django.test.Client(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
django.test
, or try the search function
.
Example 1
Project: django-phone-verify Author: CuriousLearner File: conftest.py License: GNU General Public License v3.0 | 6 votes |
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 2
Project: django_reddit Author: nikolak File: test_voting.py License: Apache License 2.0 | 6 votes |
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 3
Project: django_reddit Author: nikolak File: test_frontpage.py License: Apache License 2.0 | 6 votes |
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 4
Project: pyas2 Author: abhishek-ram File: tests.py License: GNU General Public License v2.0 | 6 votes |
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 5
Project: django-simple-forum Author: MicroPyramid File: tests.py License: MIT License | 6 votes |
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 6
Project: django-simple-forum Author: MicroPyramid File: tests.py License: MIT License | 6 votes |
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
Project: django-simple-forum Author: MicroPyramid File: tests.py License: MIT License | 6 votes |
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
Project: django-simple-forum Author: MicroPyramid File: tests.py License: MIT License | 6 votes |
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 9
Project: django-simple-forum Author: MicroPyramid File: tests.py License: MIT License | 6 votes |
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
Project: django-simple-forum Author: MicroPyramid File: tests.py License: MIT License | 6 votes |
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 11
Project: pythonjobs.ie Author: kimeraapp File: test_services.py License: GNU General Public License v2.0 | 5 votes |
def setUp(self): self.client = Client() self.token = generate_token()
Example 12
Project: pythonjobs.ie Author: kimeraapp File: test_views.py License: GNU General Public License v2.0 | 5 votes |
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 13
Project: OpenMDM Author: OpenMDM File: tests.py License: Apache License 2.0 | 5 votes |
def setUp(self): # Every test needs access to the request factory. self.factory = RequestFactory() self.user = User.objects.create_user( username='John Doe', email='', password='test') self.c = Client()
Example 14
Project: polls-api Author: apiaryio File: tests.py License: MIT License | 5 votes |
def test_supports_cors(self): client = Client() response = client.options('/', HTTP_ORIGIN='https://example.com/', secure=True) self.assertEqual(response.status_code, 200) self.assertEqual(response['Access-Control-Allow-Origin'], '*')
Example 15
Project: polls-api Author: apiaryio File: tests.py License: MIT License | 5 votes |
def setUp(self): self.client = Client()
Example 16
Project: polls-api Author: apiaryio File: tests.py License: MIT License | 5 votes |
def setUp(self): self.client = Client()
Example 17
Project: polls-api Author: apiaryio File: tests.py License: MIT License | 5 votes |
def setUp(self): self.client = Client()
Example 18
Project: polls-api Author: apiaryio File: tests.py License: MIT License | 5 votes |
def setUp(self): self.client = Client()
Example 19
Project: yang-explorer Author: CiscoDevNet File: testview.py License: Apache License 2.0 | 5 votes |
def setUp(self): demo = User() demo.username = 'demo' demo.first_name = 'Demo' demo.last_name = 'Last' demo.set_password('demo123') demo.is_staff = False demo.save() self.user = demo self.user_path = os.path.join('data', 'users', 'demo') self.chrome = Client() self.upload_files = []
Example 20
Project: pyconkr-2015 Author: pythonkr File: tests.py License: MIT License | 5 votes |
def setUp(self): self.client = Client() self.user = User.objects.create_user('testname', 'test@test.com', 'testpassword') self.client.login(username='testname', password='testpassword')
Example 21
Project: raveberry Author: raveberry File: raveberry_test.py License: GNU Lesser General Public License v3.0 | 5 votes |
def setUp(self): from core.urls import BASE # store the base object from the server to allow mocking and direct method access self.base = BASE self.client = Client() util.admin_login(self.client) self.base.musiq.playback.start_loop()
Example 22
Project: open-synthesis Author: twschiller File: common.py License: GNU General Public License v3.0 | 5 votes |
def setUp(self): self.client = Client() self.user = User.objects.create_user(USERNAME_PRIMARY, f'{USERNAME_PRIMARY}@thebeatles.com', PASSWORD) self.other = User.objects.create_user(USERNAME_OTHER, f'{USERNAME_OTHER}@thebeatles.com', PASSWORD)
Example 23
Project: django-rest-registration Author: apragacz File: base.py License: MIT License | 5 votes |
def setUp(self): super().setUp() self.client = Client()
Example 24
Project: adventurelookup-backend Author: AdventureLookup File: test_adventures.py License: GNU General Public License v3.0 | 5 votes |
def setUpTestData(cls): cls.client = Client() cls.test_data = {'name': 'LMoP', 'links': ["www.google.com", "another.website.io"]} cls.test_adv = Adventure.objects.create(**cls.test_data)
Example 25
Project: heltour Author: cyanfish File: test_api.py License: MIT License | 5 votes |
def setUp(self): self.api_key = ApiKey.objects.create(name='test_key') self.client = Client(HTTP_AUTHORIZATION="Token {}".format(self.api_key.secret_token))
Example 26
Project: django-herald Author: worthwhile File: test_views.py License: MIT License | 5 votes |
def test_index(self): client = Client() response = client.get('/herald/') self.assertContains(response, 'MyNotification')
Example 27
Project: django-herald Author: worthwhile File: test_views.py License: MIT License | 5 votes |
def test_preview_text(self): client = Client() response = client.get('/herald/0/text/') self.assertContains(response, 'Hello World') self.assertEqual(response['content-type'], 'text/plain; charset=utf-8')
Example 28
Project: django-herald Author: worthwhile File: test_views.py License: MIT License | 5 votes |
def test_preview_html(self): client = Client() response = client.get('/herald/0/html/') self.assertContains(response, '<html><body>Hello World</body></html>') self.assertEqual(response['content-type'], 'text/html; charset=utf-8')
Example 29
Project: django-herald Author: worthwhile File: test_admin.py License: MIT License | 5 votes |
def setUp(self): get_user_model().objects.create_superuser('admin', 'admin@example.com', 'password') self.client = Client() self.client.login(username='admin', password='password') self.notification = SentNotification.objects.create( recipients='test@example.com', date_sent=timezone.now(), status=SentNotification.STATUS_SUCCESS, notification_class='tests.notifications.MyNotification' )
Example 30
Project: call-tracking-django Author: TwilioDevEd File: test_views.py License: MIT License | 5 votes |
def setUp(self): self.client = Client()