-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
adding new "describe_api" command #1092
base: master
Are you sure you want to change the base?
The head ref may contain hidden characters: "Feature--new-command-\"describe_api\""
adding new "describe_api" command #1092
Conversation
How do I tie an issue to this? https://github.com/toastdriven/django-tastypie/issues/1091 |
Could I add myself to the AUTHORS is this is pulled? |
You should add yourself to AUTHORS as part of this pull request. |
@georgedorn thank you for your answer :-) |
RESOURCE_POSTFIX = 'Resource' | ||
|
||
|
||
def describe_api(app, **options): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function could use tests. Those would also help explain what this does and what to expect from it.
There are several test projects in the top-level tests module, each with apps and models already defined, so you could just add tests to an existing test project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So are you suggesting that I should pick one of those sample apps (say basic
) run the main function on it's app, write the output of that function to a file called api.py and then run some GET, POST, PUT, and DELETE http requests to it?
Maybe I should copy the test/basic to test/describe_api
first, delete the current api/resources.py
and modify the api/urls.py
then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm suggesting a test that uses the call_command() function to run the
command using one of the test projects' apps as input.
Sorta like how django has tests for the inspectdb command (
https://github.com/django/django/blob/master/tests/inspectdb/tests.py).
On Sat, Dec 7, 2013 at 6:00 PM, sesas notifications@github.com wrote:
In tastypie/management/commands/describe_api.py:
+class Command(AppCommand):
- help = "Generates tastypie resources for the given app that you should put in APP/api.py."
- args = "[appname]"
- label = "application name"
- def handle_app(self, app, **options):
# raise NotImplementedError()
return describe_api(app)
+FIELD_TEMPLATE = "{attribute_name} = fields.ForeignKey('{app_name}.api.{foreign_model}', '{attribute_name}'{options_str})"
+RESOURCE_POSTFIX = 'Resource'
+
+
+def describe_api(app, **options):So are you suggesting that I should pick one of those sample apps (say
basic) run the main function on it's app, write the output of that
function to a file called api.py and then run some GET, POST, PUT, and
DELETE http requests to it?Maybe I should copy the test/basic to test/describe_api first, delete the
current api/resources.py and modify the api/urls.py then.—
Reply to this email directly or view it on GitHubhttps://github.com/toastdriven/django-tastypie/pull/1092/files#r8183568
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the info and clarification. Do you think it would be necessary to test the auto-generated apis as well, or just making sure the string that comes out of it is the same as a predetermined one?
importing inspect felt superflous
in favor of django.db.models.get_models()
for even more power!
b3bf380
to
2efd0e3
Compare
cec6b98
to
77cad1b
Compare
Request for comments and feedback.