Пример #1
0
 def setUpTestData(cls):
     cls.password = '******'
     cls.user = user_recipe.make()
     cls.user.set_password(cls.password)
     cls.user.save()
     cls.certification = certification_recipe.make()
     cls.url = reverse('api:certifications_api:certifications')
Пример #2
0
 def test_create(self):
     certification = certification_recipe.make()
     data = {'certification_id': certification, 'expiration_date': self.now, 'remind_at_date': None}
     user_certification = self.serializer.create(data)
     self.assertEqual(user_certification.user, self.user)
     self.assertEqual(user_certification.certification, certification)
     self.assertEqual(user_certification.expiration_date, self.now)
Пример #3
0
 def test_update(self):
     exam = exam_recipe.make()
     certification = certification_recipe.make()
     serializer = AddCertificationToExamSerializer()
     data = {'certification': [certification]}
     updated_exam = serializer.update(exam, data)
     self.assertTrue(certification in updated_exam.certification.all())
Пример #4
0
 def test_fields(self):
     certification = certification_recipe.make()
     serializer = CertificationSerializer(instance=certification)
     data = serializer.data
     self.assertEqual(data['id'], certification.id)
     self.assertEqual(data['title'], certification.title)
     self.assertEqual(data['description'], certification.description)
     self.assertEqual(data['number'], certification.number)
     self.assertEqual(data['vendor'], certification.vendor.pk)
Пример #5
0
 def test_patch(self):
     new_certification = certification_recipe.make()
     response = self.client.patch(self.url,
                                  {"certification": [new_certification.pk]},
                                  content_type='application/json')
     self.assertEqual(response.status_code, 200)
     exam_data = response.data
     self.assertEqual(exam_data['id'], self.exam.id)
     self.assertEqual(exam_data['title'], self.exam.title)
     self.assertEqual(exam_data['description'], self.exam.description)
     self.assertEqual(exam_data['number'], self.exam.number)
     self.assertTrue(new_certification.pk in exam_data['certification'])
Пример #6
0
 def test_update(self):
     user_exam = user_exam_recipe.make(user=self.user,
                                       user_certification=self.user_certification, exam=self.exam)
     new_certification = certification_recipe.make(title='Test-1', number='test-1', vendor=Vendor.objects.all()[0])
     new_user_certification = user_certification_recipe.make(user=self.user, certification=new_certification)
     new_exam = exam_recipe.make(title='Test-1', number='test-1')
     new_exam.certification.add(new_certification)
     data = {'user_certification_id': new_user_certification, 'exam_id': new_exam, 'date_of_pass': self.now,
             'remind_at_date': self.now}
     updated_exam = self.serializer.update(user_exam, data)
     self.assertEqual(updated_exam.user, self.user)
     self.assertEqual(updated_exam.user_certification_id, new_user_certification.pk)
     self.assertEqual(updated_exam.exam_id, new_exam.pk)
     self.assertEqual(updated_exam.date_of_pass, self.now)
     self.assertEqual(updated_exam.remind_at_date, self.now)
Пример #7
0
 def test_post(self):
     new_certification = certification_recipe.make(
         title='Test-1', number='test-1', vendor=Vendor.objects.all()[0])
     data = {
         'certification_id': new_certification.pk,
         'expiration_date': self.now.strftime('%Y-%m-%d'),
         'remind_at_date': None
     }
     response = self.client.post(self.url,
                                 data,
                                 content_type='application/json')
     self.assertEqual(response.status_code, 201)
     user_cert_data = response.data
     self.assertEqual(user_cert_data['user']['id'], self.user.id)
     self.assertEqual(user_cert_data['certification_id'],
                      new_certification.id)
     self.assertEqual(
         datetime.strptime(user_cert_data['expiration_date'],
                           '%Y-%m-%d').date(), self.now.date())
     self.assertIsNone(user_cert_data['remind_at_date'])
Пример #8
0
 def setUpTestData(cls):
     cls.certification = certification_recipe.make()