2011-10-21 15 views
2

私はweb2pyでGAEアプリを構築しており、テストフレームワークの設定には苦労しています。 私はに見てきた:Web2py Google App Engine Testing

  • web2py_utils
  • nosegae
  • たGoogle社員猪飼蘭のGAEにマージされました
  • gaetestbedsuggestionsはここ

をAPISユニットテストIです試みた:

import unittest 
import nose 
from nose.tools import * 
from google.appengine.ext import testbed 
from google.appengine.datastore import datastore_stub_itil 

class UserModelTest(unittest.TestCase): 
    def setUp(self): 
     # First, create an instance of the Testbed class. 
     self.testbed = testbed.Testbed() 
     # Then activate the testbed, which prepares the service stubs for use. 
     self.testbed.activate() 
     # Initialize the datastore stub with this policy. 
     self.testbed.init_datastore_v3_stub(consistency_policy=self.policy) 

     self.env = new_env(app='fb', controller='default') 
     self.db = copy_db(self.env, db_name='db', db_link='sqlite:memory') 

     self.user = self.db.auth_user.insert(first_name='Bob', last_name='Narley', fb_id=1, password='testtest') 
     self.dream = self.db.dream.insert(title='Graduate UC Santa Cruz with Computer Science degree by June 8, 2012.', 
     type='education', owner = self.user, progress=92.0) 
     self.task1 = self.db.task.insert(dream=self.dream, title='Buy batteries for calculator', solution='Go to Walmart at 12:00pm October 30, 2012 and buy Duracell AAA.', 
     status=1) 
     self.task2 = self.db.task.insert(dream=self.dream, title='Make Winston happy', 
         solution='Make banana milk', 
         status=0) 
     self.user.update_record(tasks=[self.task1, self.task2]) 

    def tearDown(self): 
     self.testbed.deactivate() 

    def test_create_user(self): 
     assert_equal('Bob', self.user.first_name) 
     assert_equal(1, self.user.fb_id) 
     assert_equal('testtest', self.user.password) 

    def test_user_has_many_tasks(self): 
     tasks = self.db(self.db.task.id.belongs(self.user.tasks)).select() 
     assert_equal(2, len(tasks)) 

run_fb_tests.py:

from web2py_utils.test_runner import run 
import sys 

run(path = sys.path[0], 
    app = 'fb', 
    test_key = 'superSecret', 
    test_options = {'verbosity': 3, 'with-gae': True, 'without-sandbox': True}, 
    coverage_report = 'logs/coverage_report.txt', 
    DO_COVER = True, 
    DO_NOSE = True,) 

私run_fb_tests.py

はImportError実行すると、私は次のエラーを取得する:

google.appengine.extという名前のモジュールを私は多くの間違いで数日前から頭を叩いていました。これは多くのうちの1つです

GAEアプリケーション用のテストフレームワークをweb2pyに設定するにはどうすればよいですか?

+0

+1私は1つの配備http://joeyonlinecorner.appspot.comでweb2pyを選んだので興味があります。たとえば、wikiやブログのようなものを追加したいのですが、web2pyプラグインを入手できませんでしたweb2pyの作者がGAEを使って少なくとも1つのプラグインをテストしたと言っても、GAEを使うことができます。 google web2pyグループに投稿すると、著者はあなたの質問と回答を読むことができます。 –

+0

'run()'を呼び出す前に 'print sys.path'を置いたときに何が表示されますか?そのパスにgoogle.appengineはありますか?コードには特に除外されているものはありませんので、スクリプトがApp Engineのパッケージの場所を認識していないのかどうか疑問に思っています。 –

答えて

0

あなたのスクリプトはどこですか?run_fb_tests.pyはどこですか?それがweb2pyフォルダにある場合も同様のエラーが発生しますが、google_appenine、またはgoogle_appengineの格納フォルダに配置すると、インポートエラーは発生しません。