Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fixes #26 - add examples in restplus models using faker library
  • Loading branch information
Angeluz-07 committed Mar 17, 2020
commit cfedacc847965a8c5878322d7a72897d0b8396cb
1 change: 1 addition & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pytest==5.2.0

# Mocking
pytest-mock==2.0.0
Faker==4.0.2

# Coverage
coverage==4.5.1
6 changes: 6 additions & 0 deletions time_tracker_api/activities/activities_namespace.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from flask_restplus import fields, Resource, Namespace
from time_tracker_api.api import audit_fields
from faker import Faker

faker = Faker()

ns = Namespace('activities', description='API for activities')

Expand All @@ -10,10 +13,12 @@
title='Name',
max_length=50,
description='Canonical name of the activity',
example=faker.word(['Development', 'Training'])
),
'description': fields.String(
title='Description',
description='Comments about the activity',
example=faker.paragraph()
),
})

Expand All @@ -23,6 +28,7 @@
required=True,
title='Identifier',
description='The unique identifier',
example=faker.uuid4()
)
}
activity_response_fields.update(audit_fields)
Expand Down
8 changes: 7 additions & 1 deletion time_tracker_api/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from flask_restplus import Api, fields
from faker import Faker

faker = Faker()

api = Api(version='1.0.1', title="TimeTracker API",
description="API for the TimeTracker project")
Expand All @@ -8,19 +11,22 @@
'created_at': fields.Date(
readOnly=True,
title='Created',
description='Date of creation'
description='Date of creation',
example=faker.iso8601(end_datetime=None)
),
'tenant_id': fields.String(
readOnly=True,
title='Tenant',
max_length=64,
description='The tenant this belongs to',
example=faker.uuid4()
),
'created_by': fields.String(
readOnly=True,
title='Creator',
max_length=64,
description='User that created it',
example=faker.uuid4()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add trailing comas

),
}

Expand Down
11 changes: 9 additions & 2 deletions time_tracker_api/projects/projects_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from .projects_model import project_dao
from time_tracker_api.errors import MissingResource
from time_tracker_api.api import audit_fields
from faker import Faker

faker = Faker()

ns = Namespace('projects', description='API for projects (clients)')

Expand All @@ -11,17 +14,20 @@
required=True,
title='Name',
max_length=50,
description='Name of the project'
description='Name of the project',
example=faker.word(['YoSpace', 'Yira'])
),
'description': fields.String(
title='Description',
description='Description about the project'
description='Description about the project',
example=faker.paragraph()
),
'type': fields.String(
required=True,
title='Type',
max_length=30,
description='If it is `Costumer`, `Training` or other type',
example=faker.word(['Customer', 'Training'])
),
})

Expand All @@ -31,6 +37,7 @@
required=True,
title='Identifier',
description='The unique identifier',
example=faker.uuid4()
)
}
project_response_fields.update(audit_fields)
Expand Down
7 changes: 6 additions & 1 deletion time_tracker_api/technologies/technologies_namespace.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from flask_restplus import Namespace, Resource, fields
from time_tracker_api.api import audit_fields
from faker import Faker

faker = Faker()

ns = Namespace('technologies', description='API for technologies used')

Expand All @@ -9,7 +12,8 @@
required=True,
title='Name',
max_length=50,
description='Name of the technology'
description='Name of the technology',
example=faker.word(['Java', 'Python', 'Elixir'])
),
})

Expand All @@ -19,6 +23,7 @@
required=True,
title='Identifier',
description='The unique identifier',
example=faker.uuid4()
),
}
technology_response_fields.update(audit_fields)
Expand Down
15 changes: 13 additions & 2 deletions time_tracker_api/time_entries/time_entries_namespace.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from flask_restplus import fields, Resource, Namespace
from time_tracker_api.api import audit_fields
from time_tracker_api import database
from faker import Faker

faker = Faker()

ns = Namespace('time-entries', description='API for time entries')

Expand All @@ -11,12 +14,14 @@
title='Project',
max_length=64,
description='The id of the selected project',
example=faker.uuid4()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the ids that are stored in the database are going to be integers because that is how SQL databases do it. So let's keep the ids as random integers of 4 digits maximum, at least for now. Later when we start doing migrations to uuid we do the change, but the representation has to be truth to real.

),
'activity_id': fields.String(
required=False,
title='Activity',
max_length=64,
description='The id of the selected activity',
example=faker.uuid4()
),
'technologies': fields.String(
required=True,
Expand All @@ -26,17 +31,20 @@
),
'description': fields.String(
title='Comments',
description='Comments about the time entry'
description='Comments about the time entry',
example=faker.paragraph()
),
'start_date': fields.DateTime(
required=True,
title='Start date',
description='When the user started doing this activity',
example=faker.iso8601(end_datetime=None)
),
'end_date': fields.DateTime(
required=True,
title='End date',
description='When the user ended doing this activity',
example=faker.iso8601(end_datetime=None)
),
})

Expand All @@ -46,11 +54,13 @@
required=True,
title='Identifier',
description='The unique identifier',
example=faker.uuid4()
),
'running': fields.Boolean(
readOnly=True,
title='Is it running?',
description='Whether this time entry is currently running or not'
description='Whether this time entry is currently running or not',
example=faker.boolean()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, running has to be true if the end_date has no value. I think that end_date has to have a value or not.

),
}
time_entry_response_fields.update(audit_fields)
Expand All @@ -64,6 +74,7 @@

model = database.create('time-entries')


@ns.route('')
class TimeEntries(Resource):
@ns.doc('list_time_entries')
Expand Down