Exemple #1
0
class TestStudentManager(unittest.TestCase):
    def setUp(self):
        self.mock_db = MockDB()
        self.mock_db.setUp()
        self.sm = utils.StudentManager(allow_no_award=True)

    def test_get(self):
        for student_id in self.mock_db.student_ids:
            self.assertIsNotNone(self.sm.get(student_id))

    def test_len(self):
        self.assertEqual(len(self.sm), self.mock_db.student_count)

    def test_get_by_index(self):
        for student in self.sm:
            self.assertIsNotNone(student)

        with self.assertRaises(IndexError):
            self.sm[self.mock_db.student_count]

    def test_attending(self):
        self.assertEqual(self.sm.attending, self.mock_db.attending_count)

    def tearDown(self):
        self.mock_db.tearDown()
Exemple #2
0
class TestGroupManager:
    def setUp(self):
        self.mock_db = MockDB()
        self.mock_db.setUp()
        self.g = utils.GroupManager()
        self.g.sm.allow_no_award = True
        self.g._attending = 52

    def test_index(self):
        for student_list in self.g[0]:
            for student in student_list:
                self.assertIsNotNone(student)

        with self.assertRaises(IndexError):
            self.g[self.mockdb.student_count]

    def test_size(self):
        self.assertEqual(self.g.size, 9)

    def test_count(self):
        self.assertEqual(self.g.count, 5)

    def test_last_size(self):
        self.assertEqual(self.g.last_size, 7)

    def tearDown(self):
        self.mock_db.tearDown()
Exemple #3
0
class TestAttendance(unittest.TestCase):
    def setUp(self):
        self.app = create_app()
        self.md = MockDB()
        self.md.setUp()
        self.sm = utils.StudentManager()

    def test_url(self):
        with self.app.test_client() as c:
            with c.session_transaction() as sess:
                sess['logged_in'] = True

            response = c.get('/attendance', follow_redirects=True)
        self.assertEqual(response.status_code, 200)

    def test_student_search(self):
        with self.app.test_client() as c:
            with c.session_transaction() as sess:
                sess['logged_in'] = True

            for student in self.sm:
                rv = c.get('/attendance?studentID={}'.format(student.student_id), follow_redirects=True)
                if student.preferred_name is not None:
                    fname = student.preferred_name
                else:
                    fname = student.first_name

                self.assertTrue(bytes('{} {}'.format(fname, student.last_name), 'utf-8') in rv.data)

    def tearDown(self):
        self.md.tearDown()
Exemple #4
0
class TestMain(unittest.TestCase):
    def setUp(self):
        self.app = create_app()
        self.md = MockDB()
        self.md.setUp()

    def test_main(self):
        with self.app.test_client() as c:
            with c.session_transaction() as sess:
                sess['logged_in'] = True

            for year_level in self.app.config['YEAR_LEVELS']:
                response = c.get('/main/{}/0/0'.format(str(year_level)), follow_redirects=True)
                self.assertEqual(response.status_code, 200)

            invalid_year = self.app.config['YEAR_LEVELS'][0] - 1
            response = c.get('/main/{}/0/0'.format(str(invalid_year)), follow_redirects=True)
            self.assertEqual(response.status_code, 404)

    def tearDown(self):
        self.md.tearDown()
Exemple #5
0
class TestLogin(unittest.TestCase):
    def setUp(self):
        self.app = create_app()
        self.client = self.app.test_client()
        self.md = MockDB()
        self.md.setUp()

    def test_login(self):
        rv = self.client.post('/login/', data=dict(
                              username=self.app.config['USERNAME'],
                              password=self.app.config['PASSWORD']
                              ), follow_redirects=True)
        self.assertNotIn(b'Incorrect username or password.', rv.data)

    def test_failed_login(self):
        rv = self.client.post('/login/', data=dict(
                              username=self.app.config['USERNAME'] + 'x',
                              password=self.app.config['PASSWORD']
                              ), follow_redirects=True)
        self.assertIn(b'Incorrect username or password.', rv.data)

        rv = self.client.post('/login/', data=dict(
                              username=self.app.config['USERNAME'],
                              password=self.app.config['PASSWORD'] + 'x'
                              ), follow_redirects=True)
        self.assertIn(b'Incorrect username or password.', rv.data)

    def test_logout(self):
        self.client.post('/login/', data=dict(
                         username=self.app.config['USERNAME'],
                         password=self.app.config['PASSWORD']
                         ), follow_redirects=True)

        rv = self.client.get('/logout/', follow_redirects=True)
        self.assertIn(b'Logged out.', rv.data)

    def tearDown(self):
        self.md.tearDown()
Exemple #6
0
 def setUp(self):
     self.mock_db = MockDB()
     self.mock_db.setUp()
     self.sm = utils.StudentManager(allow_no_award=True)
Exemple #7
0
 def setUp(self):
     self.mock_db = MockDB()
     self.mock_db.setUp()
     self.g = utils.GroupManager()
     self.g.sm.allow_no_award = True
     self.g._attending = 52
Exemple #8
0
class TestStudentManagerYearRestrictions(TestStudentManager):
    def setUp(self):
        self.mock_db = MockDB([7])
        self.mock_db.setUp()
        self.sm = utils.StudentManager([7], allow_no_award=True)
import json

from flask import Flask, request, redirect
from flask_restful import Resource, Api

from mockdb import MockDB

app = Flask(__name__, static_url_path='', static_folder='../')


@app.route('/')
def index():
    return redirect('/index.html')


db = MockDB('db.json')


class DataTimeSpans(Resource):
    def get(self):
        print("GET:", request.args)
        from_date = request.args.get('from', None)
        to_date = request.args.get('to', None)
        return db.get(from_date, to_date)

    def put(self):
        json_data = request.get_json(force=True)
        print("PUT:", json_data)
        db.update(json_data)
        return db.get()
import json

from flask import Flask, request, redirect
from flask_restful import Resource, Api

from mockdb import MockDB

app = Flask(__name__, static_url_path='', static_folder='../')


@app.route('/')
def index():
    return redirect('/index.html')


db = MockDB('db.json')


class DataTimeSpans(Resource):
    def get(self):
        print("GET:", request.args)
        from_date = request.args.get('from', None)
        to_date = request.args.get('to', None)
        return db.get(from_date, to_date)

    def put(self):
        json_data = request.get_json(force=True)
        print("PUT:", json_data)
        db.update(json_data)
        return db.get()
Exemple #11
0
 def setUp(self):
     self.app = create_app()
     self.md = MockDB()
     self.md.setUp()
     self.sm = utils.StudentManager()
Exemple #12
0
 def setUp(self):
     self.app = create_app()
     self.client = self.app.test_client()
     self.md = MockDB()
     self.md.setUp()
Exemple #13
0
 def setUp(self):
     self.app = create_app()
     self.md = MockDB()
     self.md.setUp()