def test_has_valid_profile(self): with patch.object(settings, 'PROFILE_APP_NAME', 'user_profile'): with patch.object(settings, 'PROFILE_MODEL_NAME', 'userprofile'): self.assertIs(has_valid_profile(), True) # settings attr provided, profile model has no image with patch('comment.utils.hasattr', return_value=False): self.assertIs(has_valid_profile(), False) # one of settings attribute is missing with patch.object(settings, 'PROFILE_MODEL_NAME', ''): self.assertIs(has_valid_profile(), False) # settings attr provided with wrong value with patch.object(settings, 'PROFILE_MODEL_NAME', 'wrong_value'): self.assertIs(has_valid_profile(), False) with patch.object(settings, 'COMMENT_USE_GRAVATAR', True): self.assertIs(has_valid_profile(), True)
def test_has_valid_profile(self): patch.object(settings, 'PROFILE_APP_NAME', 'user_profile').start() patch.object(settings, 'PROFILE_MODEL_NAME', 'userprofile').start() self.assertTrue(has_valid_profile()) # one of settings attribute is missing patch.object(settings, 'PROFILE_MODEL_NAME', '').start() self.assertFalse(has_valid_profile()) # settings attr provided with wrong value patch.object(settings, 'PROFILE_MODEL_NAME', 'wrong_value').start() self.assertFalse(has_valid_profile()) # settings attr provided, profile model has no image patch.object(settings, 'PROFILE_MODEL_NAME', 'userprofile').start() mocked_hasattr = patch('comment.utils.hasattr').start() mocked_hasattr.return_value = False self.assertFalse(has_valid_profile()) patch.object(settings, 'COMMENT_USE_GRAVATAR', True).start() self.assertTrue(has_valid_profile())
def test_has_valid_profile(self): setattr(settings, 'PROFILE_APP_NAME', 'user_profile') setattr(settings, 'PROFILE_MODEL_NAME', 'userprofile') has_profile = has_valid_profile() self.assertTrue(has_profile) # one of settings attribute is missing setattr(settings, 'PROFILE_MODEL_NAME', '') has_profile = has_valid_profile() self.assertFalse(has_profile) # settings attr provided with wrong value setattr(settings, 'PROFILE_MODEL_NAME', 'wrong_value') has_profile = has_valid_profile() self.assertFalse(has_profile) # settings attr provided, profile model has no image setattr(settings, 'PROFILE_MODEL_NAME', 'userprofile') mocked_hasattr = patch('comment.utils.hasattr').start() mocked_hasattr.return_value = False has_profile = has_valid_profile() self.assertFalse(has_profile)
def __call__(self): return { 'model_object': self.model_object, 'model_name': self.model_name, 'model_id': self.model_id, 'app_name': self.app_name, 'user': self.request.user, 'comments': self.get_comments(), 'login_url': self.get_login_url(), 'has_valid_profile': has_valid_profile(), 'allowed_flags': settings.COMMENT_FLAGS_ALLOWED, 'is_anonymous_allowed': settings.COMMENT_ALLOW_ANONYMOUS, 'is_translation_allowed': settings.COMMENT_ALLOW_TRANSLATION, 'is_subscription_allowed': settings.COMMENT_ALLOW_SUBSCRIPTION, 'oauth': self.is_oauth() }
def test_gravatar_enabled(self): self.assertIs(has_valid_profile(), True)
def test_wrong_setting_attribute(self): self.assertIs(has_valid_profile(), False)
def test_model_provided_without_image(self): with patch('comment.utils.hasattr', return_value=False): self.assertIs(has_valid_profile(), False)
def test_success(self): self.assertIs(has_valid_profile(), True)