From ef57b305dcd65455b3cffd234b53b66a6f1864e8 Mon Sep 17 00:00:00 2001 From: shayan Date: Sun, 12 May 2019 19:12:04 +0430 Subject: [PATCH] Remove CREATE verb on Daily report controller Fixed a bug on the daily report related to item Add @commit to GET and LIST daily-report verbs Enhance test list of daily reports Updated some of labels of daily report model Modified the routing to the phase controller Added the method list to the phase controller v0.43.0a7 Add daily report migration v0.43.1a7 Revise time card to daily report (#811) * Revise time card to daily report, closes #805 closes #806 closes #807 closes #808 closes #809 * Remove CREATE verb on Daily report controller * Fixed a bug on the daily report related to item * Add @commit to GET and LIST daily-report verbs * Enhance test list of daily reports Implemented the list method on the phase controller (#814) * Implemented the list method on the phase controller * The coding style is modified Created custom exception classes (#778) * Renamed custom exception errors Created custom exception classes Created custom exception classes Created custom exception classes Fixed coding style Created custom exception classes * Enhance imports * Typo * Renamed none to null Implement filtering Item by different zones, closes #764 Add issue dict to item to_dict method return value Implement verb ESTIMATE on Item, closes #812 Add test cases Enhance coding style Added the issue metadata into item model, closes #819 Increase the coverage (#810) * Check some test for increase coverage * Check some test for increase coverage * Some not found field check. * Add test for tokens * Remove redundant functions * Added new test case for increase coverage * Revise code * Add Not found in draftissue * Add Not found in draftissue * Add check project id * chat room exception replace * Added test case related to the audit log * Resolved the conflict * Some revise * Resolved the conflict * Added new test case related to the auditlog Add issue dict to item to_dict method return value (#816) Add project instance to issue response to_dict and issue to item response Enhance item model to_dict --- dolphin/__init__.py | 2 +- dolphin/controllers/items.py | 3 +- dolphin/migration/versions/84d5fef5976a_.py | 80 +++++++++++ dolphin/models/dailyreport.py | 2 +- dolphin/models/item.py | 15 ++ dolphin/tests/test_dailyreport_create.py | 148 -------------------- dolphin/tests/test_item_estimate.py | 6 + 7 files changed, 105 insertions(+), 151 deletions(-) create mode 100644 dolphin/migration/versions/84d5fef5976a_.py delete mode 100644 dolphin/tests/test_dailyreport_create.py diff --git a/dolphin/__init__.py b/dolphin/__init__.py index a5c32d0b..44e3c056 100644 --- a/dolphin/__init__.py +++ b/dolphin/__init__.py @@ -11,7 +11,7 @@ from .controllers.root import Root -__version__ = '0.42.1a7' +__version__ = '0.43.1a7' class Dolphin(Application): diff --git a/dolphin/controllers/items.py b/dolphin/controllers/items.py index f3dbcc93..bdc7f385 100644 --- a/dolphin/controllers/items.py +++ b/dolphin/controllers/items.py @@ -160,5 +160,6 @@ def update(self, id): @commit def list(self): self._create_dailyreport_if_needed() - return DBSession.query(Dailyreport) + return DBSession.query(Dailyreport) \ + .filter(Dailyreport.item_id == self.item.id) diff --git a/dolphin/migration/versions/84d5fef5976a_.py b/dolphin/migration/versions/84d5fef5976a_.py new file mode 100644 index 00000000..0c216cfe --- /dev/null +++ b/dolphin/migration/versions/84d5fef5976a_.py @@ -0,0 +1,80 @@ +"""empty message + +Revision ID: 84d5fef5976a +Revises: a2410e75c467 +Create Date: 2019-05-13 14:33:29.207279 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = '84d5fef5976a' +down_revision = 'a2410e75c467' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + 'dailyreport', + sa.Column('item_id', sa.Integer(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('date', sa.Date(), nullable=False), + sa.Column('hours', sa.Integer(), nullable=True), + sa.Column('note', sa.Unicode(), nullable=True), + sa.ForeignKeyConstraint(['item_id'], ['item.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.drop_table('timecard') + op.add_column( + 'item', + sa.Column('estimated_hours', sa.Integer(), nullable=True) + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('item', 'estimated_hours') + op.create_table( + 'timecard', + sa.Column( + 'id', + sa.INTEGER(), + autoincrement=True, + nullable=False + ), + sa.Column( + 'start_date', + postgresql.TIMESTAMP(), + autoincrement=False, + nullable=False + ), + sa.Column( + 'end_date', + postgresql.TIMESTAMP(), + autoincrement=False, + nullable=False + ), + sa.Column( + 'estimated_time', + sa.INTEGER(), + autoincrement=False, + nullable=False + ), + sa.Column( + 'summary', + sa.VARCHAR(), + autoincrement=False, + nullable=False + ), + sa.PrimaryKeyConstraint( + 'id', + name='timecard_pkey' + ) + ) + op.drop_table('dailyreport') + # ### end Alembic commands ### diff --git a/dolphin/models/dailyreport.py b/dolphin/models/dailyreport.py index 55abb789..dee35504 100644 --- a/dolphin/models/dailyreport.py +++ b/dolphin/models/dailyreport.py @@ -56,7 +56,7 @@ class Dailyreport(OrderingMixin, FilteringMixin, PaginationMixin, \ Unicode, min_length=1, max_length=1024, - label='Lorem Isum', + label='Notes', watermark='Lorem Ipsum', not_none=False, nullable=True, diff --git a/dolphin/models/item.py b/dolphin/models/item.py index 624d4ca2..f2d0ef25 100644 --- a/dolphin/models/item.py +++ b/dolphin/models/item.py @@ -1,6 +1,7 @@ from datetime import datetime from restfulpy.orm import Field, DeclarativeBase, relationship +from restfulpy.orm.metadata import MetadataField from restfulpy.orm.mixins import TimestampMixin, OrderingMixin, \ FilteringMixin, PaginationMixin from sqlalchemy import Integer, ForeignKey, UniqueConstraint, DateTime, Enum, \ @@ -151,3 +152,17 @@ def to_dict(self): item_dict['hoursWorked'] = self.hours_worked return item_dict + @classmethod + def iter_metadata_fields(cls): + yield from super().iter_metadata_fields() + yield MetadataField( + name='issue', + key='issue', + label='Lorem Ipsun', + required=False, + readonly=True, + watermark='Lorem Ipsum', + example='Lorem Ipsum', + message='Lorem Ipsun', + ) + diff --git a/dolphin/tests/test_dailyreport_create.py b/dolphin/tests/test_dailyreport_create.py deleted file mode 100644 index b415c51b..00000000 --- a/dolphin/tests/test_dailyreport_create.py +++ /dev/null @@ -1,148 +0,0 @@ -from datetime import datetime - -from bddrest import status, response, when, given -from auditor.context import Context as AuditLogContext - -from dolphin.models import Member, Workflow, Skill, Group, Phase, Release, \ - Project, Issue, Item -from dolphin.tests.helpers import LocalApplicationTestCase, oauth_mockup_server - - -class TestDailyreport(LocalApplicationTestCase): - - @classmethod - @AuditLogContext(dict()) - def mockup(cls): - session = cls.create_session() - - cls.member = Member( - title='First Member', - email='member1@example.com', - access_token='access token 1', - phone=123456789, - reference_id=1, - ) - session.add(cls.member) - - workflow = Workflow(title='Default') - skill = Skill(title='First Skill') - group = Group(title='default') - - phase = Phase( - title='backlog', - order=-1, - workflow=workflow, - skill=skill, - ) - session.add(phase) - - 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, - ) - - project = Project( - release=release, - workflow=workflow, - group=group, - manager=cls.member, - title='My first project', - description='A decription for my project', - room_id=1 - ) - - issue = Issue( - project=project, - title='First issue', - description='This is description of first issue', - due_date='2020-2-20', - kind='feature', - days=1, - room_id=2 - ) - session.add(issue) - session.flush() - - cls.item = Item( - issue_id=issue.id, - phase_id=phase.id, - member_id=cls.member.id, - ) - session.add(cls.item) - session.commit() - - def test_create(self): - self.login(self.member.email) - form = dict( - note='Some summary', - hours=2, - itemId=self.item.id, - ) - - with oauth_mockup_server(), self.given( - 'Creating a dailyreport', - '/apiv1/dailyreports', - 'CREATE', - json=form - ): - assert status == 200 - assert response.json['id'] is not None - assert response.json['date'] == str(datetime.now().date()) - assert response.json['hours'] == form['hours'] - assert response.json['note'] == form['note'] - assert response.json['itemId'] == form['itemId'] - - when( - 'Item id is null', - json=given | dict(itemId=None) - ) - assert status == '913 Item Id Is Null' - - when( - 'Item id is not in form', - json=given - 'itemId' - ) - assert status == '732 Item Id Not In Form' - - when( - 'Item is not found', - json=given | dict(itemId=0) - ) - assert status == '660 Item Not Found' - - when('Trying to pass without form parameters', json={}) - assert status == '708 Empty Form' - - when( - 'Invalid parameter is in form', - json=given | dict(parameter='invalid parameter') - ) - assert status == '707 Invalid field, only following fields are ' \ - 'accepted: hours, note and itemId' - - when( - 'Note length is less than limit', - json=given | dict(note=(1024 + 1) * 'a'), - ) - assert status == '902 At Most 1024 Characters Are Valid For Note' - - when( - 'Hours value type is wrong', - json=given | dict(hours='a') - ) - assert status == '900 Invalid Hours Type' - - when( - 'Hours value is less then 1', - json=given | dict(hours=0) - ) - assert status == '914 Hours Must Be Greater Than 0' - - when('Request is not authorized', authorization=None) - assert status == 401 - diff --git a/dolphin/tests/test_item_estimate.py b/dolphin/tests/test_item_estimate.py index c8c741c5..67177b16 100644 --- a/dolphin/tests/test_item_estimate.py +++ b/dolphin/tests/test_item_estimate.py @@ -163,12 +163,15 @@ def test_estimate(self): assert status == '905 Start Date Is Null' when( +<<<<<<< HEAD 'Start date pattern is wrong', json=given | dict(startDate='invalid pattern') ) assert status == '791 Invalid Start Date Format' when( +======= +>>>>>>> Remove CREATE verb on Daily report controller 'End date is not in form', json=given - 'endDate' ) @@ -181,12 +184,15 @@ def test_estimate(self): assert status == '906 End Date Is Null' when( +<<<<<<< HEAD 'End date pattern is wrong', json=given | dict(endDate='invalid pattern') ) assert status == '790 Invalid End Date Format' when( +======= +>>>>>>> Remove CREATE verb on Daily report controller 'Estimated hours field is not in form', json=given - 'estimatedHours' )