Exemple #1
0
    def test_refresh(self):
        student = StudentFactory(email='*****@*****.**',
                                 read_access_until=(datetime.now() -
                                                    timedelta(days=1)))
        student.permissions_list = [
            Permission.ReadEvaluations, Permission.WriteEvaluations,
            Permission.VoteOnEvaluations
        ]

        db.session.flush()

        old_jwt = create_access_token(identity=student.to_dict())

        rv = self.client.get('/auth/refresh',
                             headers={'Authorization': 'Bearer ' + old_jwt})
        self.assertEqual(200, rv.status_code)

        data = json.loads(rv.data)

        new_identity = jwt.get_unverified_claims(data['jwt'])['sub']

        self.assertEqual(None, student.read_access_until)
        self.assertNotIn(Permission.ReadEvaluations, student.permissions_list)
        self.assertNotIn(Permission.VoteOnEvaluations,
                         student.permissions_list)
        self.assertEqual([Permission.WriteEvaluations],
                         new_identity['permissions'])
Exemple #2
0
    def test_existing_user_incomplete(self, data, decode_func):
        student = StudentFactory(email='*****@*****.**')
        student.permissions_list = [Permission.Incomplete]

        rv = self.client.post('/auth',
                              headers={'Content-Type': 'application/json'},
                              data=json.dumps({'id_token': data['id_token']}))
        self.assertEqual(200, rv.status_code)
Exemple #3
0
    def test_existing_user_read_access_expired(self, data, decode_func):
        student = StudentFactory(email='*****@*****.**',
                                 read_access_until=(datetime.now() -
                                                    timedelta(days=1)))
        student.permissions_list = [
            Permission.ReadEvaluations, Permission.WriteEvaluations,
            Permission.VoteOnEvaluations
        ]

        rv = self.client.post('/auth',
                              headers={'Content-Type': 'application/json'},
                              data=json.dumps({'id_token': data['id_token']}))
        self.assertEqual(200, rv.status_code)

        data = json.loads(rv.data)
        self.assertEqual('ok', data['status'])

        self.assertEqual(None, student.read_access_until)
        self.assertNotIn(Permission.ReadEvaluations, student.permissions_list)
        self.assertNotIn(Permission.VoteOnEvaluations,
                         student.permissions_list)