예제 #1
0
    def setUp(self):
        """
        Setup before each test
        We force the locale to en otherwise it will use
        the locale of the host running the tests and we
        will get unpredictable results / 404s
        """

        self.client = Client()
        self.client.post(
            '/set_language/', data={'language': 'en'})
        logging.disable(logging.CRITICAL)
        self.user = UserF.create(**{
            'username': '******',
            'password': '******',
            'is_staff': True
        })
        self.user.set_password('password')
        self.user.save()
        self.project = ProjectF.create()
        self.certifying_organisation = CertifyingOrganisationF.create(
            project=self.project
        )
        self.course = CourseF.create(
            certifying_organisation=self.certifying_organisation
        )
예제 #2
0
 def setUp(self):
     self.client = Client()
     self.client.post('/set_language/', data={'language': 'en'})
     logging.disable(logging.CRITICAL)
     self.project = ProjectF.create()
     self.certifying_organisation = \
         CertifyingOrganisationF.create(project=self.project)
     self.training_center = \
         TrainingCenterF.create(
             certifying_organisation=self.certifying_organisation)
     self.course_convener = \
         CourseConvenerF.create(
             certifying_organisation=self.certifying_organisation)
     self.course_type = \
         CourseTypeF.create(
             certifying_organisation=self.certifying_organisation)
     self.course = CourseF.create(
         certifying_organisation=self.certifying_organisation,
         training_center=self.training_center,
         course_convener=self.course_convener,
         course_type=self.course_type)
     self.user = UserF.create(**{
         'username': '******',
         'password': '******',
         'is_staff': True
     })
     self.user.set_password('password')
     self.user.save()
예제 #3
0
    def setUp(self):
        """
        Setup before each test
        We force the locale to en otherwise it will use
        the locale of the host running the tests and we
        will get unpredictable results / 404s
        """
        self.client = Client()
        self.client.post(
            '/set_language/', data={'language': 'en'})
        logging.disable(logging.CRITICAL)
        self.user = UserF.create(**{
            'username': '******',
            'password': '******',
            'is_staff': True,
        })
        self.user.set_password('password')
        self.user.save()

        self.user2 = UserF.create(**{
            'username': '******',
            'password': '******',
            'is_staff': True,
            'first_name': 'User',
            'last_name': 'Last',
        })
        self.user.set_password('password')
        self.user.save()

        self.project = ProjectF.create(
            owner=self.user,
            project_representative=self.user2
        )
        self.certifying_organisation = \
            CertifyingOrganisationF.create()
        self.course_convener = CourseConvenerF.create()
        self.training_center = TrainingCenterF.create()
        self.course_type = CourseTypeF.create()
        self.course = CourseF.create(
            course_convener=self.course_convener,
            certifying_organisation=self.certifying_organisation,
            course_type=self.course_type,
            training_center=self.training_center
        )
        self.attendee = AttendeeF.create()
        self.certificate = CertificateF.create(
            course=self.course,
            attendee=self.attendee,
            author=self.user
        )
        self.certifying_organisation_certificate = (
            CertifyingOrganisationCertificateF.create(
                author=self.user,
                certifying_organisation=self.certifying_organisation
            )
        )
예제 #4
0
 def test_delete_with_duplicates(self):
     self.client.login(username='******', password='******')
     course2 = CourseF.create(
         certifying_organisation=self.certifying_organisation
     )
     course2.slug = self.course.slug
     course2.save()
     response = self.client.get(reverse('course-delete', kwargs={
         'project_slug': self.project.slug,
         'organisation_slug': self.certifying_organisation.slug,
         'slug': course2.slug
     }))
     self.assertEqual(response.status_code, 302)
     expected_url = reverse('certifyingorganisation-detail', kwargs={
         'project_slug': self.project.slug,
         'slug': self.certifying_organisation.slug,
     })
     self.assertRedirects(response, expected_url)
예제 #5
0
    def test_issue_certificate_without_credit(self):
        """Test when the organisation has no credit available."""

        # The organisation credit is set to 0
        organisation = \
            CertifyingOrganisationF.create(
                project=self.project, organisation_credits=0)
        self.course = CourseF.create(certifying_organisation=organisation)
        self.course_attendee = CourseAttendeeF.create(course=self.course)

        # Issue certificate
        certificate_create = \
            CertificateCreateView(
                project_slug=self.project.slug,
                organisation_slug=organisation.slug,
                course_slug=self.course.slug)
        form = \
            CertificateForm(
                user=self.user,
                course=self.course,
                attendee=self.course_attendee.attendee,
            )

        response = certificate_create.form_valid(form)
        is_paid = form['is_paid'].value()
        self.assertEquals(response.status_code, 302)

        # Newly created object test
        certificate = \
            Certificate.objects.get(attendee=self.course_attendee.attendee)
        certificate.is_paid = is_paid

        self.assertEquals(
            certificate.course.certifying_organisation.organisation_credits,
            -3)
        self.assertEquals(certificate.is_paid, False)
예제 #6
0
    def test_issue_certificate_with_credit(self):
        """
        Test issue certificate when organisation is set to have 10 credits.

        """

        organisation = \
            CertifyingOrganisationF.create(
                project=self.project, organisation_credits=10)
        self.course = CourseF.create(certifying_organisation=organisation)
        self.course_attendee = CourseAttendeeF.create(course=self.course)

        # Issue certificate
        certificate_create = \
            CertificateCreateView(
                project_slug=self.project.slug,
                organisation_slug=organisation.slug,
                course_slug=self.course.slug)
        form = \
            CertificateForm(
                user=self.user,
                course=self.course,
                attendee=self.course_attendee.attendee,
            )

        response = certificate_create.form_valid(form)
        is_paid = form['is_paid'].value()
        self.assertEquals(response.status_code, 302)

        # Newly created object test
        certificate = \
            Certificate.objects.get(attendee=self.course_attendee.attendee)
        certificate.is_paid = is_paid

        # Test remaining credits in the organisation
        self.assertEquals(
            certificate.course.certifying_organisation.organisation_credits, 7)

        # Test status of the certificate
        self.assertEquals(certificate.is_paid, True)

        # Add another attendee
        course_attendee2 = CourseAttendeeF.create(course=self.course)

        # Issue another certificate
        certificate_create = \
            CertificateCreateView(
                project_slug=self.project.slug,
                organisation_slug=organisation.slug,
                course_slug=self.course.slug)
        form2 = \
            CertificateForm(
                user=self.user,
                course=self.course,
                attendee=course_attendee2.attendee,
            )
        response = certificate_create.form_valid(form2)
        is_paid = form2['is_paid'].value()
        self.assertEquals(response.status_code, 302)

        # Newly created object test
        certificate2 = \
            Certificate.objects.get(attendee=course_attendee2.attendee)
        certificate2.is_paid = is_paid

        self.assertEquals(
            certificate2.course.certifying_organisation.organisation_credits,
            4)
        self.assertEquals(certificate2.is_paid, True)