Esempio n. 1
0
    def test_invalid_group_name(self):
        with routes.app.test_request_context():
            # Invalid group name during group creation
            try:
                database.create_new_group("Invalid Name", "low")
                self.assertTrue(0)  # Gives assertion error if the above function fails
            except SyntaxError:
                self.assertTrue(1)  # SyntaxError got raised, as wanted.

            # Invalid group name during adding member
            try:
                database.add_group_members("Invalid Name", "low")
                self.assertTrue(0)  # Gives assertion error if the above function fails
            except SyntaxError:
                self.assertTrue(1)  # SyntaxError got raised, as wanted.
Esempio n. 2
0
    def test_get_group_members(self):
        with routes.app.test_request_context():
            database.create_new_group("GroupWithMembers", "low")

            database.add_registered_user(["Linus", "Kortesalmi", "*****@*****.**",
                                          "Sweden", "Linkpping", "g_plus"])

            database.add_group_members("GroupWithMembers", [0, 1])

            # JSON Object we expect to get back
            json_test = json.loads("""{ "members": [
                {
                    "answered": "FALSE",
                    "email": "*****@*****.**",
                    "id": 1,
                    "name": "Linus Kortesalmi"
                }
            ]}""")

            rv = self.app.get('/api/v1.0/groups/GroupWithMembers')  # JSON Object we get back
            self.assertEquals(json.loads(rv.data), json_test)
Esempio n. 3
0
def new_group():
    try:
        # Check if we are logged in this session.
        if not session['logged_in']:
            abort(401)

        group_name = request.form['group_name']
        priority = request.form['priority']
        database.create_new_group(group_name, priority)
        database.add_group_members(group_name, request.form.getlist('person_id'))

        flash('Group created')
        return redirect(url_for('create_group'))

    except KeyError:
        # Visualize for the user that something went wrong.
        flash('You need to be logged in to view that page')
        return redirect(url_for('home'))

    except sqlite3.IntegrityError:
        flash('Group already exists')
        return redirect(url_for('create_group'))