def test_file_preference_conflicting_file_names(self):
        '''
        f2 should have a different file name to f, since Django storage needs
        to differentiate between the two
        '''
        f = SimpleUploadedFile('test_file_c95d02ef-0e5d-4d36-98c0-1b54505860d0.txt', 'hello world'.encode('utf-8'))
        f2 = SimpleUploadedFile('test_file_c95d02ef-0e5d-4d36-98c0-1b54505860d0.txt', 'hello world 2'.encode('utf-8'))
        p = global_preferences_registry.get(section='blog', name='logo')
        manager = global_preferences_registry.manager()

        manager['blog__logo'] = f
        manager['blog__logo2'] = f2

        self.assertEqual(
            manager['blog__logo2'].read(),
            b'hello world 2')
        self.assertEqual(
            manager['blog__logo'].read(),
            b'hello world')

        self.assertNotEqual(
            manager['blog__logo'].url,
            manager['blog__logo2'].url
        )
        self.assertNotEqual(
            manager['blog__logo'].path,
            manager['blog__logo2'].path
        )
    def test_file_preference_api_repr_returns_path(self):
        f = SimpleUploadedFile('test_file.txt', 'hello world'.encode('utf-8'))
        p = global_preferences_registry.get(section='blog', name='logo')
        manager = global_preferences_registry.manager()
        manager['blog__logo'] = f

        f = manager['blog__logo']
        self.assertEqual(p.api_repr(f), f.url)
    def test_can_get_db_pref_from_manager(self):
        manager = registry.manager()
        manager.queryset.delete()
        pref = manager.get_db_pref(section='test', name='TestGlobal1')

        self.assertEqual(pref.section, 'test')
        self.assertEqual(pref.name, 'TestGlobal1')
        self.assertEqual(
            pref.raw_value, registry.get('test__TestGlobal1').default)
예제 #4
0
    def test_can_get_db_pref_from_manager(self):
        manager = registry.manager()
        manager.queryset.delete()
        pref = manager.get_db_pref(section='test', name='TestGlobal1')

        self.assertEqual(pref.section, 'test')
        self.assertEqual(pref.name, 'TestGlobal1')
        self.assertEqual(pref.raw_value,
                         registry.get('test__TestGlobal1').default)
 def test_can_delete_file_preference(self):
     f = SimpleUploadedFile('test_file.txt', 'hello world'.encode('utf-8'))
     p = global_preferences_registry.get(section='blog', name='logo')
     manager = global_preferences_registry.manager()
     manager['blog__logo'] = f
     path = os.path.join(settings.MEDIA_ROOT, p.get_upload_path(), f.name)
     self.assertTrue(os.path.exists(path))
     manager['blog__logo'].delete()
     self.assertFalse(os.path.exists(path))
    def test_file_preference_api_repr_returns_path(self):
        f = SimpleUploadedFile('test_file.txt', 'hello world'.encode('utf-8'))
        p = global_preferences_registry.get(section='blog', name='logo')
        manager = global_preferences_registry.manager()
        manager['blog__logo'] = f

        f = manager['blog__logo']
        self.assertEqual(
            p.api_repr(f),
            f.url
        )
 def test_file_preference_store_file_path(self):
     f = SimpleUploadedFile('test_file.txt', 'hello world'.encode('utf-8'))
     p = global_preferences_registry.get(section='blog', name='logo')
     manager = global_preferences_registry.manager()
     manager['blog__logo'] = f
     self.assertEqual(manager['blog__logo'].read(), b'hello world')
     self.assertEqual(
         manager['blog__logo'].url,
         os.path.join(settings.MEDIA_URL, p.get_upload_path(), f.name))
     self.assertEqual(
         manager['blog__logo'].path,
         os.path.join(settings.MEDIA_ROOT, p.get_upload_path(), f.name))
 def test_can_delete_file_preference(self):
     f = SimpleUploadedFile('test_file.txt', 'hello world'.encode('utf-8'))
     p = global_preferences_registry.get(section='blog', name='logo')
     manager = global_preferences_registry.manager()
     manager['blog__logo'] = f
     path = os.path.join(
         settings.MEDIA_ROOT,
         p.get_upload_path(),
         f.name
     )
     self.assertTrue(os.path.exists(path))
     manager['blog__logo'].delete()
     self.assertFalse(os.path.exists(path))
 def test_file_preference_store_file_path(self):
     f = SimpleUploadedFile('test_file.txt', 'hello world'.encode('utf-8'))
     p = global_preferences_registry.get(section='blog', name='logo')
     manager = global_preferences_registry.manager()
     manager['blog__logo'] = f
     self.assertEqual(
         manager['blog__logo'].read(),
         b'hello world')
     self.assertEqual(
         manager['blog__logo'].url,
         os.path.join(
             settings.MEDIA_URL, p.get_upload_path(), f.name)
     )
     self.assertEqual(
         manager['blog__logo'].path,
         os.path.join(
             settings.MEDIA_ROOT, p.get_upload_path(), f.name)
         )
 def test_can_register_and_retrieve_preference_with_section_none(self):
     no_section_pref = global_preferences_registry.get(name="no_section")
     self.assertEqual(no_section_pref.section, preferences.EMPTY_SECTION)
 def test_can_retrieve_preference_using_dotted_notation(self):
     registration_allowed = global_preferences_registry.get(
         name="registration_allowed", section="user")
     dotted_result = global_preferences_registry.get(
         "user__registration_allowed")
     self.assertEqual(registration_allowed, dotted_result)
    def test_can_get_to_string_notation(self):
        pref = global_preferences_registry.get('user__registration_allowed')

        self.assertEqual(pref.identifier(), 'user__registration_allowed')
 def test_can_register_and_retrieve_preference_with_section_none(self):
     no_section_pref = global_preferences_registry.get(name="no_section")
     self.assertEqual(no_section_pref.section, preferences.EMPTY_SECTION)
 def test_can_retrieve_preference_using_dotted_notation(self):
     registration_allowed = global_preferences_registry.get(
         name="registration_allowed", section="user")
     dotted_result = global_preferences_registry.get(
         "user__registration_allowed")
     self.assertEqual(registration_allowed, dotted_result)
    def test_can_get_to_string_notation(self):
        pref = global_preferences_registry.get('user__registration_allowed')

        self.assertEqual(pref.identifier(), 'user__registration_allowed')