def test_leave_group_student_not_in_group(self): # Make a study group study_group = StudyGroup(name="banana", maxSize=4) study_group.save() # Add Student to group study_group.members.add(self.student1) study_group.save() # Obtain Group ID to pass as a parameter to the request group = StudyGroup.objects.get(name="banana") id = group.id # Make request and call leaveGroup request = self.request_factory.post(reverse('studygroups:leaveGroup'), { 'Group': [str(id)], 'edit': [''] }) request.user = self.user leaveGroup(request) actual = study_group.get_members() expected = [self.student1] self.assertEqual(expected, actual)
def test_new_study_group_email(self): facilitator = create_user('*****@*****.**', 'facil', 'itate', 'password') mail.outbox = [] sg = StudyGroup(course=Course.objects.first(), facilitator=facilitator, description='blah', venue_name='ACME publich library', venue_address='ACME rd 1', venue_details='venue_details', city='city', latitude=0, longitude=0, start_date=datetime.date(2010, 1, 1), end_date=datetime.date(2010, 1, 1) + datetime.timedelta(weeks=6), meeting_time=datetime.time(12, 0), duration=90, timezone='SAST', facilitator_goal='the_facilitator_goal', facilitator_concerns='the_facilitators_concerns') sg.save() self.assertEqual(len(mail.outbox), 1) self.assertIn('the_facilitator_goal', mail.outbox[0].body) self.assertIn('the_facilitators_concerns', mail.outbox[0].body)
def test_leave_group_student_yes_delete(self): # Make a study group study_group = StudyGroup(name="banana", maxSize=4) study_group.save() # Add Student to group #self.student.group_id = "64042306" study_group.members.add(self.student) study_group.save() # Obtain Group ID to pass as a parameter to the request group = StudyGroup.objects.get(name="banana") id = group.id # Make request and call leaveGroup request = self.request_factory.post(reverse('studygroups:leaveGroup'), { 'Group': [str(id)], 'edit': [''] }) request.user = self.user leaveGroup(request) # Try to access group again self.assertRaises(StudyGroup.DoesNotExist, StudyGroup.objects.get, name="banana")
def test_duplicated_group_name(self): study_group = StudyGroup( name="banana", maxSize=4, ) study_group.save() # Add Students to group study_group.members.add(self.student1) study_group.save() request = self.request_factory.post( reverse('studentprofile:generateSchedule'), { 'Name': ['banana'], 'Size': ['3'], 'Class': ['CS 3240'], }) #no class entered request.user = self.user actual = len(makeGroup(request).content) expected = len( render(request, 'studygroups/groupCreate.html', { 'error_message': "Group name is taken, please try another name", }).content) self.assertEqual(expected, actual)
def post(self, request): post_schema = _make_learning_circle_schema(request) data = json.loads(request.body) data, errors = schema.validate(post_schema, data) if errors != {}: return json_response(request, { "status": "error", "errors": errors }) # create learning circle end_date = data.get('start_date') + datetime.timedelta( weeks=data.get('weeks') - 1) study_group = StudyGroup( course=data.get('course'), facilitator=request.user, description=data.get('description'), venue_name=data.get('venue_name'), venue_address=data.get('venue_address'), venue_details=data.get('venue_details'), venue_website=data.get('venue_website', ''), city=data.get('city'), region=data.get('region'), country=data.get('country'), latitude=data.get('latitude'), longitude=data.get('longitude'), place_id=data.get('place_id', ''), start_date=data.get('start_date'), end_date=end_date, meeting_time=data.get('meeting_time'), duration=data.get('duration'), timezone=data.get('timezone'), image=data.get('image'), signup_question=data.get('signup_question', ''), facilitator_goal=data.get('facilitator_goal', ''), facilitator_concerns=data.get('facilitator_concerns', '')) # only update value for draft if the use verified their email address if request.user.profile.email_confirmed_at != None: study_group.draft = data.get('draft', True) study_group.save() # generate all meetings if the learning circle has been published if study_group.draft == False: generate_all_meetings(study_group) study_group_url = settings.DOMAIN + reverse( 'studygroups_signup', args=( slugify(study_group.venue_name, allow_unicode=True), study_group.id, )) return json_response(request, { "status": "created", "url": study_group_url })
def test_get_members_empty(self): # Make a study group study_group = StudyGroup( name="banana", maxSize=4, ) study_group.save() actual = study_group.get_members() expected = [] self.assertEqual(expected, actual)
def test_get_members_not_empty(self): # Make a study group study_group = StudyGroup( name="banana", maxSize=4, ) study_group.save() # Add Student to group study_group.members.add(self.student) study_group.save() actual = study_group.get_members() expected = [self.student] self.assertEqual(expected, actual)
def test_get_available_groups_with_none_in_same_course(self): self.student.schedule = self.schedule study_group1 = StudyGroup(name="banana", maxSize=2, course=Course.objects.get(mnemonic="CS", number=2102)) study_group1.save() study_group2 = StudyGroup(name="apple", maxSize=3, course=Course.objects.get(mnemonic="CS", number=4102)) study_group2.save() expected = [] actual = self.student.get_available_groups() self.assertEqual(expected, actual)
def test_get_suggested_groups_some(self): self.student.schedule = self.schedule study_group1 = StudyGroup(name="banana", maxSize=2, course=Course.objects.get(mnemonic="CS", number=2150)) study_group1.save() study_group2 = StudyGroup(name="apple", maxSize=3, course=Course.objects.get(mnemonic="ECON", number=2010)) study_group2.save() expected = [study_group1, study_group2] actual = self.student.get_suggested_groups() self.assertEqual(expected, actual)
def test_leave_group_does_not_exist(self): # Make a study group study_group = StudyGroup(name="banana", maxSize=2) study_group.save() # Add Students to group study_group.members.add(self.student1) study_group.save() study_group.members.add(self.student2) study_group.save() # Obtain Group ID to pass as a parameter to the request group = StudyGroup.objects.get(name="banana") id = group.id # Delete the group group.delete() # Make request and call leaveGroup request = self.request_factory.post(reverse('studygroups:leaveGroup'), { 'Group': [str(id)], 'edit': [''] }) request.user = self.user # This should fail and thus yield a StudyGroup.DoesNotExist Exception self.assertRaises(StudyGroup.DoesNotExist, leaveGroup, request=request)
def test_get_available_groups_with_some_same_course(self): self.student.schedule = self.schedule study_group1 = StudyGroup(name="banana", maxSize=2, course=Course.objects.get(mnemonic="CS", number=2150)) study_group1.save() study_group2 = StudyGroup(name="apple", maxSize=3, course=Course.objects.get(mnemonic="CS", number=3330)) study_group2.save() study_group3 = StudyGroup(name="berry", maxSize=2, course=Course.objects.get(mnemonic="MATH", number=1220)) study_group3.save() study_group4 = StudyGroup(name="peach", maxSize=5, course=Course.objects.get(mnemonic="COMM", number=2020)) study_group4.save() study_group5 = StudyGroup(name="kiwi", maxSize=6, course=Course.objects.get(mnemonic="ECON", number=2010)) study_group5.save() expected = [study_group4, study_group5] actual = self.student.get_available_groups() self.assertEqual(expected, actual)
def test_get_members_string_not_empty(self): # Make a study group study_group = StudyGroup( name="banana", maxSize=4, ) study_group.save() # Add Students to group study_group.members.add(self.student1) study_group.save() study_group.members.add(self.student2) study_group.save() actual = study_group.get_members_string() expected = 'Jim, Jim2' self.assertEqual(expected, actual)
def test_get_members_email_not_empty(self): # Make a study group study_group = StudyGroup( name="banana", maxSize=4, ) study_group.save() # Add Students to group study_group.members.add(self.student1) study_group.save() study_group.members.add(self.student2) study_group.save() actual = study_group.get_members_email() expected = 'Jim ([email protected]), Jim2 ([email protected])' self.assertEqual(expected, actual)