def test_reporting_on_different_opportunities(self): self.login() self.fill_in_basic_info() user = User.objects.get(username=self.msisdn) t = Training.objects.create(title='Test op 2', description='This is a test', owner=user) v = Volunteer.objects.create(title='Test Volunteer 2', description='This is a test Volunteer', owner=user) kwargs = {'slug': t.slug, 'report_key_field': UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD } self.client.get(reverse('report_object', kwargs=kwargs)) kwargs = {'slug': v.slug, 'report_key_field': UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD } self.client.get(reverse('report_object', kwargs=kwargs)) self.assertEquals(helpers.get_object_votes(t, UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD), 1) self.assertEquals(helpers.get_object_votes(v, UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD), 1)
def test_reporting_on_training(self): self.login() self.fill_in_basic_info() user = User.objects.get(username=self.msisdn) t = Training.objects.create(title='Test op 1', description='This is a test', owner=user) kwargs = {'slug': t.slug, 'report_key_field': UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD } self.client.get(reverse('report_object', kwargs=kwargs)) self.assertEquals(helpers.get_object_votes(t, UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD), 1) #test duplicate votes self.client.get(reverse('report_object', kwargs=kwargs)) self.assertEquals(helpers.get_object_votes(t, UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD), 1) #test vote by other user self.logout() self.client = VLiveClient(HTTP_X_UP_CALLING_LINE_ID='27121111111', HTTP_REFERER='/') self.client.get(reverse('report_object', kwargs=kwargs)) self.assertEquals(helpers.get_object_votes(t, UmmeliOpportunity.ABUSE_REPORT_KEY_FIELD), 2)
def opportunity_report_warnings(context, obj, back): from ummeli.opportunities.models import UmmeliOpportunity scam_votes = helpers.get_object_votes(obj, UmmeliOpportunity.SCAM_REPORT_KEY_FIELD) postion_filled_votes = helpers.get_object_votes(obj, UmmeliOpportunity.POSITION_FILLED_REPORT_KEY_FIELD) inappropriate_votes = helpers.get_object_votes(obj, UmmeliOpportunity.INAPPROPRIATE_REPORT_KEY_FIELD) context['is_scam'] = scam_votes >= settings.REPORT_FLAG_LIMIT context['is_position_filled'] = postion_filled_votes >= settings.REPORT_FLAG_LIMIT obj.is_removed_by_community = inappropriate_votes >= settings.REPORT_FLAG_LIMIT context['object'] = obj context['back'] = reverse(back) return context
def _community_moderation(self, obj): # Poll redis for whether this opportunity was removed scam_votes = helpers.get_object_votes(obj, UmmeliOpportunity.SCAM_REPORT_KEY_FIELD) postion_filled_votes = helpers.get_object_votes(obj, UmmeliOpportunity.POSITION_FILLED_REPORT_KEY_FIELD) inappropriate_votes = helpers.get_object_votes(obj, UmmeliOpportunity.INAPPROPRIATE_REPORT_KEY_FIELD) is_scam = scam_votes >= settings.REPORT_FLAG_LIMIT is_position_filled = postion_filled_votes >= settings.REPORT_FLAG_LIMIT is_removed_by_community = inappropriate_votes >= settings.REPORT_FLAG_LIMIT if is_removed_by_community: return 'Removed by community' if is_position_filled: return 'Position filled' if is_scam: return 'Scam' return ''
def get_votes_for_object(context, obj, key): context[key] = helpers.get_object_votes(obj, key) return ''