問題タブ [django-unittest]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
python - ビュークラスからDjangoリダイレクトをテストする方法
私は Django atm を学んでいて、単純なテスト ケースの作成に行き詰まっています。
次のビューをテストするにはどうすればよいですか? ユーザーがすでにログインしている場合は、リスト ビューにリダイレクトされます。
これまでのところ、作成したテストは次のようになります。
最初のアサーションは成功しましたが、すでにログインしている場合にユーザーをリダイレクトする必要がある 2 番目のアサーションでこのエラーがスローされます
私は何を間違っていますか?
django - django tests response.request.user.is_authenticated() returning True after logout
I am trying to write some tests for the authentication part of my application and I encountered a problem with checking if the user is logged in or not. Here's the code:
The user fills the form and clicks submit, then receives an email with a verification url. After he clicks the verification url in the email he's supposed to get directed to the site and authenticated. My questions is, what is a good way to find out if the user is authenticated or not? What is a preferred way to log out a user in this situation? I want to check that if the user is logged out and clicks the link the verification link second time it doesn't work. I tried some things like:
But unfortunately it seems to work once every two times even when I remove this line.
Thanks for any help!
django - Python モックが django unittest client.session をシャドウ request.session にすることは可能ですか?
内部 API にアクセスし、セッションで値を設定する単体テストがあります。
例えば。
今私がそれをテストするために:
私の質問は、MagicMock のようなライブラリを使用して、self.client.session を request.session のシャドウにすることができるかどうかです。
django - テスト中の Django WebServer
Django で複雑な Web アプリケーションを作成しています。多くのコンポーネントがあります。特に 2 つは、Django サーバー (lets call this ) と、計算を に提供するServer
C++ アプリケーション サーバー (lets call this )です。計算が必要な場合は、リッスンしているソケットにコマンドを送信します。このような:Calculator
Server
Server
Calculator
現在、Calculator
その作業を行うために、さまざまな時点でさまざまな情報が必要になる場合があります。Calaculator
したがって、コマンドで直接データを渡す代わりに、Calculator
必要なものを尋ねる必要があります。これは、上で RESTful API を呼び出すことによって行われますServer
。
Calculator
次に、この呼び出しからのデータを使用して計算を行いServer
、応答で応答します。
Djangos unittest フレームワークを使用して単体テストを実行しようとすると、問題が発生します。テストで一連のデータ構造をセットアップしましたが、 をServer
呼び出すときCalculator
に、必要なものを取得できるように、REST API でこのデータを使用Calculator
できるようにする必要があります。問題は、Django テスト フレームワークが Web サーバーを起動しないことです。これを手動で行うと、テスト ケースではなく、実際のデータベースからデータが読み取られます。
外部の人/プロセスが利用できるデータを使用して単体テストを実行する方法を知っている人はいますか?
それが理にかなっていることを願っています...
python - Django でサードパーティ サーバーからの応答をシミュレートする
私は呼び出しを行う関数を持っています:
次の方法で JSON リストをフェッチします: [ { id: 1, name: 'abc', }, { id: 2, name: 'def', } ]
次に、関数はフェッチされた配列内のオブジェクトをループし、さらに呼び出しを行います
テストのために、サードパーティ ドメイン API を呼び出したくはありません。その代わりに、LISt および DETAILS API の既知の応答でそれを偽装します。
Djangoでこれを行うにはどうすればよいですか?
python - 単体テストでdjangoアプリの設定を上書きするには?
Django では、テストを実行するときに設定を上書きできますSimpleTestCase.settings()
( https://docs.djangoproject.com/en/1.8/topics/testing/tools/#django.test.SimpleTestCase.settings )。Django の設定の 1 つを上書きしようとすると、うまくいきます。
テストを実行したいアプリsettings.py
は、プロジェクト全体でアプリ固有の設定を上書きできるように、次の構造を持つアプリ固有の独自の設定を実行しsettings.py
ます。
テストの次のダミー コードは、問題を示しています。
なぜそれが機能しないのですか?どうすれば機能させることができますか?
python - django.db.utils.DatabaseError: (1146、「テーブル 'test_xxx.django_content_type' が存在しません」)
django unittest を実行すると、次のエラーが発生します。
私が間違っているかもしれないことを教えてください。
これは INSTALLED_APPS の順序と関係がありますか?