예제 #1
0
    def test_normalize_authors_newlines(self):
        '''
        Since each author is entered on a new line, depending on the OS, the newline
        delimiter may not be only '\n'. Thus, we check to make sure that all newlines
        are converted to '\n'.
        '''
        expected_authors = "Author One\nAuthor Two\nAuthor Three"
        post = self.post.copy()

        cases = [
            #CR+LF newline (Windows)
            "Author One\r\nAuthor Two\r\nAuthor Three",
            #LF newline (*nix)
            "Author One\nAuthor Two\nAuthor Three",
            #CR newline (Old OSes)
            "Author One\rAuthor Two\rAuthor Three",
            #Mixed newline
            #NOTE: This fails because \n\r is considered two newlines. We'll
            #      accept that.
            #"Author One\rAuthor Two\n\rAuthor Three",
        ]

        for c in cases:
            post['authors'] = c

            f = PaperForm(post)
            self.assertTrue(f.is_valid())
            self.assertEqual(f.cleaned_data['authors'], expected_authors)
예제 #2
0
    def test_empty_form_errors(self):
        #Make all the values in the data empty
        post = dict((k, '') for (k, v) in self.post.iteritems())
        f = PaperForm(post)

        self.assertFalse(f.is_valid())
        self.assertEqual(f.errors, {
            'title': [u'This field is required.'], 
            'authors': [u'This field is required.'], 
        })
예제 #3
0
 def test_invalid_upload_file(self):
     '''
     If uploaded file does not have extension of
     settings.ALLOWED_UPLOAD_EXTENSIONS, then file should be rejected.
     '''
     #This is a dummy blank png file, which is not allowed.
     f = open(os.path.join(self.TEST_FILES_PATH, 'blank.png'), 'rb')
     invalid_files = self.files.copy()
     invalid_files['file'] = SimpleUploadedFile(f.name, f.read())
     f.close()
     
     f = PaperForm(self.post, invalid_files)
     self.assertFalse(f.is_valid())
예제 #4
0
    def test_oversized_upload_file(self):
        '''
        If uploaded file size is greater than
        settings.MAXIMUM_UPLOAD_SIZE_BYTES, then file should be rejected.
        '''
        #Temporarily set maximum file size to 0.
        temp = settings.MAXIMUM_UPLOAD_SIZE_BYTES
        settings.MAXIMUM_UPLOAD_SIZE_BYTES = 0

        f = PaperForm(self.post, self.files)
        self.assertFalse(f.is_valid())

        #Undo setting
        settings.MAXIMUM_UPLOAD_SIZE_BYTES = temp
예제 #5
0
    def test_valid_form(self):
        f = PaperForm(self.post, self.files)

        self.assertTrue(f.is_valid())