-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
executable file
·82 lines (66 loc) · 2.89 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import unittest
import os
import webapp2
import webtest
from google.appengine.ext import testbed
import ConfigParser
#from boilerplate.lib import utils
from test_tools import test_helpers
# setting HTTP_HOST in extra_environ parameter for TestApp is not enough for taskqueue stub
from test_tools import config, routes
from ebay_items import EbayItems
from models import EbayItem
import settings
os.environ['HTTP_HOST'] = 'localhost'
class AppTest(unittest.TestCase, test_helpers.HandlerHelpers):
def setUp(self):
webapp2_config = config.config
# create a WSGI application.
self.app = webapp2.WSGIApplication(config=webapp2_config)
routes.add_routes(self.app)
# boilerplate_routes.add_routes(self.app)
self.testapp = webtest.TestApp(self.app, extra_environ={'REMOTE_ADDR': '127.0.0.1'})
# activate GAE stubs
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
self.testbed.init_urlfetch_stub()
self.testbed.init_taskqueue_stub()
self.testbed.init_mail_stub()
self.testbed.init_blobstore_stub()
self.testbed.init_modules_stub()
self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
self.taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
self.testbed.init_user_stub()
cfg = ConfigParser.ConfigParser(allow_no_value=True)
cfg.read(settings.EBAY_API_SETTINGS_FILE)
self.headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) Version/6.0 Safari/536.25',
'Accept-Language': 'en_US'}
# fix configuration if this is still a raw boilerplate code - required by test with mails
# if not utils.is_email_valid(self.app.config.get('contact_sender')):
# self.app.config['contact_sender'] = "noreply-testapp@example.com"
# if not utils.is_email_valid(self.app.config.get('contact_recipient')):
# self.app.config['contact_recipient'] = "support-testapp@example.com"
def tearDown(self):
self.testbed.deactivate()
def test_homepage(self):
response = self.get('/')
self.assertIn('eBay Items', response)
def test_item_search(self):
search_term = 'iphone'
category = 'default'
condition = 'Used'
max_price = '1000'
Zip = '27104'
data = EbayItems.search_items(search_term=search_term,
category=category,
condition=condition,
max_price=max_price,
Zip=Zip)
self.assertIn(search_term, str(data))
def test_update_items(self):
EbayItem.update_items()
self.assertEqual(True, True)
if __name__ == "__main__":
unittest.main()