Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance issue model boarding column property #1065

Merged
merged 3 commits into from
Aug 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion dolphin/controllers/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ..exceptions import StatusRoomMemberAlreadyExist, \
StatusRoomMemberNotFound, StatusRelatedIssueNotFound, \
StatusIssueBugMustHaveRelatedIssue, StatusIssueNotFound, \
StatusQueryParameterNotInFormOrQueryString
StatusQueryParameterNotInFormOrQueryString, StatusIssueIsAlreadyExtended
from ..models import Issue, Subscription, Phase, Item, Member, Project, \
RelatedIssue, IssueTag, Tag, AbstractResourceSummaryView, \
AbstractPhaseSummaryView, IssuePhase, ReturnToTriageJob
Expand Down Expand Up @@ -826,6 +826,21 @@ def search(self):

return query

@authorize
@json(prevent_form='709 Form Not Allowed')
@commit
def extend(self, id):
id = int_or_notfound(id)
issue = DBSession.query(Issue).get(id)
if issue is None:
raise HTTPNotFound()

if issue.is_extended:
raise StatusIssueIsAlreadyExtended()

issue.is_extended = True
return issue


class IssuePhaseSummaryController(ModelRestController):
__model__ = AbstractPhaseSummaryView
Expand Down
4 changes: 4 additions & 0 deletions dolphin/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,7 @@ class StatusIssueIdNotInForm(HTTPKnownStatus):
class StatusInvalidBatch(HTTPKnownStatus):
status = '936 Invalid Batch More Than 100'


class StatusIssueIsAlreadyExtended(HTTPKnownStatus):
status = '666 Issue Is Already Extended'

29 changes: 28 additions & 1 deletion dolphin/models/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ class Issue(OrderingMixin, FilteringMixin, PaginationMixin, ModifiedByMixin,
example='lorem ipsum',
message='lorem ipsum',
)
is_extended = Field(
Boolean,
python_type=bool,
label='Last Moving Time',
nullable=True,
protected=True,
required=False,
not_none=False,
readonly=True,
)
attachments = relationship('Attachment', lazy='selectin')
tags = relationship(
'Tag',
Expand All @@ -209,8 +219,8 @@ class Issue(OrderingMixin, FilteringMixin, PaginationMixin, ModifiedByMixin,
)
project = relationship(
'Project',
foreign_keys=[project_id],
back_populates='issues',
foreign_keys=[project_id],
protected=False,
)
returntotriagejobs = relationship(
Expand Down Expand Up @@ -341,6 +351,23 @@ class Issue(OrderingMixin, FilteringMixin, PaginationMixin, ModifiedByMixin,
deferred=True
)

boarding = column_property(
case([
(
stage == 'on-hold',
'frozen'
),
(
due_date == null(),
'on-time'
),
(
due_date < func.now(),
'delayed'
),
], else_='on-time').label('boarding'),
)

@hybrid_property
def response_time(self):
if self.last_moving_time:
Expand Down
102 changes: 102 additions & 0 deletions tests/test_issue_extend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
from nanohttp import context
from nanohttp.contexts import Context
from auditor.context import Context as AuditLogContext
from bddrest import status, response, when

from dolphin.models import Issue, Member, Workflow, Group, Project, Release, \
Specialty, Phase, Item, IssuePhase
from .helpers import LocalApplicationTestCase, oauth_mockup_server


class TestIssue(LocalApplicationTestCase):

@classmethod
@AuditLogContext(dict())
def mockup(cls):
session = cls.create_session()

cls.member = Member(
title='First Member',
email='[email protected]',
access_token='access token 1',
phone=123456789,
reference_id=2
)
session.add(cls.member)
session.commit()

workflow = Workflow(title='default')
specialty = Specialty(title='First Specialty')
group = Group(title='default')

release = Release(
title='My first release',
description='A decription for my first release',
cutoff='2030-2-20',
launch_date='2030-2-20',
manager=cls.member,
room_id=0,
group=group,
)

cls.project = Project(
release=release,
workflow=workflow,
group=group,
manager=cls.member,
title='My first project',
description='A decription for my project',
room_id=1
)

with Context(dict()):
context.identity = cls.member

cls.issue = Issue(
project=cls.project,
title='First issue',
description='This is description of first issue',
kind='feature',
days=1,
room_id=2
)
session.add(cls.issue)
session.commit()

def test_extend(self):
session = self.create_session()
self.login(self.member.email)

with oauth_mockup_server(), self.given(
'Getting a issue',
f'/apiv1/issues/id: {self.issue.id}',
'EXTEND'
):
assert status == 200
assert response.json['id'] == self.issue.id
assert session.query(Issue).get(self.issue.id).is_extended == True

when('Issue is already extended')
assert status == '666 Issue Is Already Extended'

when(
'Intended project with string type not found',
url_parameters=dict(id='Alphabetical')
)
assert status == 404

when(
'Intended project with string type not found',
url_parameters=dict(id=100)
)
assert status == 404

when(
'Form parameter is sent with request',
form=dict(parameter='Invalid form parameter')
)
assert status == '709 Form Not Allowed'

when('Request is not authorized', authorization=None)
assert status == 401

86 changes: 85 additions & 1 deletion tests/test_issue_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timedelta

from auditor.context import Context as AuditLogContext
from nanohttp import context
Expand Down Expand Up @@ -875,3 +875,87 @@ def test_issue_response_time(db):

assert issue1.response_time == None


def test_issue_boarding(db):
session = db()
session.expire_on_commit = True

with AuditLogContext(dict()):
member1 = Member(
title='First Member',
email='[email protected]',
access_token='access token 1',
reference_id=2,
)
session.add(member1)
session.commit()

workflow = Workflow(title='Default')
skill = Skill(title='First Skill')
specialty = Specialty(skill=skill, title='First Specialty')
group = Group(title='default')

release = Release(
title='My first release',
cutoff='2030-2-20',
launch_date='2030-2-20',
manager=member1,
room_id=0,
group=group,
)

project = Project(
release=release,
workflow=workflow,
group=group,
manager=member1,
title='My first project',
room_id=1,
)

with Context(dict()):
context.identity = member1

issue1 = Issue(
project=project,
title='First issue',
days=1,
room_id=2,
stage='on-hold',
)
session.add(issue1)
session.commit()

assert issue1.boarding == 'frozen'

issue1.stage = 'triage'
session.commit()

assert issue1.boarding == 'on-time'

phase1 = Phase(
workflow=workflow,
title='Backlog',
order=1,
specialty=specialty,
)
session.add(phase1)

issue_phase1 = IssuePhase(
issue=issue1,
phase=phase1,
)
session.add(issue_phase1)

item1 = Item(
issue_phase=issue_phase1,
member_id=member1.id,
start_date=datetime.now() - timedelta(days=2),
end_date=datetime.now() - timedelta(days=1),
estimated_hours=4,
)
session.add(item1)
session.commit()

assert issue1.boarding == 'delayed'