Exemple #1
0
 def test_get_modified_time(self):
     tzname = "Asia/Shanghai"
     with self.settings(USE_TZ = False, TIME_ZONE = tzname), self.save_file():
         modified_time = default_storage.get_modified_time("test.txt")
         logging.info("modified time: %s", modified_time)
         logging.info("is naive: %s", is_naive(modified_time))
         self.assertTrue(is_naive(modified_time))
         # Check that the timestamps are roughly equals in the correct timezone
         self.assertLess(abs(modified_time - timezone.now()), timedelta(seconds=10))
         self.assertEqual(default_storage.get_accessed_time("test.txt"), modified_time)
         self.assertEqual(default_storage.get_created_time("test.txt"), modified_time)
     with self.settings(USE_TZ = True, TIME_ZONE = tzname), self.save_file():
         modified_time = default_storage.get_modified_time("test.txt")
         logging.info("modified time: %s", modified_time)
         logging.info("is naive: %s", is_naive(modified_time))
         self.assertFalse(is_naive(modified_time))
         # Check that the timestamps are roughly equals in the correct timezone
         self.assertLess(abs(modified_time - timezone.now()), timedelta(seconds=10))
         self.assertEqual(default_storage.get_accessed_time("test.txt"), modified_time)
         self.assertEqual(default_storage.get_created_time("test.txt"), modified_time)
     with self.save_file():
         modified_time = default_storage.get_modified_time("test.txt")
         logging.info("modified time: %s", modified_time)
         logging.info("is naive: %s", is_naive(modified_time))
         self.assertFalse(is_naive(modified_time))
         # Check that the timestamps are roughly equals in the correct timezone
         self.assertLess(abs(modified_time - timezone.now()), timedelta(seconds=10))
         self.assertEqual(default_storage.get_accessed_time("test.txt"), modified_time)
         self.assertEqual(default_storage.get_created_time("test.txt"), modified_time)
Exemple #2
0
    def testGetModifiedTime(self):
        tzname = "America/Argentina/Buenos_Aires"
        with self.settings(USE_TZ=False, TIME_ZONE=tzname), self.save_file():
            modified_time = default_storage.get_modified_time("foo.txt")
            self.assertTrue(is_naive(modified_time))
            # Check that the timestamps are roughly equals in the correct timezone
            self.assertLess(abs(modified_time - timezone.now()),
                            timedelta(seconds=10))
            # All other timestamps are slaved to modified time.
            self.assertEqual(default_storage.get_accessed_time("foo.txt"),
                             modified_time)
            self.assertEqual(default_storage.get_created_time("foo.txt"),
                             modified_time)

        with self.save_file():
            modified_time = default_storage.get_modified_time("foo.txt")
            self.assertFalse(is_naive(modified_time))
            # Check that the timestamps are roughly equals
            self.assertLess(abs(modified_time - timezone.now()),
                            timedelta(seconds=10))
            # All other timestamps are slaved to modified time.
            self.assertEqual(default_storage.get_accessed_time("foo.txt"),
                             modified_time)
            self.assertEqual(default_storage.get_created_time("foo.txt"),
                             modified_time)
Exemple #3
0
    def check_availability(self):
        """
        Perform check against Default Storage.
        """
        try:
            name = default_storage.get_valid_name('Informer Storage')

            # Save data.
            content = ContentFile('File used by StorageInformer checking.')
            path = default_storage.save(name, content)

            # Check properties.
            default_storage.size(path)
            default_storage.url(path)
            default_storage.path(path)

            default_storage.get_accessed_time(path)
            default_storage.get_available_name(path)
            default_storage.get_created_time(path)
            default_storage.get_modified_time(path)
            default_storage.get_valid_name(path)

            # And remove file.
            default_storage.delete(path)

            storage = default_storage.__class__.__name__
        except Exception as error:
            raise InformerException(
                f'An error occurred when trying to use your Storage: {error}')
        else:
            return True, f'Your {storage} is operational.'
Exemple #4
0
def fetch_list_generation_state(request):
    filename = "depotlist.pdf"
    if m.ListGeneration.objects.first().generating:
        data = json.dumps({"generating": True})
        return HttpResponse(data, content_type="application/json")
    elif default_storage.exists(filename):
        gen_date = default_storage.get_created_time(filename)
        gen_date = gen_date.strftime("%B %d, %Y %H:%M:%S %Z")
        data = json.dumps({"list_generation_date": gen_date})
        return HttpResponse(data, content_type="application/json")
    else:
        raise Http404(f"{filename} does not exist.")
Exemple #5
0
def list_files_info():
    """
    Function returns a list of dictionaries for each file
    in 'saved_data' directory. Each file contains file name,
    created time and modified time.
    """
    _, filenames = default_storage.listdir('saved_data')
    files = [{
        'name':
        filename,
        'created':
        default_storage.get_created_time(f'saved_data/{filename}'),
        'modified':
        default_storage.get_modified_time(f'saved_data/{filename}')
    } for filename in filenames if re.search('^[a-z0-9]', filename)]

    return files
Exemple #6
0
 def get_created_time(self, name):
     return default_storage.get_created_time(name)