コード例 #1
0
    def setUp(self):
        start_date = datetime.datetime(2000, 1, 1, tzinfo=UTC())
        end_date = datetime.datetime(2010, 12, 31, tzinfo=UTC())
        #self.course = CourseFactory.create(
        #    org='org', number='num', run='run', display_name='test_course',
        #    start=start_date, end=end_date)
        for i in xrange(1, 10):
            random = i * randint(1, 100)
            try: 
                self.course = CourseFactory.create(
                    org='org_' + str(random), number='num', run="run", display_name='test_course',
                    start=start_date, end=end_date)
                break
            except DuplicateCourseError:
                print "wow"

        UserFactory.reset_sequence()
        self.students = UserFactory.create_batch(3)
        for student in self.students:
            CourseEnrollmentFactory.create(
                user=student, course_id=self.course.id)

        self.course.save()

        self.prog_name = "create_certs"
        self.args_create = ["create", self.course.id.to_deprecated_string()]
        self.args_delete = ["delete", self.course.id.to_deprecated_string()]
        self.args_report = ["report", self.course.id.to_deprecated_string()]
        self.args_publish = ["publish", self.course.id.to_deprecated_string()]
        self.kwargs = {
            "noop": False, "username": False,
            "debug": False, "prefix": "", "exclude": None}

        patcher0 = patch('pdfgen.views.logging')
        self.log_mock = patcher0.start()
        self.addCleanup(patcher0.stop)

        patcher1 = patch('pdfgen.views.S3Connection')
        self.s3conn_mock = patcher1.start()
        self.addCleanup(patcher1.stop)

        patcher2 = patch('pdfgen.views.Key')
        self.s3key_mock = patcher2.start()
        self.addCleanup(patcher2.stop)
        self.s3key_mock().generate_url.return_value = "http://example.com"

        self.pdf_path = settings.PDFGEN_BASE_PDF_DIR + "/" + self.kwargs['prefix'] + "-".join(
            self.course.id.to_deprecated_string().split('/')) + ".pdf"
        self.base_pdf = canvas.Canvas(self.pdf_path, pagesize=landscape(A4))
        self.base_pdf.showPage()
        self.base_pdf.save()