Ejemplo n.º 1
0
    def set_test_avatar_paths_settings(self):
        """Overrides the current settings to use test environment paths for avatar-related settings"""

        test_root = '/tmp/cardstories-test'

        self.default_media_url = settings.MEDIA_URL
        self.default_media_root = settings.MEDIA_ROOT
        self.default_avatars_default_subpath = settings.AVATARS_DEFAULT_SUBPATH
        self.default_avatars_cache_subpath = settings.AVATARS_CACHE_SUBPATH

        settings.MEDIA_ROOT = test_root
        settings.MEDIA_URL = '/media'
        settings.AVATARS_CACHE_SUBPATH = 'avatars/cache'
        settings.AVATARS_DEFAULT_SUBPATH = 'avatars/default'

        # Make sure the directory on the HD is empty
        shutil.rmtree(test_root, ignore_errors=True)

        # Copy default avatars over
        mkdir_p(os.path.join(test_root, 'avatars'))
        shutil.copytree(
            os.path.join(self.default_media_root,
                         self.default_avatars_default_subpath),
            os.path.join(settings.MEDIA_ROOT,
                         settings.AVATARS_DEFAULT_SUBPATH))
Ejemplo n.º 2
0
 def get_path(self, size="small"):
     '''The full system path to this user's avatar image file'''
     
     avatar_subdir, avatar_filename = self.get_subdir_filename(size=size)
     avatar_dir = os.path.join(settings.MEDIA_ROOT, settings.AVATARS_CACHE_SUBPATH, avatar_subdir)
     mkdir_p(avatar_dir) # Make sure the directory exists
     
     return os.path.join(avatar_dir, avatar_filename)
Ejemplo n.º 3
0
    def get_path(self, size="small"):
        '''The full system path to this user's avatar image file'''

        avatar_subdir, avatar_filename = self.get_subdir_filename(size=size)
        avatar_dir = os.path.join(settings.MEDIA_ROOT,
                                  settings.AVATARS_CACHE_SUBPATH,
                                  avatar_subdir)
        mkdir_p(avatar_dir)  # Make sure the directory exists

        return os.path.join(avatar_dir, avatar_filename)
Ejemplo n.º 4
0
 def test_10avatar_in_cache(self):
     """Test Avatar.in_cache()
     Requires users fixture"""
     
     self.set_test_avatar_paths_settings()
     
     from website.cardstories.avatar import Avatar
     from django.contrib.auth.models import User
     
     player_id = 1
     user = User.objects.get(id=player_id)
     avatar = Avatar(user)
     
     self.assertFalse(avatar.in_cache())
     
     mkdir_p('/tmp/cardstories-test/avatars/cache/000/000')
     with open('/tmp/cardstories-test/avatars/cache/000/000/1_small.jpg', 'w') as f:
         f.write('ok')
         
     self.assertTrue(avatar.in_cache())
     
     self.unset_test_avatar_paths_settings()
Ejemplo n.º 5
0
 def set_test_avatar_paths_settings(self):
     """Overrides the current settings to use test environment paths for avatar-related settings"""
     
     test_root = '/tmp/cardstories-test' 
     
     self.default_media_url = settings.MEDIA_URL
     self.default_media_root = settings.MEDIA_ROOT
     self.default_avatars_default_subpath = settings.AVATARS_DEFAULT_SUBPATH
     self.default_avatars_cache_subpath = settings.AVATARS_CACHE_SUBPATH
     
     settings.MEDIA_ROOT = test_root
     settings.MEDIA_URL = '/media'
     settings.AVATARS_CACHE_SUBPATH = 'avatars/cache'
     settings.AVATARS_DEFAULT_SUBPATH = 'avatars/default'
     
     # Make sure the directory on the HD is empty
     shutil.rmtree(test_root, ignore_errors=True)
     
     # Copy default avatars over
     mkdir_p(os.path.join(test_root, 'avatars'))
     shutil.copytree(os.path.join(self.default_media_root, self.default_avatars_default_subpath),
                     os.path.join(settings.MEDIA_ROOT, settings.AVATARS_DEFAULT_SUBPATH))
Ejemplo n.º 6
0
    def test_10avatar_in_cache(self):
        """Test Avatar.in_cache()
        Requires users fixture"""

        self.set_test_avatar_paths_settings()

        from website.cardstories.avatar import Avatar
        from django.contrib.auth.models import User

        player_id = 1
        user = User.objects.get(id=player_id)
        avatar = Avatar(user)

        self.assertFalse(avatar.in_cache())

        mkdir_p('/tmp/cardstories-test/avatars/cache/000/000')
        with open('/tmp/cardstories-test/avatars/cache/000/000/1_small.jpg',
                  'w') as f:
            f.write('ok')

        self.assertTrue(avatar.in_cache())

        self.unset_test_avatar_paths_settings()