Ejemplo n.º 1
0
	def done(self, form_list, **kwargs):
		position = Position(
					project=form_list[0].cleaned_data['project'], 
					title=form_list[0].cleaned_data['title'], 
					description=form_list[0].cleaned_data['description'],)
		
		position.save()
			
		for k, v in form_list[1].cleaned_data.items():
			if v > 0:
				skillobj = Skill.objects.get(id=int(k))
				ps = PositionSkill(position=position, skill=skillobj, rank=v)
				ps.save()
		
		return redirect(project_detail, self.project)
Ejemplo n.º 2
0
    def setUp(self):
        db.create_all()
        user = User(email='*****@*****.**',
                    first_name='Organization',
                    last_name='Owner',
                    password='******',
                    confirmed=True)
        db.session.add(user)
        db.session.commit()

        org = Organization('Test', user.id)

        db.session.add(org)
        db.session.commit()

        john = User(email='*****@*****.**',
                    first_name='John',
                    last_name='Doe',
                    password='******',
                    confirmed=True)

        db.session.add(john)
        db.session.commit()

        john_membership = Membership(member_id=john.id,
                                     organization_id=org.id,
                                     is_owner=False,
                                     joined=True)

        db.session.add(john_membership)
        db.session.commit()

        position = Position(title='Test Position',
                            organization_id=org.id,
                            description='This is a description')

        db.session.add(position)
        db.session.commit()

        shift = Shift(
            position_id=position.id,
            assigned_user_id=None,
            start_time='2016-10-26T06:00:00',
            end_time='2016-10-26T07:00:00',
            description=None,
        )

        db.session.add(shift)
        db.session.commit()

        self.owner = user
        self.john = john
        self.john_membership = john_membership
        self.organization = org
        self.position = position
        self.shift = shift
Ejemplo n.º 3
0
    def test_valid_description_missing(self):
        """
        Tests a valid dictionary where the description is missing
        :return:
        """
        position = Position(
            title='Test Position',
            organization_id=1,
            description='test'
        )

        user = User(
            email='*****@*****.**',
            first_name='John',
            last_name='Doe',
            password='******',
            confirmed=True
        )

        shift = Shift(assigned_user_id=user.id, description=None, position_id=position.id,
                             start_time='2007-04-05T14:30', end_time='2007-04-05T14:30')

        shift.Position = position
        shift.user = user

        assert shift is not None

        shift_dict = org_utils.shift_to_dict(shift)
        assert shift_dict is not None

        assert 'id' in shift_dict
        assert shift_dict['id'] == shift.id

        assert 'position_id' in shift_dict
        assert shift_dict['position_id'] == shift.Position.id

        assert 'position_title' in shift_dict
        assert shift_dict['position_title'] == shift.Position.title

        assert 'start' in shift_dict
        assert shift_dict['start'] == shift.start_time

        assert 'end' in shift_dict
        assert shift_dict['end'] == shift.end_time

        assert 'description' in shift_dict
        assert shift_dict['description'] == ''

        assert 'assigned_member_id' in shift_dict
        assert shift_dict['assigned_member_id'] == shift.assigned_user_id

        assert 'assigned_member' in shift_dict
        assert shift_dict['assigned_member'] == shift.user.first_name + ' ' + shift.user.last_name
Ejemplo n.º 4
0
def create_position(org, title, description):
    """
    Creates a position given a organization and a position title/name
    :return:
    """
    position = Position(title=title,
                        organization_id=org.id,
                        description=description)
    db.session.add(position)
    org.owned_positions.append(position)
    db.session.commit()
    return position
Ejemplo n.º 5
0
    def test_valid_user_missing(self):
        """
        Tests a valid dictionary where no user is assigned
        :return:
        """
        position = Position(
            title='Test Position',
            organization_id=1,
            description='test'
        )

        shift = Shift(assigned_user_id=None, description='A description', position_id=position.id,
                             start_time='2007-04-05T14:30', end_time='2007-04-05T14:30')

        shift.Position = position

        assert shift is not None

        shift_dict = org_utils.shift_to_dict(shift)
        assert shift_dict is not None

        assert 'id' in shift_dict
        assert shift_dict['id'] == shift.id

        assert 'position_id' in shift_dict
        assert shift_dict['position_id'] == shift.Position.id

        assert 'position_title' in shift_dict
        assert shift_dict['position_title'] == shift.Position.title

        assert 'start' in shift_dict
        assert shift_dict['start'] == shift.start_time

        assert 'end' in shift_dict
        assert shift_dict['end'] == shift.end_time

        assert 'description' in shift_dict
        assert shift_dict['description'] == shift.description

        assert 'assigned_member_id' in shift_dict
        assert shift_dict['assigned_member_id'] == 0

        assert 'assigned_member' in shift_dict
        assert shift_dict['assigned_member'] == 'Unassigned'
Ejemplo n.º 6
0
    def test_update_shift(self):
        """
        Tests updating a shift
        :return:
        """
        shift = org_utils.get_shift(1)

        new_pos = Position(title='Test 3',
                           organization_id=self.organization.id,
                           description='Test')
        db.session.add(new_pos)
        db.session.commit()

        start_time = '2016-10-26T08:00:00'
        end_time = '2016-10-26T10:30:00'

        shift.update(new_pos.id, self.john.id, start_time, end_time, 'desc')

        # re-query, compare fields
        shift = org_utils.get_shift(1)
        assert shift.position_id == new_pos.id
        assert shift.assigned_user_id == self.john.id
        assert shift.start_time == start_time
        assert shift.end_time == end_time
        assert shift.description == 'desc'

        # test optional args
        shift.update(position_id=self.shift.position_id)
        shift = org_utils.get_shift(1)
        assert shift.position_id == self.shift.position_id
        assert shift.assigned_user_id == self.john.id
        assert shift.start_time == start_time
        assert shift.end_time == end_time
        assert shift.description == 'desc'

        # reset fields for future tests
        shift.update(self.shift.position_id, self.shift.assigned_user_id,
                     self.shift.start_time, self.shift.end_time,
                     self.shift.description)
Ejemplo n.º 7
0
    def test_create_shift(self):
        """
        Tests creating a new shift
        :return:
        """
        new_pos = Position(title='Test 2',
                           organization_id=self.organization.id,
                           description='test')
        db.session.add(new_pos)
        db.session.commit()

        start_time = '2016-10-26T08:00:00'
        end_time = '2016-10-26T09:00:00'

        shift = org_utils.create_shift(new_pos.id, self.john.id, start_time,
                                       end_time, 'desc')

        assert shift is not None
        assert shift.position_id == new_pos.id
        assert shift.assigned_user_id == self.john.id
        assert shift.start_time == start_time
        assert shift.end_time == end_time
        assert shift.description == 'desc'
Ejemplo n.º 8
0
    def test_shift_belongs_to_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'

        shift1 = org_utils.get_shift(1)
        assert shift1 is not None

        org2 = Organization('Test2', org.owner_id)
        db.session.add(org2)
        db.session.commit()

        position = Position(title='Test Position',
                            organization_id=org2.id,
                            description='This is a description')
        db.session.add(position)
        db.session.commit()

        shift2 = Shift(
            position_id=position.id,
            assigned_user_id=None,
            start_time='2016-10-26T06:00:00',
            end_time='2016-10-26T07:00:00',
            description=None,
        )
        db.session.add(shift2)
        db.session.commit()

        does_nothing_shift_belongs(key=org.id, key1=shift1.id)

        self.assertRaises(ShiftNotInOrg,
                          does_nothing_shift_belongs,
                          key=org.id,
                          key1=shift2.id)