Beispiel #1
0
    def test_remove_not_in_group(self):
        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)

        self.assertRaises(BadRequest, group.remove, self.user2, self.user3)
        self.assertRaises(BadRequest, group.remove, self.user3, self.user2)
Beispiel #2
0
    def setUp(self):
        """ Add submissions for 3 users. """
        super(TestRevision, self).setUp()
        self.setup_course()

        message_dict = {'file_contents': {'backup.py': '1'}, 'analytics': {}}

        self.active_user_ids = [self.user1.id, self.user2.id, self.user3.id]

        self.assignment.revisions_allowed = True

        time = self.assignment.due_date # Set to dt.now(), so future subms are late
        for user_id in self.active_user_ids:
            time -= datetime.timedelta(minutes=15)
            backup = Backup(submitter_id=user_id,
                            assignment=self.assignment, submit=True)
            # Revisions are submitted on time.
            backup.created = time
            messages = [Message(kind=k, backup=backup,
                                contents=m) for k, m in message_dict.items()]
            db.session.add_all(messages)
            db.session.add(backup)

        # Put user 3 in a group with user 4
        Group.invite(self.user3, self.user4, self.assignment)
        group = Group.lookup(self.user3, self.assignment)
        group.accept(self.user4)

        okversion = Version(name="ok-client", current_version="v1.5.0",
            download_link="http://localhost/ok")
        db.session.add(okversion)

        db.session.commit()
Beispiel #3
0
    def test_remove_degenerate(self):
        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.remove(self.user1, self.user1)

        assert Group.lookup(self.user1, self.assignment) is None
        assert Group.lookup(self.user2, self.assignment) is None
Beispiel #4
0
    def test_remove_degenerate(self):
        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.remove(self.user1, self.user1)

        assert Group.lookup(self.user1, self.assignment) is None
        assert Group.lookup(self.user2, self.assignment) is None
Beispiel #5
0
    def test_decline_degenerate(self):
        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.decline(self.user2)

        assert Group.lookup(self.user1, self.assignment) is None
        assert Group.lookup(self.user2, self.assignment) is None
Beispiel #6
0
    def test_decline_degenerate(self):
        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.decline(self.user2)

        assert Group.lookup(self.user1, self.assignment) is None
        assert Group.lookup(self.user2, self.assignment) is None
Beispiel #7
0
    def test_remove_not_in_group(self):
        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)

        self.assertRaises(BadRequest, group.remove, self.user2, self.user3)
        self.assertRaises(BadRequest, group.remove, self.user3, self.user2)
Beispiel #8
0
    def test_accept_not_pending(self):
        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)

        self.assertRaises(BadRequest, group.accept, self.user2)
        self.assertRaises(BadRequest, group.accept, self.user3)
Beispiel #9
0
    def test_accept_not_pending(self):
        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)

        self.assertRaises(BadRequest, group.accept, self.user2)
        self.assertRaises(BadRequest, group.accept, self.user3)
Beispiel #10
0
    def setUp(self):
        super(TestGrading, self).setUp()
        self.setup_course()

        message_dict = {'file_contents': {'backup.py': '1'}, 'analytics': {}}

        self.active_user_ids = [self.user1.id, self.user2.id, self.user3.id]
        self.active_staff = [self.staff1, self.staff2]
        self.active_assignments = [self.assignment, self.assignment2]

        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)

        # Creates 5 submissions for each assignment per user, each spaced two minutes apart

        for assign in self.active_assignments:
            time = assign.due_date - datetime.timedelta(minutes=30)
            for num in range(5):
                for user_id in self.active_user_ids:
                    num += 1
                    time += datetime.timedelta(minutes=2)
                    backup = Backup(submitter_id=user_id,
                        assignment=assign, submit=True)
                    messages = [Message(kind=k, backup=backup,
                        contents=m) for k, m in message_dict.items()]
                    backup.created = time
                    db.session.add_all(messages)
                    db.session.add(backup)
                    # Debugging print if tests fails
                    # print("User {} | Assignment {} | Submission {} | Time {}".format(
                    #     user_id, assign.id, num, time))
        db.session.commit()
Beispiel #11
0
    def setUp(self):
        super(TestGrading, self).setUp()
        self.setup_course()

        message_dict = {'file_contents': {'backup.py': '1'}, 'analytics': {}}

        self.active_user_ids = [self.user1.id, self.user2.id, self.user3.id]
        self.active_staff = [self.staff1, self.staff2]
        self.active_assignments = [self.assignment, self.assignment2]

        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)

        # Creates 5 submissions for each assignment per user, each spaced two minutes apart

        for assign in self.active_assignments:
            time = assign.due_date - datetime.timedelta(minutes=30)
            for num in range(5):
                for user_id in self.active_user_ids:
                    num += 1
                    time += datetime.timedelta(minutes=2)
                    backup = Backup(submitter_id=user_id,
                        assignment=assign, submit=True)
                    messages = [Message(kind=k, backup=backup,
                        contents=m) for k, m in message_dict.items()]
                    backup.created = time
                    db.session.add_all(messages)
                    db.session.add(backup)
                    # Debugging print if tests fails
                    # print("User {} | Assignment {} | Submission {} | Time {}".format(
                    #     user_id, assign.id, num, time))
        db.session.commit()
Beispiel #12
0
    def test_accept(self):
        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)

        assert group.has_status(self.user1, 'active')
        assert group.has_status(self.user2, 'active')
        assert group.size() == 2
Beispiel #13
0
    def test_accept(self):
        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)

        assert group.has_status(self.user1, 'active')
        assert group.has_status(self.user2, 'active')
        assert group.size() == 2
Beispiel #14
0
    def test_remove_self(self):
        Group.invite(self.user1, self.user2, self.assignment)
        Group.invite(self.user1, self.user3, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)
        group.accept(self.user3)
        group.remove(self.user1, self.user1)

        assert Group.lookup(self.user1, self.assignment) is None
        assert group.has_status(self.user2, 'active')
        assert group.has_status(self.user3, 'active')
Beispiel #15
0
    def test_decline(self):
        Group.invite(self.user1, self.user2, self.assignment)
        Group.invite(self.user1, self.user3, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)
        group.decline(self.user3)

        assert group.has_status(self.user1, 'active')
        assert group.has_status(self.user2, 'active')
        assert Group.lookup(self.user3, self.assignment) is None
        assert group.size() == 2
Beispiel #16
0
    def test_accept_unflag(self):
        # when a user accepts an invitation, unflag their submissions.
        submission = self.assignment.submissions([self.user1.id]).all()[3]
        self.assignment.flag(submission.id, [self.user1.id])

        Group.invite(self.user2, self.user1, self.assignment)
        assert submission.flagged

        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user1)
        assert not submission.flagged
Beispiel #17
0
    def test_decline(self):
        Group.invite(self.user1, self.user2, self.assignment)
        Group.invite(self.user1, self.user3, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)
        group.decline(self.user3)

        assert group.has_status(self.user1, 'active')
        assert group.has_status(self.user2, 'active')
        assert Group.lookup(self.user3, self.assignment) is None
        assert group.size() == 2
Beispiel #18
0
    def test_accept_unflag(self):
        # when a user accepts an invitation, unflag their submissions.
        submission = self.assignment.submissions([self.user1.id]).all()[3]
        self.assignment.flag(submission.id, [self.user1.id])

        Group.invite(self.user2, self.user1, self.assignment)
        assert submission.flagged

        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user1)
        assert not submission.flagged
Beispiel #19
0
    def test_remove_self(self):
        Group.invite(self.user1, self.user2, self.assignment)
        Group.invite(self.user1, self.user3, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)
        group.accept(self.user3)
        group.remove(self.user1, self.user1)

        assert Group.lookup(self.user1, self.assignment) is None
        assert group.has_status(self.user2, 'active')
        assert group.has_status(self.user3, 'active')
Beispiel #20
0
    def test_active_user_ids(self):
        Group.invite(self.user1, self.user2, self.assignment)
        Group.invite(self.user1, self.user3, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)

        assert self.assignment.active_user_ids(self.user1.id) == \
            {self.user1.id, self.user2.id}
        assert self.assignment.active_user_ids(self.user2.id) == \
            {self.user1.id, self.user2.id}
        assert self.assignment.active_user_ids(self.user3.id) == \
            {self.user3.id}
Beispiel #21
0
    def test_active_user_ids(self):
        Group.invite(self.user1, self.user2, self.assignment)
        Group.invite(self.user1, self.user3, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)

        assert self.assignment.active_user_ids(self.user1.id) == \
            {self.user1.id, self.user2.id}
        assert self.assignment.active_user_ids(self.user2.id) == \
            {self.user1.id, self.user2.id}
        assert self.assignment.active_user_ids(self.user3.id) == \
            {self.user3.id}
Beispiel #22
0
    def test_group_api(self):
        self._test_backup(True)
        self.logout()

        student = User.lookup(self.user1.email)

        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)
        base_api = '/api/v3/assignment/{0}/group/{1}'
        endpoint = base_api.format(self.assignment.name, self.user1.email)

        response = self.client.get(endpoint)
        self.assert_401(response)

        self.login(self.user1.email)
        response = self.client.get(endpoint)
        self.assert_200(response)
        members = response.json['data']['members']
        self.assertEquals(len(members), 2)
        assert 'email' in members[0]['user']

        # Make sure user2 can access user1's endpoint
        self.login(self.user2.email)
        response = self.client.get(endpoint)
        self.assert_200(response)
        members = response.json['data']['members']
        self.assertEquals(len(members), 2)
        assert 'email' in members[1]['user']

        self.login(self.staff1.email)
        response = self.client.get(endpoint)

        self.assert_200(response)
        members = response.json['data']['members']
        self.assertEquals(len(members), 2)
        assert 'email' in members[0]['user']

        # Login as some random user
        self.login(self.user3.email)
        response = self.client.get(endpoint)
        self.assert_403(response)

        # Check for existence of email
        response = self.client.get(
            base_api.format(self.assignment.name, '*****@*****.**'))
        self.assert_403(response)

        self.login(self.admin.email)
        response = self.client.get(
            base_api.format(self.assignment.name, '*****@*****.**'))
        self.assert_404(response)
Beispiel #23
0
    def test_invite_in_group(self):
        Group.invite(self.user1, self.user2, self.assignment)

        self.assertRaises(BadRequest, Group.invite, self.user1, self.user1, self.assignment)
        self.assertRaises(BadRequest, Group.invite, self.user1, self.user2, self.assignment)

        self.assertRaises(BadRequest, Group.invite, self.user2, self.user1, self.assignment)
        self.assertRaises(BadRequest, Group.invite, self.user2, self.user2, self.assignment)
        self.assertRaises(BadRequest, Group.invite, self.user2, self.user3, self.assignment)

        self.assertRaises(BadRequest, Group.invite, self.user3, self.user1, self.assignment)
        self.assertRaises(BadRequest, Group.invite, self.user3, self.user2, self.assignment)
        self.assertRaises(BadRequest, Group.invite, self.user3, self.user3, self.assignment)
Beispiel #24
0
    def test_group_api(self):
        self._test_backup(True)
        self.logout()

        student = User.lookup(self.user1.email)

        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)
        base_api = '/api/v3/assignment/{0}/group/{1}'
        endpoint = base_api.format(self.assignment.name, self.user1.email)

        response = self.client.get(endpoint)
        self.assert_401(response)

        self.login(self.user1.email)
        response = self.client.get(endpoint)
        self.assert_200(response)
        members = response.json['data']['members']
        self.assertEqual(len(members), 2)
        assert 'email' in members[0]['user']

        # Make sure user2 can access user1's endpoint
        self.login(self.user2.email)
        response = self.client.get(endpoint)
        self.assert_200(response)
        members = response.json['data']['members']
        self.assertEqual(len(members), 2)
        assert 'email' in members[1]['user']


        self.login(self.staff1.email)
        response = self.client.get(endpoint)

        self.assert_200(response)
        members = response.json['data']['members']
        self.assertEqual(len(members), 2)
        assert 'email' in  members[0]['user']

        # Login as some random user
        self.login(self.user3.email)
        response = self.client.get(endpoint)
        self.assert_403(response)

        # Check for existence of email
        response = self.client.get(base_api.format(self.assignment.name, '*****@*****.**'))
        self.assert_403(response)

        self.login(self.admin.email)
        response = self.client.get(base_api.format(self.assignment.name, '*****@*****.**'))
        self.assert_404(response)
Beispiel #25
0
    def test_invite(self):
        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)

        assert group.has_status(self.user1, 'active')
        assert group.has_status(self.user2, 'pending')
        assert group.size() == 2

        Group.invite(self.user1, self.user3, self.assignment)

        assert group.has_status(self.user1, 'active')
        assert group.has_status(self.user2, 'pending')
        assert group.has_status(self.user3, 'pending')
        assert group.size() == 3
Beispiel #26
0
    def test_invite(self):
        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)

        assert group.has_status(self.user1, 'active')
        assert group.has_status(self.user2, 'pending')
        assert group.size() == 2

        Group.invite(self.user1, self.user3, self.assignment)

        assert group.has_status(self.user1, 'active')
        assert group.has_status(self.user2, 'pending')
        assert group.has_status(self.user3, 'pending')
        assert group.size() == 3
Beispiel #27
0
def group_invite(name):
    assignment = get_assignment(name)
    email = request.form['email']
    invitee = User.lookup(email)
    if not invitee:
        flash("{0} is not enrolled".format(email), 'warning')
    else:
        try:
            Group.invite(current_user, invitee, assignment)
            success = "{0} has been invited. They can accept the invite by logging into okpy.org".format(email)
            invite_email(current_user, invitee, assignment)
            flash(success, "success")
        except BadRequest as e:
            flash(e.description, 'danger')
    return redirect(url_for('.assignment', name=assignment.name))
Beispiel #28
0
    def test_group_permission(self):
        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)

        # Only the original creator and staff can accept the files
        self.assertTrue(ExternalFile.can(self.file2, self.user1, 'download'))
        self.assertTrue(ExternalFile.can(self.file2, self.staff1, 'download'))
        self.assertFalse(ExternalFile.can(self.file2, self.user2, 'download'))

        group.accept(self.user2)

        # Now all group members can access the files
        self.assertTrue(ExternalFile.can(self.file2, self.user1, 'download'))
        self.assertTrue(ExternalFile.can(self.file2, self.staff1, 'download'))
        self.assertTrue(ExternalFile.can(self.file2, self.user2, 'download'))
        self.assertFalse(ExternalFile.can(self.file2, self.user3, 'download'))
Beispiel #29
0
    def test_group_permission(self):
        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)

        # Only the original creator and staff can accept the files
        self.assertTrue(ExternalFile.can(self.file2, self.user1, 'download'))
        self.assertTrue(ExternalFile.can(self.file2, self.staff1, 'download'))
        self.assertFalse(ExternalFile.can(self.file2, self.user2, 'download'))

        group.accept(self.user2)

        # Now all group members can access the files
        self.assertTrue(ExternalFile.can(self.file2, self.user1, 'download'))
        self.assertTrue(ExternalFile.can(self.file2, self.staff1, 'download'))
        self.assertTrue(ExternalFile.can(self.file2, self.user2, 'download'))
        self.assertFalse(ExternalFile.can(self.file2, self.user3, 'download'))
Beispiel #30
0
    def test_extension_group(self):
        self.set_offset(1) # Allow assignment to be active
        Group.invite(self.user1, self.user2, self.assignment)
        Group.invite(self.user1, self.user3, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)
        self.set_offset(-1) # Lock assignment

        ext = self._make_ext(self.assignment, self.user1)
        self.assertEquals(ext, Extension.get_extension(self.user1, self.assignment))
        self.assertEquals(ext, Extension.get_extension(self.user2, self.assignment))
        # User 3 has not accepted yet so does not get an extension
        self.assertFalse(Extension.get_extension(self.user3, self.assignment))

        # If user 2 leaves, they no longer have access to the extension
        group.remove(self.user1, self.user2)
        self.assertFalse(Extension.get_extension(self.user2, self.assignment))
Beispiel #31
0
    def test_extension_group(self):
        self.set_offset(1) # Allow assignment to be active
        Group.invite(self.user1, self.user2, self.assignment)
        Group.invite(self.user1, self.user3, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)
        self.set_offset(-2) # Lock assignment

        ext = self._make_ext(self.assignment, self.user1)
        self.assertEqual(ext, Extension.get_extension(self.user1, self.assignment))
        self.assertEqual(ext, Extension.get_extension(self.user2, self.assignment))
        # User 3 has not accepted yet so does not get an extension
        self.assertFalse(Extension.get_extension(self.user3, self.assignment))

        # If user 2 leaves, they no longer have access to the extension
        self.set_offset(1) # Allow assignment to be active to remove the user.
        group.remove(self.user1, self.user2)
        self.assertFalse(Extension.get_extension(self.user2, self.assignment))
Beispiel #32
0
    def test_backup_owners(self):
        backup = Backup(submitter_id=self.user1.id,
                        assignment=self.assignment,
                        submit=True)
        backup2 = Backup(submitter_id=self.user2.id,
                         assignment=self.assignment,
                         submit=True)
        db.session.add(backup)
        db.session.add(backup2)
        db.session.commit()
        assert backup2.owners() == {self.user2.id}

        Group.invite(self.user1, self.user2, self.assignment)
        Group.invite(self.user1, self.user3, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)

        assert backup.owners() == {self.user1.id, self.user2.id}
        assert backup2.owners() == {self.user1.id, self.user2.id}
Beispiel #33
0
    def test_invite_in_group(self):
        Group.invite(self.user1, self.user2, self.assignment)

        self.assertRaises(BadRequest, Group.invite, self.user1, self.user1,
                          self.assignment)
        self.assertRaises(BadRequest, Group.invite, self.user1, self.user2,
                          self.assignment)

        self.assertRaises(BadRequest, Group.invite, self.user2, self.user1,
                          self.assignment)
        self.assertRaises(BadRequest, Group.invite, self.user2, self.user2,
                          self.assignment)
        self.assertRaises(BadRequest, Group.invite, self.user2, self.user3,
                          self.assignment)

        self.assertRaises(BadRequest, Group.invite, self.user3, self.user1,
                          self.assignment)
        self.assertRaises(BadRequest, Group.invite, self.user3, self.user2,
                          self.assignment)
        self.assertRaises(BadRequest, Group.invite, self.user3, self.user3,
                          self.assignment)
Beispiel #34
0
    def test_backup_owners(self):
        backup = Backup(
            submitter_id=self.user1.id,
            assignment=self.assignment,
            submit=True)
        backup2 = Backup(
            submitter_id=self.user2.id,
            assignment=self.assignment,
            submit=True)
        db.session.add(backup)
        db.session.add(backup2)
        db.session.commit()
        assert backup2.owners() == {self.user2.id}

        Group.invite(self.user1, self.user2, self.assignment)
        Group.invite(self.user1, self.user3, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)

        assert backup.owners() == {self.user1.id, self.user2.id}
        assert backup2.owners() == {self.user1.id, self.user2.id}
Beispiel #35
0
    def test_invite_full(self):
        Group.invite(self.user1, self.user2, self.assignment)
        Group.invite(self.user1, self.user3, self.assignment)
        Group.invite(self.user1, self.user4, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)

        assert group.size() == 4
        self.assertRaises(BadRequest, Group.invite, self.user1, self.user5, self.assignment)
Beispiel #36
0
    def setUp(self):
        """ Add submissions for 3 users. """
        super(TestRevision, self).setUp()
        self.setup_course()

        message_dict = {'file_contents': {'backup.py': '1'}, 'analytics': {}}

        self.active_user_ids = [self.user1.id, self.user2.id, self.user3.id]

        self.assignment.revisions_allowed = True

        time = self.assignment.due_date  # Set to dt.now(), so future subms are late
        for user_id in self.active_user_ids:
            time -= datetime.timedelta(minutes=15)
            backup = Backup(submitter_id=user_id,
                            assignment=self.assignment,
                            submit=True)
            # Revisions are submitted on time.
            backup.created = time
            messages = [
                Message(kind=k, backup=backup, contents=m)
                for k, m in message_dict.items()
            ]
            db.session.add_all(messages)
            db.session.add(backup)

        # Put user 3 in a group with user 4
        Group.invite(self.user3, self.user4, self.assignment)
        group = Group.lookup(self.user3, self.assignment)
        group.accept(self.user4)

        okversion = Version(name="ok-client",
                            current_version="v1.5.0",
                            download_link="http://localhost/ok")
        db.session.add(okversion)

        db.session.commit()
Beispiel #37
0
    def test_invite_full(self):
        Group.invite(self.user1, self.user2, self.assignment)
        Group.invite(self.user1, self.user3, self.assignment)
        Group.invite(self.user1, self.user4, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)

        assert group.size() == 4
        self.assertRaises(BadRequest, Group.invite, self.user1, self.user5,
                          self.assignment)
Beispiel #38
0
    def test_locked(self):
        Group.invite(self.user1, self.user2, self.assignment)
        Group.invite(self.user1, self.user3, self.assignment)
        Group.invite(self.user1, self.user4, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)

        self.assignment.lock_date = datetime.datetime.now() - datetime.timedelta(days=1)
        db.session.commit()

        self.assertRaises(BadRequest, Group.invite, self.user1, self.user2, self.assignment)
        self.assertRaises(BadRequest, group.accept, self.user3)
        self.assertRaises(BadRequest, group.decline, self.user3)
        self.assertRaises(BadRequest, group.remove, self.user1, self.user2)
Beispiel #39
0
    def test_locked(self):
        Group.invite(self.user1, self.user2, self.assignment)
        Group.invite(self.user1, self.user3, self.assignment)
        Group.invite(self.user1, self.user4, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)

        self.assignment.lock_date = datetime.datetime.now(
        ) - datetime.timedelta(days=1)
        db.session.commit()

        self.assertRaises(BadRequest, Group.invite, self.user1, self.user2,
                          self.assignment)
        self.assertRaises(BadRequest, group.accept, self.user3)
        self.assertRaises(BadRequest, group.decline, self.user3)
        self.assertRaises(BadRequest, group.remove, self.user1, self.user2)
Beispiel #40
0
    def test_remove(self):
        Group.invite(self.user1, self.user2, self.assignment)
        Group.invite(self.user1, self.user3, self.assignment)
        Group.invite(self.user1, self.user4, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)

        group.remove(self.user1, self.user2)
        assert group.has_status(self.user1, 'active')
        assert Group.lookup(self.user2, self.assignment) is None
        assert group.has_status(self.user3, 'pending')
        assert group.size() == 3

        group.remove(self.user1, self.user3)
        assert group.has_status(self.user1, 'active')
        assert Group.lookup(self.user3, self.assignment) is None
        assert group.size() == 2
Beispiel #41
0
    def test_remove(self):
        Group.invite(self.user1, self.user2, self.assignment)
        Group.invite(self.user1, self.user3, self.assignment)
        Group.invite(self.user1, self.user4, self.assignment)
        group = Group.lookup(self.user1, self.assignment)
        group.accept(self.user2)

        group.remove(self.user1, self.user2)
        assert group.has_status(self.user1, 'active')
        assert Group.lookup(self.user2, self.assignment) is None
        assert group.has_status(self.user3, 'pending')
        assert group.size() == 3

        group.remove(self.user1, self.user3)
        assert group.has_status(self.user1, 'active')
        assert Group.lookup(self.user3, self.assignment) is None
        assert group.size() == 2
Beispiel #42
0
def gen_invite(member, invitee, assignment, accept=False):
    Group.invite(member, invitee, assignment)
    group = Group.lookup(invitee, assignment)
    if accept:
        group.accept(invitee)
    return group
Beispiel #43
0
def gen_invite(member, invitee, assignment, accept=False):
    Group.invite(member, invitee, assignment)
    group = Group.lookup(invitee, assignment)
    if accept:
        group.accept(invitee)
    return group
Beispiel #44
0
    def test_log(self):
        def latest_action():
            return GroupAction.query.order_by(GroupAction.id.desc()).first()

        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)

        state = {
            'id': group.id,
            'assignment_id': group.assignment_id,
            'members': []
        }

        action = latest_action()
        assert action.action_type == 'invite'
        assert action.user_id == self.user1.id
        assert action.target_id == self.user2.id
        assert action.group_before == state
        state['members'].append({'user_id': self.user1.id, 'status': 'active'})
        state['members'].append({
            'user_id': self.user2.id,
            'status': 'pending'
        })
        assert action.group_after == state

        group.accept(self.user2)

        action = latest_action()
        assert action.action_type == 'accept'
        assert action.user_id == self.user2.id
        assert action.target_id == self.user2.id
        assert action.group_before == state
        state['members'][1]['status'] = 'active'
        assert action.group_after == state

        Group.invite(self.user1, self.user3, self.assignment)

        action = latest_action()
        assert action.action_type == 'invite'
        assert action.user_id == self.user1.id
        assert action.target_id == self.user3.id
        assert action.group_before == state
        state['members'].append({
            'user_id': self.user3.id,
            'status': 'pending'
        })
        assert action.group_after == state

        group.decline(self.user3)

        action = latest_action()
        assert action.action_type == 'decline'
        assert action.user_id == self.user3.id
        assert action.target_id == self.user3.id
        assert action.group_before == state
        state['members'].pop(2)
        assert action.group_after == state

        group.remove(self.user2, self.user1)
        action = latest_action()
        assert action.action_type == 'remove'
        assert action.user_id == self.user2.id
        assert action.target_id == self.user1.id
        assert action.group_before == state
        state['members'] = []
        assert action.group_after == state
Beispiel #45
0
    def test_decline_not_pending(self):
        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)

        self.assertRaises(BadRequest, group.decline, self.user3)
Beispiel #46
0
    def test_log(self):
        def latest_action():
            return GroupAction.query.order_by(GroupAction.id.desc()).first()

        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)

        state = {
            'id': group.id,
            'assignment_id': group.assignment_id,
            'members': []
        }

        action = latest_action()
        assert action.action_type == 'invite'
        assert action.user_id == self.user1.id
        assert action.target_id == self.user2.id
        assert action.group_before == state
        state['members'].append({
            'user_id': self.user1.id,
            'status': 'active'
        })
        state['members'].append({
            'user_id': self.user2.id,
            'status': 'pending'
        })
        assert action.group_after == state

        group.accept(self.user2)

        action = latest_action()
        assert action.action_type == 'accept'
        assert action.user_id == self.user2.id
        assert action.target_id == self.user2.id
        assert action.group_before == state
        state['members'][1]['status'] = 'active'
        assert action.group_after == state

        Group.invite(self.user1, self.user3, self.assignment)

        action = latest_action()
        assert action.action_type == 'invite'
        assert action.user_id == self.user1.id
        assert action.target_id == self.user3.id
        assert action.group_before == state
        state['members'].append({
            'user_id': self.user3.id,
            'status': 'pending'
        })
        assert action.group_after == state

        group.decline(self.user3)

        action = latest_action()
        assert action.action_type == 'decline'
        assert action.user_id == self.user3.id
        assert action.target_id == self.user3.id
        assert action.group_before == state
        state['members'].pop(2)
        assert action.group_after == state

        group.remove(self.user2, self.user1)
        action = latest_action()
        assert action.action_type == 'remove'
        assert action.user_id == self.user2.id
        assert action.target_id == self.user1.id
        assert action.group_before == state
        state['members'] = []
        assert action.group_after == state
Beispiel #47
0
    def test_decline_not_pending(self):
        Group.invite(self.user1, self.user2, self.assignment)
        group = Group.lookup(self.user1, self.assignment)

        self.assertRaises(BadRequest, group.decline, self.user3)