<commit_before>import datetime

from django.test import TestCase

from django.contrib.auth.models import User
from makahiki_profiles.models import Profile
from activities.models import Activity, ActivityMember, Commitment, CommitmentMember, Goal, GoalMember
from floors.models import Floor

class ActivitiesUnitTestCase(TestCase):
  fixtures = ["base_data.json", "user_data.json"]
  
  def testApproveAddsPoints(self):
    """Test for verifying that approving a user awards them points."""
    user = User.objects.all()[0]
    points = user.get_profile().points
    last_awarded_submission = user.get_profile().last_awarded_submission
    
    activity = Activity.objects.all()[0]
    activity_points = activity.point_value
    
    activity_member = ActivityMember(user=user, activity=activity)
    activity_member.save()
    
    # Verify that nothing has changed.
    self.assertTrue(points == user.get_profile().points)
    self.assertTrue(last_awarded_submission == user.get_profile().last_awarded_submission)
    
    activity_member.approval_status = "approved"
    activity_member.save()
    
    new_points = user.get_profile().points
    self.assertTrue(new_points - points == activity_points)
    self.assertTrue(activity_member.submission_date == user.get_profile().last_awarded_submission)
    
  def testApprovePostsMessage(self):
    """Test that an approved activity posts to the user's wall."""
    floor = Floor.objects.all()[0]
    num_posts = floor.post_set.count()
    profile = floor.profile_set.all()[0]
    
    activity = Activity.objects.all()[0]
    
    activity_member = ActivityMember(user=profile.user, activity=activity)
    activity_member.approval_status = "approved"
    activity_member.save()
    
    self.assertTrue(num_posts == floor.post_set.count() - 1)
    
  def testUnapproveRemovesPoints(self):
    """Test that unapproving a user removes their points."""
    user = User.objects.all()[0]
    points = user.get_profile().points
    last_awarded_submission = user.get_profile().last_awarded_submission
    
    activity = Activity.objects.all()[0]
    
    activity_member = ActivityMember(user=user, activity=activity)
    activity_member.approval_status = "approved"
    activity_member.save()
    award_date = activity_member.award_date
    
    activity_member.approval_status = "rejected"
    activity_member.save()
    new_points = user.get_profile().points
    
    self.assertTrue(activity_member.award_date is None)
    self.assertTrue(points == new_points)
    self.assertTrue(user.get_profile().last_awarded_submission < award_date)
    
  def testDeleteRemovesPoints(self):
    """Test that deleting an approved ActivityMember removes their points."""
    
    user = User.objects.all()[0]
    points = user.get_profile().points
    last_awarded_submission = user.get_profile().last_awarded_submission
    
    activity = Activity.objects.all()[0]
    
    activity_member = ActivityMember(user=user, activity=activity)
    activity_member.approval_status = "approved"
    activity_member.save()
    award_date = activity_member.award_date
    
    activity_member.delete()
    new_points = user.get_profile().points
    
    self.assertTrue(points == new_points)
    self.assertTrue(user.get_profile().last_awarded_submission < award_date)
    
class ActivitiesFunctionalTestCase(TestCase):
  fixtures = ["base_data.json", "user_data.json"]
  
  def setUp(self):
    self.user = User.objects.get(username="user")
    self.client.post('/account/login/', {"username": self.user.username, "password": "<PASSWORD>", "remember": False})
  
  def testLoadActivities(self):
    """Test that we can load the activity list page."""
    response = self.client.get('/activities/activity_list/')
    self.failUnlessEqual(response.status_code, 200)
    for activity in self.user.activity_set.all():
      self.assertNotIn(activity, response.context["available_items"])
      self.failUnless((activity in response.context["user_items"]) or (activity in response.context["completed_items"]))
      
  def testAddActivity(self):
    """Test that we can add an activity."""
    activity = Activity.objects.exclude(
      activitymember__user=self.user,
    )[0]
    response = self.client.post('/activities/add_activity/%d/' % activity.pk, {}, "multipart/form-data", True)
    self.assertRedirects(response, "/profiles/profile/%s/" % self.user.username)
    self.failUnless(activity in response.context["user_activities"])
    response = self.client.get('/activities/activity_list/')
    self.failUnless(activity in response.context["user_items"])
    
  def testApprovedActivity(self):
    """Test that approved activities appear in the correct location."""
    activity = Activity.objects.exclude(
      activitymember__user=self.user,
    )[0]
    member = ActivityMember(user=self.user, activity=activity, approval_status="approved")
    member.save()
    response = self.client.get('/activities/activity_list/')
    self.failUnless(activity in response.context["completed_items"])
    
class CommitmentsUnitTestCase(TestCase):
  fixtures = ["base_data.json", "user_data.json"]
  
  def testCompletionAddsPoints(self):
    """Tests that completing a task adds points."""
    user = User.objects.all()[0]<commit_msg>Updating test to reflect change from username to id.<commit_after>import datetime

from django.test import TestCase

from django.contrib.auth.models import User
from makahiki_profiles.models import Profile
from activities.models import Activity, ActivityMember, Commitment, CommitmentMember, Goal, GoalMember
from floors.models import Floor

class ActivitiesUnitTestCase(TestCase):
  fixtures = ["base_data.json", "user_data.json"]
  
  def testApproveAddsPoints(self):
    """Test for verifying that approving a user awards them points."""
    user = User.objects.all()[0]
    points = user.get_profile().points
    last_awarded_submission = user.get_profile().last_awarded_submission
    
    activity = Activity.objects.all()[0]
    activity_points = activity.point_value
    
    activity_member = ActivityMember(user=user, activity=activity)
    activity_member.save()
    
    # Verify that nothing has changed.
    self.assertTrue(points == user.get_profile().points)
    self.assertTrue(last_awarded_submission == user.get_profile().last_awarded_submission)
    
    activity_member.approval_status = "approved"
    activity_member.save()
    
    new_points = user.get_profile().points
    self.assertTrue(new_points - points == activity_points)
    self.assertTrue(activity_member.submission_date == user.get_profile().last_awarded_submission)
    
  def testApprovePostsMessage(self):
    """Test that an approved activity posts to the user's wall."""
    floor = Floor.objects.all()[0]
    num_posts = floor.post_set.count()
    profile = floor.profile_set.all()[0]
    
    activity = Activity.objects.all()[0]
    
    activity_member = ActivityMember(user=profile.user, activity=activity)
    activity_member.approval_status = "approved"
    activity_member.save()
    
    self.assertTrue(num_posts == floor.post_set.count() - 1)
    
  def testUnapproveRemovesPoints(self):
    """Test that unapproving a user removes their points."""
    user = User.objects.all()[0]
    points = user.get_profile().points
    last_awarded_submission = user.get_profile().last_awarded_submission
    
    activity = Activity.objects.all()[0]
    
    activity_member = ActivityMember(user=user, activity=activity)
    activity_member.approval_status = "approved"
    activity_member.save()
    award_date = activity_member.award_date
    
    activity_member.approval_status = "rejected"
    activity_member.save()
    new_points = user.get_profile().points
    
    self.assertTrue(activity_member.award_date is None)
    self.assertTrue(points == new_points)
    self.assertTrue(user.get_profile().last_awarded_submission < award_date)
    
  def testDeleteRemovesPoints(self):
    """Test that deleting an approved ActivityMember removes their points."""
    
    user = User.objects.all()[0]
    points = user.get_profile().points
    last_awarded_submission = user.get_profile().last_awarded_submission
    
    activity = Activity.objects.all()[0]
    
    activity_member = ActivityMember(user=user, activity=activity)
    activity_member.approval_status = "approved"
    activity_member.save()
    award_date = activity_member.award_date
    
    activity_member.delete()
    new_points = user.get_profile().points
    
    self.assertTrue(points == new_points)
    self.assertTrue(user.get_profile().last_awarded_submission < award_date)
    
class ActivitiesFunctionalTestCase(TestCase):
  fixtures = ["base_data.json", "user_data.json"]
  
  def setUp(self):
    self.user = User.objects.get(username="user")
    self.client.post('/account/login/', {"username": self.user.username, "password": "<PASSWORD>", "remember": False})
  
  def testLoadActivities(self):
    """Test that we can load the activity list page."""
    response = self.client.get('/activities/activity_list/')
    self.failUnlessEqual(response.status_code, 200)
    for activity in self.user.activity_set.all():
      self.assertNotIn(activity, response.context["available_items"])
      self.failUnless((activity in response.context["user_items"]) or (activity in response.context["completed_items"]))
      
  def testAddActivity(self):
    """Test that we can add an activity."""
    activity = Activity.objects.exclude(
      activitymember__user=self.user,
    )[0]
    response = self.client.post('/activities/add_activity/%d/' % activity.pk, {}, "multipart/form-data", True)
    self.assertRedirects(response, "/profiles/profile/%d/" % self.user.pk)
    self.failUnless(activity in response.context["user_activities"])
    response = self.client.get('/activities/activity_list/')
    self.failUnless(activity in response.context["user_items"])
    
  def testApprovedActivity(self):
    """Test that approved activities appear in the correct location."""
    activity = Activity.objects.exclude(
      activitymember__user=self.user,
    )[0]
    member = ActivityMember(user=self.user, activity=activity, approval_status="approved")
    member.save()
    response = self.client.get('/activities/activity_list/')
    self.failUnless(activity in response.context["completed_items"])
    
class CommitmentsUnitTestCase(TestCase):
  fixtures = ["base_data.json", "user_data.json"]
  
  def testCompletionAddsPoints(self):
    """Tests that completing a task adds points."""
    user = User.objects.all()[0]
{'fraction_non_alphanumeric': 0.1149654061226424, 'fraction_numerical': 0.003032887877926263, 'mean_word_length': 4.213438735177865, 'pattern_counts': {'":': 6, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3066172', 'n_tokens_mistral': 3115, 'n_tokens_neox': 3078, 'n_words': 591}