示例#1
0
    def save(self, *args, **kwargs):
        if self.pk is None:  # Creating a new object
            self.file.name = random_string(10)
            if self.created is None:
                self.created = utc_now()
            self.size = self.file.size

        super(Attachment, self).save(*args, **kwargs)
示例#2
0
    def save(self, *args, **kwargs):
        if self.pk is None: # Creating a new object
            self.file.name = random_string(10)
            if self.created is None:
                self.created = utc_now()
            self.size = self.file.size

        super(Attachment, self).save(*args, **kwargs)
示例#3
0
    def save(self, *args, **kwargs):
        if self.pk is None: # Creating a new object
            self.key = random_string(64, chars=(string.ascii_lowercase + string.digits))
            if self.created is None:
                self.created = utc_now()
            if self.valid_to is None:
                self.valid_to = self.created + datetime.timedelta(days=app_settings.DEFAULT_VALIDITY)

        super(Invitation, self).save(*args, **kwargs)
示例#4
0
    def save(self, *args, **kwargs):
        if self.pk is None: # Creating a new object
            self.key = random_string(64, chars=(string.ascii_lowercase + string.digits))
            if self.created is None:
                self.created = utc_now()
            if self.valid_to is None:
                delta = datetime.timedelta(days=app_settings.DEFAULT_VALIDITY)
                self.valid_to = self.created + delta

        super(Invitation, self).save(*args, **kwargs)
示例#5
0
 def test_content_disposition_header_with_random_unicode_junk(self):
     path = self._create_file()
     name = random_string(
         20,
         chars=
         u'BacòԉíρsûϻᏧolrѕìtãmeéӽѵ߀ɭpèлuin.Iüà,ɦëǥhƅɢïêgԁSùúâɑfäbƃdkϳɰյƙyáFХ-åɋw'
     )
     response = self._request_file(path, name)
     self.assertEqual(response[u'Content-Disposition'],
                      u"attachment; filename*=UTF-8''%s" % urlquote(name))
示例#6
0
 def test_random_file(self):
     content = random_string(random.randrange(1000, 2000))
     path = self._create_file(content=content)
     response = self._request_file(path)
     self._check_response(response, FileResponse, 200)
     self._check_content(response, path)
示例#7
0
 def test_content_disposition_header_with_random_unicode_junk(self):
     path = self._create_file()
     name = random_string(20, chars=u'BacòԉíρsûϻᏧolrѕìtãmeéӽѵ߀ɭpèлuin.Iüà,ɦëǥhƅɢïêgԁSùúâɑfäbƃdkϳɰյƙyáFХ-åɋw')
     response = self._request_file(path, name)
     self.assertEqual(response[u'Content-Disposition'], u"attachment; filename*=UTF-8''%s" % urlquote(name))
示例#8
0
 def test_content_length_header_for_random_file(self):
     content = random_string(random.randrange(1000, 2000))
     path = self._create_file(content=content)
     response = self._request_file(path)
     self.assertEqual(response[u'Content-Length'], str(len(content)))
示例#9
0
 def test_random_file(self):
     content = random_string(random.randrange(1000, 2000))
     path = self._create_file(content=content)
     response = self._request_file(path)
     self._check_response(response, FileResponse, 200)
     self._check_content(response, path)
示例#10
0
 def test_content_length_header_for_random_file(self):
     content = random_string(random.randrange(1000, 2000))
     path = self._create_file(content=content)
     response = self._request_file(path)
     self.assertEqual(response[u'Content-Length'], str(len(content)))
示例#11
0
    def _check(self, length, chars):
        pattern = r'^[{chars}]*$'.format(chars=re.escape(chars))

        res = random_string(length, chars)
        self.assertEqual(len(res), length)
        self.assertRegexpMatches(res, pattern)
示例#12
0
    def _check(self, length, chars):
        pattern = r'^[{chars}]*$'.format(chars=re.escape(chars))

        res = random_string(length, chars)
        self.assertEqual(len(res), length)
        self.assertRegexpMatches(res, pattern)