예제 #1
0
    def test_organization_member(self):

        org = org_utils.get_organization(1)
        assert org is not None
        assert org.id == 1
        assert org.owner_id == 1
        assert org.name == 'Test'

        john = org_utils.get_user(2)  # john
        membership1 = org_utils.get_membership(org, john)
        assert john is not None
        assert membership1 is not None

        jane = User(email='*****@*****.**',
                    first_name='Jane',
                    last_name='Doe',
                    password='******',
                    confirmed=True)
        db.session.add(jane)
        db.session.commit()

        jane = org_utils.get_user(3)  # jane
        membership2 = org_utils.get_membership(org, jane)
        assert jane is not None
        assert membership2 is None

        g.user = john
        does_nothing_member_of_org(key=org.id)

        g.user = jane
        self.assertRaises(NotMember, does_nothing_member_of_org, key=org.id)
예제 #2
0
 def test_assign_member_to_position(self):
     """
     Tests that a user is assigned to a position
     :return:
     """
     pos = org_utils.get_position(1).id
     user = org_utils.get_user(1).id
     
     org_utils.assign_member_to_position(user, pos)
     assigneduser = position_assignments.select(position_assignments.c.user_id == 1)
     assert assigneduser is not None
예제 #3
0
    def test_owns_organization(self):

        org = org_utils.get_organization(1)
        assert org is not None
        assert org.id == 1
        assert org.owner_id == 1
        assert org.name == 'Test'

        member = org_utils.get_user(2)  # john
        membership = org_utils.get_membership(org, member)
        assert member is not None
        assert membership is not None
        assert membership.is_owner == False

        g.user = org.owner
        does_nothing_owns_org(key=org.id)

        g.user = member
        self.assertRaises(NotOwner, does_nothing_owns_org, key=org.id)
예제 #4
0
    def test_delete_user_from_org(self):
        """
        Tests deleting a user from a organization
        :return:
        """
        self.john_membership.joined = False
        db.session.commit()
        g.user = None

        membership = org_utils.confirm_invite(self.john_membership)

        assert membership is not None

        org_utils.delete_user_from_org(2, 1)

        user = org_utils.get_user(2)
        org = org_utils.get_organization(1)

        membership = org_utils.get_membership(org, user)

        assert membership is None
예제 #5
0
    def test_admin_of_org(self):

        org = org_utils.get_organization(1)
        assert org is not None
        assert org.id == 1
        assert org.owner_id == 1
        assert org.name == 'Test'

        john = org_utils.get_user(2)  # john
        membership = org_utils.get_membership(org, john)
        assert john is not None
        assert membership is not None
        assert membership.is_admin == False
        membership.change_admin()

        jane = User(email='*****@*****.**',
                    first_name='Jane',
                    last_name='Doe',
                    password='******',
                    confirmed=True)
        db.session.add(jane)
        db.session.commit()

        jane_membership = Membership(member_id=jane.id,
                                     organization_id=org.id,
                                     is_owner=False,
                                     joined=True)
        db.session.add(jane_membership)
        db.session.commit()

        g.user = john
        does_nothing_admin(key=org.id)

        g.user = jane
        self.assertRaises(NotAdmin, does_nothing_admin, key=org.id)

        membership.change_admin()  # reset john to non-admin