Ejemplo n.º 1
0
 def check_team_membership(self, ticket, sprint, person, is_owner=False):
     from trac.ticket.api import TicketSystem
     if person not in [None, '', TicketSystem.default_owner.default]:
         err_string = is_owner and 'owner' or 'resource'
         tmmm = TeamMemberModelManager(self.env)
         teammember = tmmm.get(name=person)
         sprint_team_name = sprint.team.name
         if (teammember == None) or (teammember.team == None) or \
             (teammember.team.name != sprint_team_name):
             name = person
             error(self, "Rule didn't validate...")
             msg = _(u"The %s '%s' of ticket #%s doesn't belong to the team '%s' assigned to this sprint.")
             raise RuleValidationException(msg % (err_string, name, ticket.id, sprint_team_name))
Ejemplo n.º 2
0
 def check_team_membership(self, ticket, sprint, person, is_owner=False):
     from trac.ticket.api import TicketSystem
     if person not in [None, '', TicketSystem.default_owner.default]:
         err_string = is_owner and 'owner' or 'resource'
         tmmm = TeamMemberModelManager(self.env)
         teammember = tmmm.get(name=person)
         sprint_team_name = sprint.team.name
         if (teammember == None) or (teammember.team == None) or \
             (teammember.team.name != sprint_team_name):
             name = person
             error(self, "Rule didn't validate...")
             msg = _(
                 u"The %s '%s' of ticket #%s doesn't belong to the team '%s' assigned to this sprint."
             )
             raise RuleValidationException(
                 msg % (err_string, name, ticket.id, sprint_team_name))
Ejemplo n.º 3
0
class TestTeamMember(AgiloTestCase):
    
    def setUp(self):
        self.super()
        self.tmm = TeamMemberModelManager(self.teh.get_env())
    
    def testTimeSheet(self):
        """Tests the accessor and mutator methods for attribute "time_sheet"."""
        test_ts_1 = [1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]
        test_ts_2 = [7.3, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0]
        # test the default constructor, capacity should return decimals
        team_member = self.tmm.create(name="Team Member #1", default_capacity=test_ts_1)
        self.assert_equals(team_member.capacity, test_ts_1)
        self.tmm.get_cache().invalidate()
        team_member = self.tmm.get(name="Team Member #1")
        self.assert_equals(team_member.capacity, test_ts_1)
        
        team_member.capacity = test_ts_2
        self.assert_equals(team_member.capacity, test_ts_2)
        self.assert_true(self.tmm.save(team_member))
        team_member = self.tmm.get(name="Team Member #1")
        self.assert_equals(team_member.capacity, test_ts_2)
    
    def test_set_get_session_attribute(self):
        team_member = self.tmm.create(name="test_member")
        env = self.teh.get_env()
        set_user_attribute_in_session(env, 'test', 'Test', team_member.name)
        self.assert_equals('Test', get_user_attribute_from_session(env, 'test', team_member.name))
    
    def test_set_get_full_name(self):
        team_member = self.tmm.create(name="test_member")
        team_member.full_name = 'Test Member'
        self.assert_equals('Test Member', team_member.full_name)
    
    def test_team_member_in_team(self):
        team = self.teh.create_team(name="Test Team")
        tm1 = self.tmm.create(name="tm1", team=team)
        self.assert_true(tm1.exists)
        tm2 = self.tmm.create(name="tm2", team=team)
        self.assert_true(tm2.exists)
        tm3 = self.tmm.create(name="tm3")
        self.assert_true(tm3.exists)
        # Check members of the team using the __cmp__ of persistent object
        self.assert_equals(2, len(team.members))
        self.assert_true(tm1 in team.members)
        self.assert_true(tm2 in team.members)
        self.assert_false(tm3 in team.members)
    
    def test_set_get_email(self):
        team_member = self.tmm.create(name="test_member")
        team_member.email = "*****@*****.**"
        self.assert_equals('*****@*****.**', team_member.email)
    
    def test_can_load_name_and_email_from_session_attributes(self):
        # Create a team member in the session simulating registration
        full_name = "Team Member Test"
        email = "*****@*****.**"
        
        set_user_attribute_in_session(self.env, 'name', full_name, 'tm')
        set_user_attribute_in_session(self.env, 'email', email, 'tm')
        
        tm = self.tmm.create(name='tm')
        self.assert_equals(full_name, tm.full_name)
        self.assert_equals(email, tm.email)
    
    def test_can_access_timezone_in_session_table(self):
        timezone_name = "GMT +7:00"
        timezone_offset = timedelta(hours=7)
        timezone = get_timezone(timezone_name)
        self.assert_equals(timezone_offset, timezone.utcoffset(None))
        
        set_user_attribute_in_session(self.env, 'tz', timezone_name, 'tm')
        
        member = self.tmm.create(name='tm')
        self.assert_equals(timezone_offset, member.timezone().utcoffset(None))
    
    def test_falls_back_to_server_timezone_if_none_is_set_in_session_table(self):
        member = self.tmm.create(name='tm')
        local_timezone_offset = localtz.utcoffset(now())
        self.assert_equals(local_timezone_offset, member.timezone().utcoffset(now()))
    
    def test_falls_back_to_server_timezone_if_garbage_is_set_in_session_table(self):
        set_user_attribute_in_session(self.env, 'tz', "fnord", 'tm')
        member = self.tmm.create(name='tm')
        local_timezone_offset = localtz.utcoffset(now())
        self.assert_equals(local_timezone_offset, member.timezone().utcoffset(now()))
    
    def test_knows_hour_at_which_work_starts_and_ends(self):
        member = self.tmm.create(name='tm')
        self.assert_equals(9, member.time_workday_starts().hour)
        self.assert_equals(18, member.time_workday_ends().hour)
    
    def test_knows_number_of_hours_of_workday(self):
        member = self.tmm.create(name='tm')
        self.assert_equals(9, member.number_of_working_hours_on_workday())
Ejemplo n.º 4
0
class AgiloPreferences(Component):
    
    implements(IPreferencePanelProvider)
    
    def __init__(self, *args, **kwargs):
        super(AgiloPreferences, self).__init__(*args, **kwargs)
        self.tmm = TeamModelManager(self.env)
        self.tmmm = TeamMemberModelManager(self.env)
    
    #=============================================================================
    # IPreferencePanelProvider methods
    #=============================================================================
    def get_preference_panels(self, req):
        """Return a list of available preference panels.
        
        The items returned by this function must be tuple of the form
        `(panel, label)`.
        """
        if req.authname is not None and req.authname != 'anonymous' and \
                Role.TEAM_MEMBER in req.perm:
            yield ('team', _('Team'))

    def render_preference_panel(self, req, panel):
        """Process a request for a preference panel. This builds the
        Panel for the team preferences
        """
        if req.method == 'POST':
            self._do_save(req)
            req.redirect(req.href.prefs(panel or None))
       
        # Build the team_member object
        team_member = None
        if req.authname not in [None, 'anonymous'] and \
                Role.TEAM_MEMBER in req.perm:
            name = req.authname
            team_member = self.tmmm.get(name=name)
            if team_member == None:
                team_member = self.tmmm.create(name=name)
        
        # Build the calendar for the current month
        calendars = list()
        ac = AgiloCalendar(day=datetime.today())
        for cal in range(2):
            calendars.append(team_member.calendar.get_hours_for_interval(ac.get_first_day(), 
                                                                         ac.get_last_day()))
            ac = ac.next_month()
            
        return 'agilo_prefs_%s.html' % (panel or 'general'), {
            'settings': {'session': req.session, 'session_id': req.session.sid},
            'teams': self.tmm.select(),
            'team_member': team_member,
            'calendars': calendars,
        }
    
    def _do_save(self, req):
        """Saves the parameters into the object"""
        # Get the Team Member
        team_member = self.tmmm.get(name=req.authname)
        cal = team_member.calendar
        save_calendar = False
        for fieldname in sorted(req.args):
            value = req.args.get(fieldname)
            if (value is not None) and (team_member is not None):
                if fieldname == 'team':
                    team = self.tmm.get(name=value)
                    team_member.team = team
                elif fieldname.startswith('ts_'):
                    if fieldname.startswith('ts_%s_' % team_member.name):
                        ts_member, day = fieldname.rsplit('_', 1)
                        try:
                            cal.set_hours_for_day(float(value), d_ordinal=day)
                        except ValueError:
                            cal.set_hours_for_day(0.0, d_ordinal=day)
                        if not save_calendar:
                            save_calendar = True
                    elif hasattr(team_member, fieldname):
                        try:
                            if float(value) != getattr(team_member, fieldname):
                                setattr(team_member, fieldname, float(value))
                        except ValueError:
                            setattr(team_member, fieldname, 0.0)
        team_member.save()
        # The member's capacity may have changed so we have to invalidate the
        # burndown
        ChartGenerator(self.env).invalidate_cache()
        if save_calendar:
            cal.save()