14
Djangoサイトには管理用のコマンドとcronジョブ上で実行するコマンドがあり、テスト方法を理解することはできません。彼らはかなりは次のようになります。UnitTest/WebTestのPython/Django管理コマンドを実行する
# Saved in file /app/management/commands/some_command.py
# Usage: python manage.py some_command
from django.core.management.base import NoArgsCommand
class Command(NoArgsCommand):
def handle_noargs(self, **options):
# Do something useful
そして、私はこのように見えるいくつかのテスト、持っている:私のテストで
import unittest
from django.test import TestCase
from django_webtest import WebTest
class SomeTest(WebTest):
fixtures = ['testdata.json']
def setUp(self):
self.open_in_browser = False
# Set up some objects
def test_registration(self):
response = self.client.get('/register/')
self.assertEqual(response.status_code, 200)
form = self.app.get('/register/').forms[1]
# Set up the form
response = form.submit()
self.assertContains(response, 'You are Registered.')
if self.open_in_browser:
response.showbrowser()
# Here I'd like to run some_command to see the how it affects my new user.
を(私がコメントを持っているところ)私は私のNoArgsCommandを実行したいのですが私の新しいユーザに何が起こるかを知る。私はこれを達成するための文書や例を見つけることができません。また、私のテスト環境はSQLlite DBであり、メモリ内で最初から作成し、いくつかのフィクスチャとオブジェクトをロードしてテストを実行するので、実際のDBにデータをセットアップしたいだけで、コマンドラインからのコマンド、私はできません、それはあまりにも時間がかかります。どんなアイデアでも大歓迎です。
RTFM、DOH:
は、基本的にはこのようなものが必要!ありがとう、私はそれが存在していたことに気づいていませんでした。 – scoopseven
特に金曜には、私たち全員に起こります。もちろん、大歓迎です! – kgr
ありがとう! Visual Studioから単体テストを実行しようとしていて、参照リンクをたどるまで取得できませんでした。 – TurboGus