Exemple #1
0
    def test_version_api(self):
        okversion = Version(name="ok",
                            current_version="v1.5.0",
                            download_link="http://localhost/ok")
        db.session.add(okversion)
        ok2version = Version(name="ok2",
                             current_version="v2.5.0",
                             download_link="http://localhost/ok2")
        db.session.add(ok2version)

        response = self.client.get('/api/v3/version/')
        self.assert_200(response)
        assert response.json['data'] == {
            'results': [{
                "current_version": "v1.5.0",
                "download_link": "http://localhost/ok",
                "name": "ok"
            }, {
                "current_version": "v2.5.0",
                "download_link": "http://localhost/ok2",
                "name": "ok2"
            }]
        }
        assert response.json['message'] == 'success'

        response = self.client.get('/api/v3/version/ok')
        self.assert_200(response)
        assert response.json['data'] == {
            'results': [{
                "current_version": "v1.5.0",
                "download_link": "http://localhost/ok",
                "name": "ok"
            }]
        }
Exemple #2
0
    def test_version_form(self):
        old = Version(name="ok-client",
                      current_version="v1.5.0",
                      download_link="http://localhost/ok-client")
        db.session.add(old)
        db.session.commit()

        self.login(self.admin.email)

        data = {
            "current_version":
            "v1.6.0",
            "download_link":
            "https://github.com/Cal-CS-61A-Staff/ok-client/releases/download/v1.5.4/ok"
        }

        response = self.client.post('/admin/versions/ok-client',
                                    data=data,
                                    follow_redirects=True)

        assert response.status_code == 200

        new = Version.query.filter_by(name="ok-client").one()
        assert new.current_version == data['current_version']
        assert new.download_link == data['download_link']
Exemple #3
0
    def setUp(self):
        super().setUp()
        self.admin = User(email="*****@*****.**", is_admin=True)
        db.session.add(self.admin)
        db.session.commit()

        old = Version(name="ok-client", current_version="v1.5.0",
            download_link="http://localhost/ok-client")
        db.session.add(old)
        db.session.commit()
Exemple #4
0
def setup_default():
    admin = User(email="*****@*****.**", is_admin=True)
    db.session.add(admin)
    admin = User(email="*****@*****.**", is_admin=True)
    db.session.add(admin)
    db.session.commit()
    course = Course(offering='cal/cs61a/sp16',
                    institution='UC Berkeley',
                    display_name='CS 61A',
                    active=True)
    db.session.add(course)

    url = 'https://github.com/Cal-CS-61A-Staff/ok-client/releases/download/v1.5.5/ok'
    ok = Version(name='ok-client', current_version='v1.5.4', download_link=url)
    db.session.add(ok)
    db.session.commit()
Exemple #5
0
def client_version(name):
    courses, current_course = get_courses()

    version = Version.query.filter_by(name=name).one_or_none()
    if not version:
        version = Version(name=name)
    form = forms.VersionForm(obj=version)
    if form.validate_on_submit():
        form.populate_obj(version)

        db.session.add(version)
        db.session.commit()

        cache.delete_memoized(Version.get_current_version, name)
        cache.delete_memoized(ok_api.Version.get)

        flash(name + " version updated successfully.", "success")
        return redirect(url_for(".client_version", name=name))

    return render_template('staff/client_version.html',
                           courses=courses, current_course=current_course,
                           version=version, form=form)
Exemple #6
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()
Exemple #7
0
def seed_versions():
    print('Seeding version...')
    url = 'https://github.com/okpy/ok-client0/releases/download/v1.5.5/ok'
    ok = Version(name='ok-client', current_version='v1.5.5', download_link=url)
    db.session.add(ok)
Exemple #8
0
    def _test_backup(self, submit, delay=10, success=True):
        self.setup_course()

        email = self.user1.email
        self.login(email)
        user = User.lookup(email)

        course = self.course
        assignment = self.assignment
        # Offset the due date & lock_dates
        assignment.due_date = assignment.due_date + dt.timedelta(hours=delay)
        assignment.lock_date = assignment.lock_date + dt.timedelta(days=delay)

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

        data = {
            'assignment': assignment.name,
            'messages': {
                'file_contents': {
                    'hog.py': 'print("Hello world!")'
                }
            },
            'submit': submit,
        }

        response = self.client.post('/api/v3/backups/?client_version=v1.4.0',
                                    data=json.dumps(data),
                                    headers=[('Content-Type',
                                              'application/json')])
        self.assert_403(response)
        assert response.json['data'] == {
            'supplied': 'v1.4.0',
            'correct': 'v1.5.0',
            'download_link': "http://localhost/ok"
        }
        assert 'Incorrect client version' in response.json['message']
        backup = Backup.query.filter(Backup.submitter_id == user.id).all()
        assert backup == []

        response = self.client.post('/api/v3/backups/?client_version=v1.5.0',
                                    data=json.dumps(data),
                                    headers=[('Content-Type',
                                              'application/json')])
        backup = Backup.query.filter(Backup.submitter_id == user.id).first()
        assert backup is not None

        if success or not submit:
            assert response.json['data'] == {
                'email': email,
                'key': encode_id(backup.id),
                'course': {
                    'id': course.id,
                    'offering': course.offering,
                    'display_name': course.display_name,
                    'active': course.active,
                    'timezone': 'America/Los_Angeles'
                },
                'assignment': assignment.name
            }
            self.assert_200(response)

        if not success:
            self.assert_403(response)
            submit = False
            assert response.json['data'] == {
                'data': {
                    'backup': True,
                    'late': True
                }
            }

        assert backup.assignment == assignment
        assert backup.submitter_id == user.id
        assert len(backup.messages) == len(data['messages'])
        assert backup.submit == submit
Exemple #9
0
    def test_version_api(self):
        okversion = Version(name="ok",
                            current_version="v1.5.0",
                            download_link="http://localhost/ok")
        db.session.add(okversion)
        ok2version = Version(name="ok2",
                             current_version="v2.5.0",
                             download_link="http://localhost/ok2")
        db.session.add(ok2version)

        response = self.client.get('/api/v3/version/')
        self.assert_200(response)
        assert response.json['data'] == {
            'results': [{
                "current_version": "v1.5.0",
                "download_link": "http://localhost/ok",
                "name": "ok"
            }, {
                "current_version": "v2.5.0",
                "download_link": "http://localhost/ok2",
                "name": "ok2"
            }]
        }
        assert response.json['message'] == 'success'

        response = self.client.get('/api/v3/version/ok')
        self.assert_200(response)
        assert response.json['data'] == {
            'results': [{
                "current_version": "v1.5.0",
                "download_link": "http://localhost/ok",
                "name": "ok"
            }]
        }

        self.setup_course()
        self.login(self.user1.email)
        response = self.client.post('/api/v3/version/ok',
                                    data={
                                        'current_version':
                                        'v1.5.1',
                                        'download_link':
                                        'http://localhost/versions/v1.5.1/ok',
                                    })
        self.assert_403(response)

        self.login(self.staff1.email)
        response = self.client.post('/api/v3/version/ok',
                                    data={
                                        'current_version':
                                        'v1.5.1',
                                        'download_link':
                                        'http://localhost/versions/v1.5.1/ok',
                                    })
        # Staff members do not have permission to edit versions
        self.assert_403(response)

        self.login(self.admin.email)

        response = self.client.post('/api/v3/version/ok',
                                    data={
                                        'current_version':
                                        'v1.5.1',
                                        'download_link':
                                        'http://example.com/doesnotexist',
                                    })
        self.assert_400(response)

        response = self.client.post('/api/v3/version/ok',
                                    data={
                                        'current_version': 'v1.5.1',
                                        'download_link': 'http://example.com',
                                    })
        self.assert_200(response)
        response = self.client.get('/api/v3/version/')
        assert response.json['data'] == {
            'results': [{
                "current_version": "v1.5.1",
                "download_link": "http://example.com",
                "name": "ok"
            }, {
                "current_version": "v2.5.0",
                "download_link": "http://localhost/ok2",
                "name": "ok2"
            }]
        }

        response = self.client.get('/api/v3/version/ok')
        self.assert_200(response)
        assert response.json['data'] == {
            'results': [{
                "current_version": "v1.5.1",
                "download_link": "http://example.com",
                "name": "ok"
            }]
        }