本文整理汇总了Python中models.team.Team.put方法的典型用法代码示例。如果您正苦于以下问题:Python Team.put方法的具体用法?Python Team.put怎么用?Python Team.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.team.Team
的用法示例。
在下文中一共展示了Team.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _upload_stats
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import put [as 别名]
def _upload_stats(team_name, stats):
query = Team.all()
query.filter('name =', team_name)
result = query.fetch(1)
if len(result) > 0:
for team in result:
team.year = Const.LAST_YEAR
team.offense_passing = stats['offense']['pass']
team.offense_rushing = stats['offense']['rush']
team.offense_first_down = stats['offense']['first_down']
team.defense_passing = stats['defense']['pass']
team.defense_rushing = stats['defense']['rush']
team.defense_first_down = stats['defense']['first_down']
team.put()
else:
team = Team(name = team_name,
year = Const.LAST_YEAR,
offense_passing = stats['offense']['pass'],
offense_rushing = stats['offense']['rush'],
offense_first_down = stats['offense']['first_down'],
defense_passing = stats['defense']['pass'],
defense_rushing = stats['defense']['rush'],
defense_first_down = stats['defense']['first_down'])
team.put()
示例2: setUp
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import put [as 别名]
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
event = Event(
id="2011ct",
end_date=datetime.datetime(2011, 4, 2, 0, 0),
event_short="ct",
event_type_enum=EventType.REGIONAL,
first_eid="5561",
name="Northeast Utilities FIRST Connecticut Regional",
start_date=datetime.datetime(2011, 3, 31, 0, 0),
year=2011,
venue_address="Connecticut Convention Center\r\n100 Columbus Blvd\r\nHartford, CT 06103\r\nUSA",
website="http://www.ctfirst.org/ctr"
)
event.put()
team = Team(
id="frc177",
team_number=177,
website="http://www.bobcatrobotics.org"
)
team.put()
event_team = EventTeam(
id="%s_%s" % (event.key.id(), team.key.id()),
event=event.key,
team=team.key,
year=None)
event_team.put()
示例3: TestTeamMediaApiController
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import put [as 别名]
class TestTeamMediaApiController(unittest2.TestCase):
def setUp(self):
app = webapp2.WSGIApplication([webapp2.Route(r'/<team_key:>/<year:>', ApiTeamMediaController, methods=['GET'])], debug=True)
self.testapp = webtest.TestApp(app)
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_urlfetch_stub()
self.testbed.init_memcache_stub()
self.testbed.init_taskqueue_stub(root_path=".")
self.team = Team(
id="frc254",
name="very long name",
team_number=254,
nickname="Teh Chezy Pofs",
address="Greenville, SC, USA"
)
self.team.put()
self.cdmedia = Media(
key=ndb.Key('Media', 'cdphotothread_39894'),
details_json=u'{"image_partial": "fe3/fe38d320428adf4f51ac969efb3db32c_l.jpg"}',
foreign_key=u'39894',
media_type_enum=1,
references=[ndb.Key('Team', 'frc254')],
year=2014)
self.cdmedia.put()
self.cddetails = dict()
self.cddetails["image_partial"] = "fe3/fe38d320428adf4f51ac969efb3db32c_l.jpg"
self.ytmedia = Media(
key=ndb.Key('Media', 'youtube_aFZy8iibMD0'),
details_json=None,
foreign_key=u'aFZy8iibMD0',
media_type_enum=0,
references=[ndb.Key('Team', 'frc254')],
year=2014)
self.ytmedia.put()
def tearDown(self):
self.testbed.deactivate()
def testTeamMediaApi(self):
response = self.testapp.get('/frc254/2014', headers={"X-TBA-App-Id": "tba-tests:team_media-controller-test:v01"})
media = json.loads(response.body)
self.assertEqual(len(media), 2)
cd = media[0]
self.assertEqual(cd["type"], "cdphotothread")
self.assertEqual(cd["foreign_key"], "39894")
self.assertEqual(cd["details"], self.cddetails)
yt = media[1]
self.assertEqual(yt["type"], "youtube")
self.assertEqual(yt["foreign_key"], "aFZy8iibMD0")
self.assertEqual(yt["details"], {})
示例4: TestTeamListApiController
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import put [as 别名]
class TestTeamListApiController(unittest2.TestCase):
def setUp(self):
app = webapp2.WSGIApplication([webapp2.Route(r'/<page_num:([0-9]*)>', ApiTeamListController, methods=['GET'])], debug=True)
self.testapp = webtest.TestApp(app)
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_urlfetch_stub()
self.testbed.init_memcache_stub()
self.testbed.init_taskqueue_stub(root_path=".")
self.team1 = Team(
id="frc123",
name="SomeName",
team_number=123,
nickname="SomeNickname",
address="San Jose, CA, USA",
website="www.website.com",
)
self.team2 = Team(
id="frc4567",
name="SomeName",
team_number=4567,
nickname="SomeNickname",
address="San Jose, CA, USA",
website="www.website.com",
)
self.team1.put()
self.team2.put()
def tearDown(self):
self.testbed.deactivate()
def assertTeam1Json(self, team):
self.assertEqual(team["key"], self.team1.key_name)
self.assertEqual(team["name"], self.team1.name)
self.assertEqual(team["team_number"], self.team1.team_number)
def assertTeam2Json(self, team):
self.assertEqual(team["key"], self.team2.key_name)
self.assertEqual(team["name"], self.team2.name)
self.assertEqual(team["team_number"], self.team2.team_number)
def testTeamListApi(self):
response = self.testapp.get('/0', headers={"X-TBA-App-Id": "tba-tests:team_list-controller-test:v01"})
team_list = json.loads(response.body)
self.assertTeam1Json(team_list[0])
response = self.testapp.get('/9', headers={"X-TBA-App-Id": "tba-tests:team_list-controller-test:v01"})
team_list = json.loads(response.body)
self.assertTeam2Json(team_list[0])
response = self.testapp.get('/10', headers={"X-TBA-App-Id": "tba-tests:team_list-controller-test:v01"})
team_list = json.loads(response.body)
self.assertEqual(team_list, [])
示例5: TestDistrictTeamsApiController
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import put [as 别名]
class TestDistrictTeamsApiController(unittest2.TestCase):
def setUp(self):
app = webapp2.WSGIApplication(
[webapp2.Route(r"/<district_abbrev:>/<year:([0-9]*)>", ApiDistrictTeamsController, methods=["GET"])],
debug=True,
)
self.testapp = webtest.TestApp(app)
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_urlfetch_stub()
self.testbed.init_memcache_stub()
ndb.get_context().clear_cache() # Prevent data from leaking between tests
self.testbed.init_taskqueue_stub(root_path=".")
self.team = Team(
id="frc281",
name="Michelin / Caterpillar / Greenville Technical College /\
jcpenney / Baldor / ASME / Gastroenterology Associates /\
Laserflex South & Greenville County Schools & Greenville\
Technical Charter High School",
team_number=281,
nickname="EnTech GreenVillians",
city="Greenville",
state_prov="SC",
country="USA",
website="www.entech.org",
motto="Infiltrating Young Minds One Robot at a Time",
)
self.district_team = DistrictTeam(id="2015ne_frc281", team=self.team.key, year=2015, district=3)
self.team.put()
self.district_team.put()
def tearDown(self):
self.testbed.deactivate()
def assertTeamJson(self, team):
team = team[0]
self.assertEqual(team["key"], self.team.key_name)
self.assertEqual(team["team_number"], self.team.team_number)
self.assertEqual(team["nickname"], self.team.nickname)
self.assertEqual(team["location"], self.team.location)
self.assertEqual(team["locality"], "Greenville")
self.assertEqual(team["country_name"], "USA")
self.assertEqual(team["region"], "SC")
self.assertEqual(team["website"], self.team.website)
self.assertEqual(team["motto"], self.team.motto)
def testDistrictsApi(self):
response = self.testapp.get(
"/ne/2015", headers={"X-TBA-App-Id": "tba-tests:team-districts-controller-test:v01"}
)
teams = json.loads(response.body)
self.assertTeamJson(teams)
示例6: create_entry_from_params
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import put [as 别名]
def create_entry_from_params(self, params):
new_team = Team(title = params["title"],
description = params["description"],
location = params["location"],
league = params["league"],
ref_id = params["ref_id"])
new_team.put()
return new_team
示例7: TestDatafeedUsfirstLegacyTeams
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import put [as 别名]
class TestDatafeedUsfirstLegacyTeams(unittest2.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_urlfetch_stub()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
self.datafeed = DatafeedUsfirstLegacy()
self.team177 = Team(
id="frc177",
team_number=177,
first_tpid=211521,
first_tpid_year=2014,
)
self.team177.put()
def tearDown(self):
self.testbed.deactivate()
def test_getTeamDetails(self):
team = self.datafeed.getTeamDetails(self.team177)
self.assertEqual(team.key.id(), 'frc177')
self.assertEqual(team.name, "United Technologies / ClearEdge Power / Gain Talent / EBA&D & South Windsor High School")
self.assertEqual(team.address, u"South Windsor, CT\xa0 USA")
self.assertEqual(team.nickname, "Bobcat Robotics")
self.assertEqual(team.rookie_year, 1995)
self.assertEqual(team.website, "http://www.bobcatrobotics.org")
def test_getTeamsTpids(self):
Team(
id="frc4409",
team_number=4409,
first_tpid=0, # should be 74735
first_tpid_year=2011
).put()
# We can skip 2000 records, paginate, and still get frc4409 and frc4410 in 2012
self.datafeed.getTeamsTpids(2012, skip=2000)
# Check new team insertion
frc4410 = Team.get_by_id("frc4410")
self.assertEqual(frc4410.team_number, 4410)
self.assertEqual(frc4410.first_tpid, 74193)
self.assertEqual(frc4410.first_tpid_year, 2012)
# Check old team updating
frc4409 = Team.get_by_id("frc4409")
self.assertEqual(frc4409.team_number, 4409)
self.assertEqual(frc4409.first_tpid, 74735)
self.assertEqual(frc4409.first_tpid_year, 2012)
示例8: TestDatafeedUsfirstTeams
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import put [as 别名]
class TestDatafeedUsfirstTeams(unittest2.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_urlfetch_stub()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
self.datafeed = DatafeedUsfirst()
self.team177 = Team(
id="frc177",
team_number=177,
first_tpid=61771,
first_tpid_year=2012
)
self.team177.put()
def tearDown(self):
self.testbed.deactivate()
def test_getTeamDetails(self):
team = self.datafeed.getTeamDetails(self.team177)
## Broken as result of FIRST website redesign -gregmarra 20151122
# self.assertEqual(team.name, "UTC Power/Ensign Bickford Aerospace & Defense & South Windsor High School")
# self.assertEqual(team.address, u"South Windsor, CT, USA")
# self.assertEqual(team.nickname, "Bobcat Robotics")
# self.assertEqual(team.website, "http://www.bobcatrobotics.org")
def test_getTeamsTpids(self):
Team(
id="frc4409",
team_number=4409,
first_tpid=0, # should be 74735
first_tpid_year=2011
).put()
# We can skip 2000 records, paginate, and still get frc4409 and frc4410 in 2012
self.datafeed.getTeamsTpids(2012, skip=2000)
# Check new team insertion
frc4410 = Team.get_by_id("frc4410")
self.assertEqual(frc4410.team_number, 4410)
self.assertEqual(frc4410.first_tpid, 74193)
self.assertEqual(frc4410.first_tpid_year, 2012)
# Check old team updating
frc4409 = Team.get_by_id("frc4409")
self.assertEqual(frc4409.team_number, 4409)
self.assertEqual(frc4409.first_tpid, 74735)
self.assertEqual(frc4409.first_tpid_year, 2012)
示例9: TestTeamApiController
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import put [as 别名]
class TestTeamApiController(unittest2.TestCase):
def setUp(self):
app = webapp2.WSGIApplication([webapp2.Route(r'/<team_key:>', ApiTeamController, methods=['GET'])], debug=True)
self.testapp = webtest.TestApp(app)
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_urlfetch_stub()
self.testbed.init_memcache_stub()
self.testbed.init_taskqueue_stub(root_path=".")
self.team = Team(
id="frc281",
name="Michelin / Caterpillar / Greenville Technical College /\
jcpenney / Baldor / ASME / Gastroenterology Associates /\
Laserflex South & Greenville County Schools & Greenville\
Technical Charter High School",
team_number=281,
rookie_year=1999,
nickname="EnTech GreenVillians",
city="Greenville",
state_prov="SC",
country="USA",
website="www.entech.org",
motto = "Infiltrating Young Minds One Robot at a Time",
)
self.team.put()
def tearDown(self):
self.testbed.deactivate()
def assertTeamJson(self, team):
self.assertEqual(team["key"], self.team.key_name)
self.assertEqual(team["team_number"], self.team.team_number)
self.assertEqual(team["nickname"], self.team.nickname)
self.assertEqual(team["location"], self.team.location)
self.assertEqual(team["locality"], "Greenville")
self.assertEqual(team["country_name"], "USA")
self.assertEqual(team["region"], "SC")
self.assertEqual(team["website"], self.team.website)
self.assertEqual(team["rookie_year"], self.team.rookie_year)
self.assertEqual(team["motto"], self.team.motto)
def testTeamApi(self):
response = self.testapp.get('/frc281', headers={"X-TBA-App-Id": "tba-tests:team-controller-test:v01"})
team_dict = json.loads(response.body)
self.assertTeamJson(team_dict)
示例10: TestTeamHistoryDistrictsApiController
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import put [as 别名]
class TestTeamHistoryDistrictsApiController(unittest2.TestCase):
def setUp(self):
app = webapp2.WSGIApplication([webapp2.Route(r'/<team_key:>', ApiTeamHistoryDistrictsController, methods=['GET'])], debug=True)
self.testapp = webtest.TestApp(app)
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_urlfetch_stub()
self.testbed.init_memcache_stub()
ndb.get_context().clear_cache() # Prevent data from leaking between tests
self.testbed.init_taskqueue_stub(root_path=".")
self.team = Team(
id="frc1124",
name="UberBots",
team_number=1124,
nickname="UberBots"
)
self.district_team = DistrictTeam(
id="2015ne_frc1124",
team=self.team.key,
year=2015,
district_key=ndb.Key(District, '2015ne')
)
self.district = District(
id='2015ne',
year=2015
)
self.team.put()
self.district_team.put()
self.district.put()
def tearDown(self):
self.testbed.deactivate()
def testDistrictsApi(self):
response = self.testapp.get('/frc1124', headers={"X-TBA-App-Id": "tba-tests:team-history-districts-controller-test:v01"})
district_dict = json.loads(response.body)
self.assertTrue("2015" in district_dict)
district_key = district_dict["2015"]
self.assertEqual(district_key, "2015ne")
示例11: TestTeamHistoryRobotsApiController
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import put [as 别名]
class TestTeamHistoryRobotsApiController(unittest2.TestCase):
def setUp(self):
app = webapp2.WSGIApplication([webapp2.Route(r'/<team_key:>', ApiTeamHistoryRobotsController, methods=['GET'])], debug=True)
self.testapp = webtest.TestApp(app)
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_urlfetch_stub()
self.testbed.init_memcache_stub()
ndb.get_context().clear_cache() # Prevent data from leaking between tests
self.testbed.init_taskqueue_stub(root_path=".")
self.team = Team(
id="frc1124",
name="UberBots",
team_number=1124,
nickname="UberBots"
)
self.robot = Robot(
id="frc1124_2015",
team=self.team.key,
year=2015,
robot_name="Orion"
)
self.team.put()
self.robot.put()
def tearDown(self):
self.testbed.deactivate()
def testRobotApi(self):
response = self.testapp.get('/frc1124', headers={"X-TBA-App-Id": "tba-tests:team_list-controller-test:v01"})
robot_dict = json.loads(response.body)
self.assertTrue("2015" in robot_dict)
robot = robot_dict["2015"]
self.assertEqual(robot["key"], "frc1124_2015")
self.assertEqual(robot["team_key"], "frc1124")
self.assertEqual(robot["year"], 2015)
self.assertEqual(robot["name"], "Orion")
示例12: TestTeamController
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import put [as 别名]
class TestTeamController(unittest2.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
app = webapp2.WSGIApplication([
RedirectRoute(r'/team/<team_number:[0-9]+>', TeamCanonical, 'team-canonical'),
RedirectRoute(r'/team/<team_number:[0-9]+>/<year:[0-9]+>', TeamDetail, 'team-detail'),
RedirectRoute(r'/team/<team_number:[0-9]+>/history', TeamHistory, 'team-history'),
RedirectRoute(r'/teams/<page:[0-9]+>', TeamList, 'team-list-year'),
RedirectRoute(r'/teams', TeamList, 'team-list'),
])
self.testapp = webtest.TestApp(app)
self.team = Team(
id="frc1124",
name="Really Long Name",
team_number=1124,
rookie_year=2003,
nickname="The UberBots",
city="Avon",
state_prov="CT",
country="USA",
website="www.uberbots.org",
motto="This is a motto",
)
self.event = Event(
id="2016necmp",
name="New England District Championship",
event_type_enum=EventType.DISTRICT_CMP,
short_name="New England",
event_short="necmp",
year=2016,
end_date=datetime(2016, 03, 27),
official=True,
city='Hartford',
state_prov='CT',
country='USA',
venue="Some Venue",
venue_address="Some Venue, Hartford, CT, USA",
timezone_id="America/New_York",
start_date=datetime(2016, 03, 24),
)
self.event_team = EventTeam(
id="2016necmp_frc1124",
team=self.team.key,
event=self.event.key,
year=2016
)
self.event2 = Event(
id="2015necmp",
name="New England District Championship",
event_type_enum=EventType.DISTRICT_CMP,
short_name="New England",
event_short="necmp",
year=2015,
end_date=datetime(2015, 03, 27),
official=True,
city='Hartford',
state_prov='CT',
country='USA',
venue="Some Venue",
venue_address="Some Venue, Hartford, CT, USA",
timezone_id="America/New_York",
start_date=datetime(2015, 03, 24),
)
self.event_team2 = EventTeam(
id="2015necmp_frc1124",
team=self.team.key,
event=self.event2.key,
year=2015
)
self.event_team.put()
self.team.put()
self.event.put()
self.event_team.put()
self.event2.put()
self.event_team2.put()
def tearDown(self):
self.testbed.deactivate()
def testTeamListDefaultPage(self):
response = self.testapp.get("/teams")
self.assertEqual(response.status_int, 200)
def testTeamListExplicitPage(self):
response = self.testapp.get("/teams/1")
self.assertEqual(response.status_int, 200)
def testTeamListBadPage(self):
response = self.testapp.get("/teams/19", status=404)
self.assertEqual(response.status_int, 404)
def testTeamCanonical(self):
response = self.testapp.get("/team/1124")
self.assertEqual(response.status_int, 200)
def testBadTeamCanonical(self):
#.........这里部分代码省略.........
示例13: TestTeamAdminRedeem
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import put [as 别名]
class TestTeamAdminRedeem(unittest2.TestCase):
def setUp(self):
self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(
probability=1)
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)
self.testbed.init_memcache_stub()
self.testbed.init_user_stub()
self.testbed.init_urlfetch_stub()
self.testbed.init_taskqueue_stub(_all_queues_valid=True)
ndb.get_context().clear_cache(
) # Prevent data from leaking between tests
app = webapp2.WSGIApplication([
RedirectRoute(
r'/mod/redeem',
TeamAdminRedeem,
'team-admin',
strict_slash=True),
])
self.testapp = webtest.TestApp(app)
self.team = Team(
id="frc1124",
name="Team",
team_number=1124,
)
self.team.put()
self.now = datetime.datetime.now()
def tearDown(self):
self.testbed.deactivate()
def loginUser(self):
self.testbed.setup_env(
user_email="[email protected]",
user_id="123",
user_is_admin='0',
overwrite=True)
self.account = Account.get_or_insert(
"123", email="[email protected]", registered=True)
def addTeamAdminAccess(self, account, team_number=1124):
access = TeamAdminAccess(
id="test_access",
access_code="abc123",
team_number=team_number,
year=self.now.year,
expiration=self.now + datetime.timedelta(days=1),
account=account,
)
return access.put()
def getForm(self):
response = self.testapp.get('/mod/redeem')
self.assertEqual(response.status_int, 200)
form = response.forms.get('redeem', None)
self.assertIsNotNone(form)
return form
def test_login_redirect(self):
response = self.testapp.get('/mod/redeem', status='3*')
response = response.follow(expect_errors=True)
self.assertTrue(
response.request.path.startswith("/account/login_required"))
def test_cant_redeem_with_code_linked(self):
self.loginUser()
access_key = self.addTeamAdminAccess(account=self.account.key)
response = self.testapp.get('/mod/redeem')
self.assertEqual(response.status_int, 200)
# If there's an existing code linked, the form shouldn't render
form = response.forms.get('redeem', None)
self.assertIsNone(form)
def test_redeem_bad_code(self):
self.loginUser()
form = self.getForm()
form['auth_code'] = 'abc123'
response = form.submit().follow()
self.assertEqual(response.request.GET['status'], 'invalid_code')
def test_redeem_no_team(self):
self.loginUser()
access_key = self.addTeamAdminAccess(account=None)
form = self.getForm()
form['auth_code'] = 'abc123'
response = form.submit().follow()
self.assertEqual(response.request.GET['status'], 'invalid_code')
def test_redeem_garbage_team(self):
self.loginUser()
#.........这里部分代码省略.........
示例14: TestTeamListApiController
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import put [as 别名]
class TestTeamListApiController(unittest2.TestCase):
def setUp(self):
app = webapp2.WSGIApplication(
[webapp2.Route(r"/<page_num:([0-9]*)>", ApiTeamListController, methods=["GET"])], debug=True
)
self.testapp = webtest.TestApp(app)
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_urlfetch_stub()
self.testbed.init_memcache_stub()
ndb.get_context().clear_cache() # Prevent data from leaking between tests
self.testbed.init_taskqueue_stub(root_path=".")
self.team1 = Team(
id="frc123",
name="SomeName",
team_number=123,
nickname="SomeNickname",
city="San Jose",
state_prov="CA",
country="USA",
website="www.website.com",
)
self.team2 = Team(
id="frc4567",
name="SomeName",
team_number=4567,
nickname="SomeNickname",
city="San Jose",
state_prov="CA",
country="USA",
website="www.website.com",
)
self.team1.put()
self.team2.put()
def tearDown(self):
self.testbed.deactivate()
def assertTeam1Json(self, team):
self.assertEqual(team["key"], self.team1.key_name)
self.assertEqual(team["name"], self.team1.name)
self.assertEqual(team["team_number"], self.team1.team_number)
def assertTeam2Json(self, team):
self.assertEqual(team["key"], self.team2.key_name)
self.assertEqual(team["name"], self.team2.name)
self.assertEqual(team["team_number"], self.team2.team_number)
def testTeamListApi(self):
response = self.testapp.get("/0", headers={"X-TBA-App-Id": "tba-tests:team_list-controller-test:v01"})
team_list = json.loads(response.body)
self.assertTeam1Json(team_list[0])
response = self.testapp.get("/9", headers={"X-TBA-App-Id": "tba-tests:team_list-controller-test:v01"})
team_list = json.loads(response.body)
self.assertTeam2Json(team_list[0])
response = self.testapp.get("/10", headers={"X-TBA-App-Id": "tba-tests:team_list-controller-test:v01"})
team_list = json.loads(response.body)
self.assertEqual(team_list, [])
示例15: TestApiTeamShow
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import put [as 别名]
class TestApiTeamShow(unittest2.TestCase):
# TODO: Add event_keys testing. -brandondean 10/21/2012
def setUp(self):
app = webapp2.WSGIApplication([(r'/', ApiTeamsShow)], debug=True)
self.testapp = webtest.TestApp(app)
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_urlfetch_stub()
self.testbed.init_memcache_stub()
self.testbed.init_taskqueue_stub()
self.team = Team(
id="frc281",
name="Michelin / Caterpillar / Greenville Technical College /\
jcpenney / Baldor / ASME / Gastroenterology Associates /\
Laserflex South & Greenville County Schools & Greenville\
Technical Charter High School",
team_number=281,
nickname="EnTech GreenVillians",
address="Greenville, SC, USA",
website="www.entech.org",
)
self.team.put()
self.event = Event(
id="2010sc",
name="Palmetto Regional",
event_type_enum=EventType.REGIONAL,
short_name="Palmetto",
event_short="sc",
year=2010,
end_date=datetime(2010, 03, 27),
official=True,
location='Clemson, SC',
start_date=datetime(2010, 03, 24),
)
self.event.put()
self.event_team = EventTeam(
team=self.team.key,
event=self.event.key,
year=datetime.now().year
)
self.event_team.put()
def tearDown(self):
self.testbed.deactivate()
def assertTeamJson(self, team_dict):
self.assertEqual(team_dict["key"], self.team.key_name)
self.assertEqual(team_dict["team_number"], self.team.team_number)
self.assertEqual(team_dict["nickname"], self.team.nickname)
self.assertEqual(team_dict["location"], self.team.location)
self.assertEqual(team_dict["locality"], "Greenville")
self.assertEqual(team_dict["country_name"], "USA")
self.assertEqual(team_dict["region"], "SC")
self.assertEqual(team_dict["website"], self.team.website)
self.assertTrue(self.event.key.id() in team_dict["events"])
def testTeamShow(self):
response = self.testapp.get('/?teams=frc281', headers={"User-Agent": "tests"})
team_dict = json.loads(response.body)
self.assertTeamJson(team_dict[0])
def testNonexistentTeam(self):
response = self.testapp.get('/?teams=frc3141579265', headers={"User-Agent": "tests"}, status=404)
self.assertEqual(response.status_int, 404)
def test_validate_user_agent(self):
response = self.testapp.get('/?teams=frc254', expect_errors=True) # By default get() doesn't send a user agent
self.assertEqual(response.status, "400 Bad Request")
self.assertEqual(response.body, '{"Error": "User-Agent is a required header."}')