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

Issue django shell commands // create/update models #23

Open
Eraldo opened this issue Jan 18, 2016 · 2 comments
Open

Issue django shell commands // create/update models #23

Eraldo opened this issue Jan 18, 2016 · 2 comments

Comments

@Eraldo
Copy link

Eraldo commented Jan 18, 2016

How can I create or update django models from within the engine?

I know
I do know that I have access to the django service:
self.services['Django'] = hitchpython.DjangoService(...

I want
I want to use this to define assumptions for my tests instead of using fixtures.
(However I have not tried using fixtures either nor do I now how that would go about)

I envision
I figured the easiest way would be to use my test factories to create the wanted models and update them according to the test assumptions.

next steps
Any suggestions or ideas on how to go about?

personal context
Today.. I will give a talk about ATDD with hitch at the Berlin Django User Group..
So I decided, that I want to know more to help hitch get more users and thus as a bonus improve my test engine of choice. ;)

Your help is appreciated. :D

@crdoconnor
Copy link
Contributor

Hi @Eraldo!

If you would prefer to write some django code to funnel data into your app that uses models directly before running the first step you can create a Django management command which you can run at the end of set_up somewhere:

self.services['Django'].manage("createfakedata").run()

Docs on creating Django management commands are here: https://docs.djangoproject.com/en/1.9/howto/custom-management-commands/

If you want to feed variables to your management command on a per test basis, you can put them in preconditions:

- name :  my scenario
  preconditions:
    myvar: myval

Which you can then feed as a variable to the management command as follows:

self.services['Django'].manage("createfakedata", self.preconditions['myvar']).run()

Today.. I will give a talk about ATDD with hitch at the Berlin Django User Group.. Do I decided, that I want to know more to help hitch get more users and thus as a bonus improve my test engine of choice. ;)

That's awesome! Thanks!

@Eraldo
Copy link
Author

Eraldo commented Jan 22, 2016

Nice..
I will play around with that and report back.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants