Esempio n. 1
0
    def test_add_timestamp_prefix(self):
        """
        Check if `add_timestamp_prefix` function prefixes file names
        correctly.

        If a given file name does not include a timestamp prefix of
        the form `YYYY-MM-DD_hh-mm-ss_`, the function is expected to
        generate one and prepend it to the file name. If the file name
        has been prefixed before, the function is expected to return
        the file name as is.
        """
        file_name = add_timestamp_prefix(self.file_name)
        self.assertTrue(re.match(
                '\d{4}(-\d{2}){2}_(\d{2}-){2}\d{2}_'+self.file_name,
                file_name))
        file_name = add_timestamp_prefix('')
        self.assertTrue(
            re.match('\d{4}(-\d{2}){2}_(\d{2}-){2}\d{2}_$', file_name))
        file_name = add_timestamp_prefix(file_name)
        self.assertTrue(
            re.match('\d{4}(-\d{2}){2}_(\d{2}-){2}\d{2}_$', file_name))
Esempio n. 2
0
    def setUpClass(cls):
        """
        Set up test environment.

        This method creates a temporary folder for test files to be
        uploaded, defines a default prefix to be used for names of
        test files, and obtains the URL to upload files to via POST
        requests.

        The `uploaded_files` list initialized by this method is used
        to collect (names of) files that were uploaded by individual
        tests, making it possible to easily remove them later on.
        """
        cls.testdir = tempfile.mkdtemp(suffix='.test', dir=ROOT_PATH)
        cls.file_prefix = add_timestamp_prefix('')
        cls.analyse_url = reverse('analyse')
        cls.uploaded_files = []