コード例 #1
0
 def test_request_improper_input(self):
     self.test_user = User.objects.create_user(username='******',
                                               password='******',
                                               email='*****@*****.**')
     self.client.force_login(self.test_user)
     self.profile = Profile.objects.get(user=self.test_user)
     self.profile.first_name = 'Test'
     self.profile.last_name = 'User'
     self.profile.email_addr = '*****@*****.**'
     self.profile.phone_number = '+5555555555'
     sub1 = Subject(subject_name='Physics')
     sub1.save()
     self.profile.subjects_can_help.add(sub1)
     self.profile.save()
     response = self.client.post(
         '/requesttutor/',
         data={
             'customer_user': self.test_user,
             'customer_profile': self.profile,
             'course': 'improper',
             'notes': 'testing',
             'location': 'Alderman Library in Charlottesville, Virginia',
             'subject': str(sub1)
         })
     self.assertEqual(200, response.status_code)
     self.assertFormError(
         response, 'form', 'course',
         'Enter a valid course code using following format: TEST 2010 (Make sure to capitalize the course subject!)'
     )
コード例 #2
0
 def test_get_accepted_jobs(self):
     self.client.force_login(self.test_user)
     self.profile = Profile.objects.get(user=self.test_user)
     self.profile.first_name = 'Test'
     self.profile.last_name = 'User'
     self.profile.email_addr = '*****@*****.**'
     self.profile.phone_number = '+5555555555'
     sub1 = Subject(subject_name='Physics')
     sub1.save()
     self.profile.subjects_can_help.add(sub1)
     self.profile.save()
     customer = Profile.objects.get(user=self.test_user2)
     test_job1 = Job.objects.create(
         customer_user=self.test_user2,
         customer_profile=customer,
         tutor_user=self.test_user,
         tutor_profile=self.profile,
         course='TEST 2020',
         notes='testing',
         location='Alderman Library in Charlottesville, Virginia',
         subject=sub1)
     response = self.client.get('/acceptedjobs/')
     self.assertEqual(200, response.status_code)
     self.assertListEqual(
         list(response.context['job_list']),
         list(Job.objects.filter(tutor_user=self.test_user)))
コード例 #3
0
 def test_queryset_with_multiple_jobs_requested(self):
     self.test_user = User.objects.create_user(username='******',
                                               password='******',
                                               email='*****@*****.**')
     self.client.force_login(self.test_user)
     self.profile = Profile.objects.get(user=self.test_user)
     self.profile.first_name = 'Test'
     self.profile.last_name = 'User'
     self.profile.email_addr = '*****@*****.**'
     self.profile.phone_number = '+5555555555'
     sub1 = Subject(subject_name='Physics')
     sub1.save()
     self.profile.subjects_can_help.add(sub1)
     self.profile.save()
     test_job1 = Job.objects.create(customer_user=self.test_user,
                                    customer_profile=self.profile,
                                    course='TEST 2020',
                                    notes='testing',
                                    location='Alderman Library',
                                    subject=sub1)
     test_job2 = Job.objects.create(customer_user=self.test_user,
                                    customer_profile=self.profile,
                                    course='TEST 3030',
                                    notes='testing second',
                                    location='Alderman Library',
                                    subject=sub1)
     response = self.client.get('/requests/')
     self.assertEqual(200, response.status_code)
     self.assertListEqual(
         list(response.context['object_list']),
         list(Job.objects.filter(customer_user=self.test_user)))
コード例 #4
0
 def test_post_single_selected_job(self):
     self.client.force_login(self.test_user1)
     self.profile = Profile.objects.get(user=self.test_user1)
     self.profile.first_name = 'Test'
     self.profile.last_name = 'User'
     self.profile.email_addr = '*****@*****.**'
     self.profile.phone_number = '+5555555555'
     sub1 = Subject(subject_name='Physics')
     sub1.save()
     self.profile.subjects_can_help.add(sub1)
     self.profile.save()
     customer = Profile.objects.get(user=self.test_user2)
     test_job1 = Job.objects.create(customer_user=self.test_user2,
                                    customer_profile=customer,
                                    course='TEST 2020',
                                    notes='testing',
                                    location='Alderman Library',
                                    subject=sub1)
     response = self.client.post(
         '/jobs/',
         data={
             'selected_job':
             Job.objects.filter(subject=sub1).values_list('id', flat=True)
         })
     self.assertEqual(302, response.status_code)
     self.assertRedirects(response,
                          reverse('tutor:accepted'),
                          status_code=302,
                          target_status_code=200,
                          msg_prefix='',
                          fetch_redirect_response=True)
コード例 #5
0
 def test_queryset(self):
     self.client.force_login(self.test_user1)
     self.profile = Profile.objects.get(user=self.test_user1)
     self.profile.first_name = 'Test'
     self.profile.last_name = 'User'
     self.profile.email_addr = '*****@*****.**'
     self.profile.phone_number = '+5555555555'
     sub1 = Subject(subject_name='Physics')
     sub1.save()
     self.profile.subjects_can_help.add(sub1)
     self.profile.save()
     sub2 = Subject(subject_name='Mathematics')
     sub2.save()
     customer = Profile.objects.get(user=self.test_user2)
     test_job1 = Job.objects.create(customer_user=self.test_user2,
                                    customer_profile=customer,
                                    course='TEST 2020',
                                    notes='testing',
                                    location='Alderman Library',
                                    subject=sub1)
     test_job2 = Job.objects.create(customer_user=self.test_user2,
                                    customer_profile=customer,
                                    course='TEST 2020',
                                    notes='testing',
                                    location='Alderman Library',
                                    subject=sub2)
     response = self.client.get('/jobs/')
     self.assertEqual(200, response.status_code)
     self.assertTemplateUsed(response, template_name='tutor/jobs_list.html')
     self.assertListEqual(list(response.context['object_list']),
                          list(Job.objects.filter(subject=sub1)))
コード例 #6
0
 def test_queryset_with_no_jobs_requested(self):
     self.test_user = User.objects.create_user(username='******',
                                               password='******',
                                               email='*****@*****.**')
     self.client.force_login(self.test_user)
     self.profile = Profile.objects.get(user=self.test_user)
     self.profile.first_name = 'Test'
     self.profile.last_name = 'User'
     self.profile.email_addr = '*****@*****.**'
     self.profile.phone_number = '+5555555555'
     sub1 = Subject(subject_name='Physics')
     sub1.save()
     self.profile.subjects_can_help.add(sub1)
     self.profile.save()
     response = self.client.get('/requests/')
     self.assertEqual(200, response.status_code)
     self.assertListEqual(
         list(response.context['object_list']),
         list(Job.objects.filter(customer_user=self.test_user)))
コード例 #7
0
 def test_proper_profile(self):
     profile = Profile.objects.get(user=self.test_user)
     profile.first_name = 'Test'
     profile.last_name = 'User'
     profile.email_addr = '*****@*****.**'
     profile.phone_number = '+5555555555'
     sub = Subject(subject_name='math')
     sub.save()
     profile.subjects_can_help.add(sub)
     profile.save()
     form = List(data={
         'first_name': profile.first_name,
         'last_name': profile.last_name,
         'email_addr': profile.email_addr,
         'phone_number': profile.phone_number,
         'subjects_can_help': profile.subjects_can_help.all()
     },
                 instance=profile)
     self.assertTrue(form.is_bound)
     self.assertTrue(form.is_valid())
コード例 #8
0
 def test_anonymous_user_redirect(self):
     self.test_user = User.objects.create_user(username='******',
                                               password='******',
                                               email='*****@*****.**')
     self.profile = Profile.objects.get(user=self.test_user)
     sub1 = Subject(subject_name='Physics')
     sub1.save()
     test_job1 = Job.objects.create(
         customer_user=self.test_user,
         customer_profile=self.profile,
         course='TEST 2020',
         notes='testing',
         location='Alderman Library in Charlottesville, Virginia',
         subject=sub1)
     url = reverse('tutor:session', args=(test_job1.id, ))
     response = self.client.get(url)
     self.assertEqual(302, response.status_code)
     self.assertRedirects(response,
                          reverse('tutor:index'),
                          status_code=302,
                          target_status_code=200,
                          msg_prefix='',
                          fetch_redirect_response=True)
コード例 #9
0
 def test_request_proper_input(self):
     self.test_user = User.objects.create_user(username='******',
                                               password='******',
                                               email='*****@*****.**')
     self.client.force_login(self.test_user)
     self.profile = Profile.objects.get(user=self.test_user)
     self.profile.first_name = 'Test'
     self.profile.last_name = 'User'
     self.profile.email_addr = '*****@*****.**'
     self.profile.phone_number = '+5555555555'
     sub1 = Subject(subject_name='Physics')
     sub1.save()
     self.profile.subjects_can_help.add(sub1)
     self.profile.save()
     response = self.client.post(
         '/requesttutor/',
         data={
             'customer_user': self.test_user,
             'customer_profile': self.profile,
             'course': 'TEST 2020',
             'notes': 'testing',
             'location': 'Alderman Library in Charlottesville, Virginia',
             'subject': str(sub1)
         })
     self.assertEqual(302, response.status_code)
     self.assertRedirects(response,
                          reverse('tutor:requests'),
                          status_code=302,
                          target_status_code=200,
                          msg_prefix='',
                          fetch_redirect_response=True)
     redir_response = self.client.get('/requests/')
     self.assertListEqual(
         list(redir_response.context['object_list']),
         list(Job.objects.filter(customer_user=self.test_user)))
     self.assertEqual(len(list(redir_response.context['object_list'])), 1)
コード例 #10
0
 def test_unsuccessful_redirect(self):
     self.client.force_login(self.test_user)
     self.profile = Profile.objects.get(user=self.test_user)
     self.profile.first_name = 'Test'
     self.profile.last_name = 'User'
     self.profile.email_addr = '*****@*****.**'
     self.profile.phone_number = 'improper input'
     sub1 = Subject(subject_name='Physics')
     sub1.save()
     self.profile.subjects_can_help.add(sub1)
     self.profile.save()
     sub2 = Subject(subject_name='Mathematics')
     sub2.save()
     self.profile.subjects_can_help.add(sub2)
     self.profile.save()
     response = self.client.post(
         '/updateinfo/',
         data={
             'first_name':
             self.profile.first_name,
             'last_name':
             self.profile.last_name,
             'email_addr':
             self.profile.email_addr,
             'phone_number':
             self.profile.phone_number,
             'subjects_can_help':
             self.profile.subjects_can_help.all().values_list('id',
                                                              flat=True),
             'pic':
             self.profile.pic
         })
     self.assertEqual(302, response.status_code)
     self.assertRedirects(response,
                          reverse('tutor:updateinfo'),
                          status_code=302,
                          target_status_code=200,
                          msg_prefix='',
                          fetch_redirect_response=True)