예제 #1
0
    def setup_method(self, method):
        db.drop_all()
        db.create_all()

        # Create admin user for tests.
        admin = Users(id = "adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        db.session.commit()
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal user for tests.
        user = Users(id = "testuser")
        user.first_name = "Test1"
        user.last_name = "User"
        user.email = "*****@*****.**"
        user.is_admin = False
        db.session.add(user)
        db.session.commit()
        self.test_user = user
        self.user_token = user.generate_auth()
        self.user_token = self.user_token.decode('ascii')

        # Create normal user for tests.
        user2 = Users(id = "testuser2")
        user2.first_name = "Test"
        user2.last_name = "User"
        user2.email = "*****@*****.**"
        user2.is_admin = False
        db.session.add(user2)
        db.session.commit()
        self.test_user2 = user2
        self.user_token2 = user2.generate_auth()
        self.user_token2 = self.user_token2.decode('ascii')

        # Create a test committee.
        committee = Committees(id = "testcommittee")
        committee.title = "Test Committee"
        committee.description = "Test Description"
        committee.location = "Test Location"
        committee.meeting_time = "1300"
        committee.meeting_day =  2
        committee.head = "testuser"
        self.committee = committee
        db.session.add(committee)
        db.session.commit()

        committee_note = CommitteeNotes(id = 10)
        committee_note.author = "testuser"
        committee_note.description = "Test Note"
        committee_note.committee = "testcommittee"
        committee_note.hidden = False
        self.committee_note = committee_note
        db.session.add(self.committee_note)
        db.session.commit()
    def setup_method(self, method):
        db.drop_all()
        db.create_all()
        self.user_data = {
            "user_id": "testuser",
            "committee_id": "testcommittee"
        }

        # Create admin user for tests.
        admin = Users(id="adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        db.session.commit()
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal user for tests.
        user = Users(id="testuser")
        user.first_name = "Test1"
        user.last_name = "User"
        user.email = "*****@*****.**"
        user.is_admin = False
        db.session.add(user)
        db.session.commit()
        self.user_token = user.generate_auth()
        self.user_token = self.user_token.decode('ascii')
        self.user = user

        # Create second normal user for tests.
        user2 = Users(id="testuser2")
        user2.first_name = "Test2"
        user2.last_name = "User2"
        db.session.add(user2)
        db.session.commit()

        self.user_token2 = user2.generate_auth()
        self.user_token2 = self.user_token2.decode('ascii')
        self.user2 = user2

        # Create a test committee.
        self.committee = Committees(id="testcommittee")
        self.committee.title = "Test Committee"
        self.committee.description = "Test Description"
        self.committee.location = "Test Location"
        self.committee.meeting_time = "1300"
        self.committee.meeting_day = 2
        self.committee.head = "adminuser"
        db.session.add(self.committee)
        db.session.commit()

        self.invite = Invitations(id=5)
        self.invite.user_name = "newuser1"
        self.invite.committee = self.committee
        self.invite.committee_id = "testcommittee"
        self.invite.isInvite = False
예제 #3
0
def create_committee(user, user_data):

    if user is not None and user.is_admin:

        # Build committee id string.
        committee_id = user_data["title"].replace(" ", "")
        committee_id = committee_id.lower()

        if Committees.query.filter_by(id=committee_id).first() is None:

            if ("title" in user_data and "description" in user_data
                    and "location" in user_data and "meeting_time" in user_data
                    and "meeting_day" in user_data and "head" in user_data):

                new_committee = Committees(id=committee_id)
                new_committee.title = user_data["title"]
                new_committee.description = user_data["description"]
                new_committee.location = user_data["location"]
                new_committee.meeting_time = user_data["meeting_time"]
                new_committee.meeting_day = user_data["meeting_day"]

                new_committee.head = user_data["head"]
                membership = Members(role=Roles.CommitteeHead)
                membership.member = Users.query.filter_by(
                    id=user_data["head"]).first()
                new_committee.members.append(membership)

                if "committee_img" in user_data:
                    com_img = base64.b64decode(user_data["committee_img"])
                    new_committee.committee_img = com_img

                db.session.add(new_committee)

                try:

                    db.session.commit()
                    emit('create_committee', Response.AddSuccess)
                    get_committees(broadcast=True)
                except Exception as e:

                    db.session.rollback()
                    db.session.flush()
                    emit("create_committee", Response.AddError)
            else:
                emit('create_committee', Response.AddError)
        else:
            emit('create_committee', Response.AddExists)
    else:
        emit('create_committee', Response.UsrDoesntExist)
예제 #4
0
    def test_member_perms(self):
        db.session.add(self.test_committee)
        db.session.commit()

        testcomm = Committees(id="testcomm")
        testcomm.title = "TestComm"

        db.session.add(testcomm)
        db.session.commit()

        membership = Members(role=Roles.NormalMember)
        membership.member = self.test_user
        testcomm.members.append(membership)

        user_data = {
            "token": self.user_token,
            "id": "testcomm",
        }

        self.socketio.emit('get_permissions', user_data)
        received = self.socketio.get_received()
        assert received[0]["args"][0] == Permissions.CanContribute
예제 #5
0
    def setup_method(self, method):
        db.drop_all()
        db.create_all()

        self.test_committee_dict = {
            "id": "testcommittee",
            "title": "testcommittee",
            "description": "Test Description",
            "location": "Test Location",
            "meeting_time": "1300",
            "meeting_day": 2,
            "head": "testuser",
            "committee_img":
            "R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
        }
        self.test_committee = Committees(id="testcommittee")
        self.test_committee.title = self.test_committee_dict["title"]
        self.test_committee.location = self.test_committee_dict["location"]
        self.test_committee.description = self.test_committee_dict[
            "description"]
        self.test_committee.meeting_time = self.test_committee_dict[
            "meeting_time"]
        self.test_committee.meeting_day = self.test_committee_dict[
            "meeting_day"]
        self.test_committee.head = self.test_committee_dict["head"]
        com_img = base64.b64decode(self.test_committee_dict["committee_img"])
        self.test_committee.com_image = com_img

        # Create admin user for tests.
        admin = Users(id="adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        db.session.commit()
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal user for tests.
        user = Users(id="testuser")
        user.first_name = "Test1"
        user.last_name = "User"
        user.email = "*****@*****.**"
        user.is_admin = False
        db.session.add(user)
        db.session.commit()
        self.test_user = user
        self.user_token = user.generate_auth()
        self.user_token = self.user_token.decode('ascii')
예제 #6
0
    def setup_method(self, method):
        db.drop_all()
        db.create_all()

        # Create admin user for tests.
        admin = Users(id="adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        db.session.commit()
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal user for tests.
        user = Users(id="testuser")
        user.first_name = "Test1"
        user.last_name = "User"
        user.email = "*****@*****.**"
        user.is_admin = False
        db.session.add(user)
        db.session.commit()
        self.test_user = user
        self.user_token = user.generate_auth()
        self.user_token = self.user_token.decode('ascii')

        # Create normal user for tests.
        user2 = Users(id="testuser2")
        user2.first_name = "Test"
        user2.last_name = "User"
        user2.email = "*****@*****.**"
        user2.is_admin = False
        db.session.add(user2)
        db.session.commit()
        self.test_user2 = user2
        self.user_token2 = user2.generate_auth()
        self.user_token2 = self.user_token2.decode('ascii')

        # Create normal user for tests.
        user3 = Users(id="activemember")
        user3.first_name = "Active"
        user3.last_name = "Member"
        user3.email = "*****@*****.**"
        user3.is_admin = False
        db.session.add(user2)
        db.session.commit()
        self.test_user3 = user3
        self.user_token3 = user3.generate_auth()
        self.user_token3 = self.user_token3.decode('ascii')

        # Create a test committee.
        committee = Committees(id="testcommittee")
        committee.title = "Test Committee"
        committee.description = "Test Description"
        committee.location = "Test Location"
        committee.meeting_time = "1300"
        committee.meeting_day = 2
        committee.head = "testuser"
        self.committee = committee

        # Create a test committee.
        committee2 = Committees(id="testcommittee2")
        committee2.title = "Test Committee2"
        committee2.description = "Test Description"
        committee2.location = "Test Location"
        committee2.meeting_time = "1300"
        committee2.meeting_day = 2
        committee2.head = "testuser"
        self.committee2 = committee2

        # Add user3 to committee.
        role = Members(role=Roles.ActiveMember)
        role.member = self.test_user3
        self.committee.members.append(role)
        db.session.add(self.committee)
        db.session.add(self.committee2)
        db.session.commit()

        self.charge_dict = {
            'id': 10,
            'title': 'Test Charge',
            'description': 'Test Description',
            'committee': 'testcommittee',
            'status': 0,
            'priority': 0,
            'private': True,
            'paw_links': "https://testlink.com"
        }

        # Create a test charge.
        charge = Charges(id=10)
        charge.author = "testuser"
        charge.title = "Test Charge"
        charge.description = "Test Description"
        charge.committee = "testcommittee"
        charge.paw_links = "https://testlink.com"
        charge.priority = 0
        charge.status = 0
        charge.private = True
        self.charge = charge

        db.session.add(charge)
        db.session.commit()
        self.charge_dict["created_at"] = self.charge.created_at.isoformat()
예제 #7
0
    def setup_method(self, method):
        db.drop_all()
        db.create_all()

        # Create admin user for tests.
        admin = Users(id="adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        db.session.commit()
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal member for tests.
        self.normal_member = Users(id="testuser")
        self.normal_member.first_name = "Test1"
        self.normal_member.last_name = "User"
        self.normal_member.email = "*****@*****.**"
        self.normal_member.is_admin = False
        db.session.add(self.normal_member)
        db.session.commit()
        self.normal_member_token = self.normal_member.generate_auth()
        self.normal_member_token = self.normal_member_token.decode('ascii')

        # Create normal minute taker for tests.
        self.minute_taker = Users(id="test2user")
        self.minute_taker.first_name = "Test2"
        self.minute_taker.last_name = "User"
        self.minute_taker.email = "*****@*****.**"
        self.minute_taker.is_admin = False
        db.session.add(self.minute_taker)
        db.session.commit()
        self.minute_taker_token = self.minute_taker.generate_auth()
        self.minute_taker_token = self.minute_taker_token.decode('ascii')

        # Create normal minute taker for tests.
        self.not_member = Users(id="test3user")
        self.not_member.first_name = "Test3"
        self.not_member.last_name = "User"
        self.not_member.email = "*****@*****.**"
        self.not_member.is_admin = False
        db.session.add(self.not_member)
        db.session.commit()
        self.not_member_token = self.not_member.generate_auth()
        self.not_member_token = self.not_member_token.decode('ascii')

        # Create a test committee.
        self.committee = Committees(id="testcommittee")
        self.committee.title = "Test Committee"
        self.committee.description = "Test Description"
        self.committee.location = "Test Location"
        self.committee.meeting_time = "1200"
        self.committee.meeting_day = 2
        self.committee.head = "adminuser"

        # Add user to committee as normal member.
        normal_role = Members(role=Roles.NormalMember)
        normal_role.member = self.normal_member
        self.committee.members.append(normal_role)

        minute_taker_role = Members(role=Roles.MinuteTaker)
        minute_taker_role.member = self.minute_taker
        self.committee.members.append(minute_taker_role)

        db.session.add(self.committee)

        self.user_data = {
            "token": self.admin_token,
            "committee_id": self.committee.id,
            "title": "New Minute",
            "body": "This is a test body.",
            "date": 565745465,
            "private": False
        }

        # Create a test charge.
        charge = Charges(id=10)
        charge.author = "testuser"
        charge.title = "Test Charge"
        charge.description = "Test Description"
        charge.committee = "testcommittee"
        charge.paw_links = "https://testlink.com"
        charge.priority = 0
        charge.status = 0
        self.charge = charge
        db.session.add(charge)

        # Create a new test charge.
        new_charge = Charges(id=11)
        new_charge.author = "testuser"
        new_charge.title = "Test Charge"
        new_charge.description = "Test Description"
        new_charge.committee = "testcommittee"
        new_charge.paw_links = "https://testlink.com"
        new_charge.priority = 0
        new_charge.status = 0
        self.new_charge = new_charge
        db.session.add(new_charge)

        self.minute = Minutes(title="Test Minute",
                              body="TestBody",
                              date=282827,
                              private=True)
        self.minute.charges.append(self.charge)
        self.committee.minutes.append(self.minute)

        self.public_minute = Minutes(title="Public Test Minute",
                                     body="PublicTestBody",
                                     date=282827,
                                     private=False)
        self.public_minute.charges.append(self.charge)
        self.committee.minutes.append(self.public_minute)

        db.session.commit()
예제 #8
0
    def setup_method(self, method):
        db.drop_all()
        db.create_all()

        self.user_data = {
            "user_id": "testuser",
            "committee_id": "testcommittee",
            "role": "NormalMember"
        }

        # Create admin user for tests.
        admin = Users(id = "adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        #db.session.expunge(admin)
        db.session.commit()
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal user for tests.
        self.user = Users(id = "testuser")
        self.user.first_name = "Test1"
        self.user.last_name = "User"
        self.user.email = "*****@*****.**"
        self.user.is_admin = False
        db.session.add(self.user)
        db.session.commit()
        self.user_token = self.user.generate_auth()
        self.user_token = self.user_token.decode('ascii')

        # Create normal user2 for tests.
        self.user2 = Users(id = "test2user")
        self.user2.first_name = "Test2"
        self.user2.last_name = "User"
        self.user2.email = "*****@*****.**"
        self.user2.is_admin = False
        db.session.add(self.user2)
        db.session.commit()
        self.user2_token = self.user2.generate_auth()
        self.user2_token = self.user2_token.decode('ascii')

        # Create a test committee.
        self.committee = Committees(id = "testcommittee")
        self.committee.title = "Test Committee"
        self.committee.description = "Test Description"
        self.committee.location = "Test Location"
        self.committee.meeting_time = "1200"
        self.committee.meeting_day = 2
        self.committee.head = "adminuser"

        # Create a seconnd test committee.
        self.committee2 = Committees(id = "testcommittee2")
        self.committee2.title = "Test Committee"
        self.committee2.description = "Test Description"
        self.committee2.location = "Test Location"
        self.committee2.meeting_time = "1200"
        self.committee2.meeting_day = 2
        self.committee2.head = "adminuser"

        # Add user2 to committee.
        role = Members(role= Roles.NormalMember)
        role.member = self.user2
        self.committee.members.append(role)
        db.session.add(self.committee)
        db.session.add(self.committee2)

        db.session.commit()