本文整理汇总了Python中models.match.Match.put方法的典型用法代码示例。如果您正苦于以下问题:Python Match.put方法的具体用法?Python Match.put怎么用?Python Match.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.match.Match
的用法示例。
在下文中一共展示了Match.put方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestEventMatchApiController
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import put [as 别名]
class TestEventMatchApiController(unittest2.TestCase):
def setUp(self):
app = webapp2.WSGIApplication([webapp2.Route(r'/<event_key:>', ApiEventMatchesController, 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.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.match = Match(
id="2010sc_qm1",
alliances_json="""{"blue": {"score": 57, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": 74, "teams": ["frc281", "frc571", "frc176"]}}""",
comp_level="qm",
event=self.event.key,
year=2010,
set_number=1,
match_number=1,
team_key_names=[u'frc281', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073'],
youtube_videos=["94UGXIq6jUA"],
tba_videos=[".mp4"],
time=datetime.fromtimestamp(1409527874)
)
self.match.put()
def tearDown(self):
self.testbed.deactivate()
def assertMatchJson(self, matches):
match = matches[0]
self.assertEqual(str(match["key"]), self.match.key.string_id())
self.assertEqual(match["comp_level"], self.match.comp_level)
self.assertEqual(match["event_key"], self.match.event.string_id())
self.assertEqual(match["set_number"], self.match.set_number)
self.assertEqual(match["match_number"], self.match.match_number)
self.assertEqual(match["videos"], self.match.videos)
self.assertEqual(match["time_string"], self.match.time_string)
self.assertEqual(match["time"], 1409527874)
def testEventMatchApi(self):
response = self.testapp.get('/2010sc', headers={"X-TBA-App-Id": "tba-tests:event-controller-test:v01"})
match_json = json.loads(response.body)
self.assertMatchJson(match_json)
示例2: TestDatafeedUsfirstTeams
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import put [as 别名]
class TestDatafeedUsfirstTeams(unittest2.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
self.event = Event(
id="2010sc",
name="Palmetto Regional",
event_type_enum=EventType.REGIONAL,
short_name="Palmetto",
event_short="sc",
year=2010,
end_date=datetime.datetime(2010, 03, 27),
official=True,
location='Clemson, SC',
start_date=datetime.datetime(2010, 03, 24),
)
self.event.put()
self.match = Match(
id="2010sc_qm1",
alliances_json="""{"blue": {"score": -1, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": -1, "teams": ["frc69", "frc571", "frc176"]}}""",
comp_level="qm",
event=self.event.key,
year=2010,
set_number=1,
match_number=1,
team_key_names=[u'frc69', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073']
)
self.match.put()
def tearDown(self):
self.testbed.deactivate()
示例3: TestMatchSuggestionAccepter
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import put [as 别名]
class TestMatchSuggestionAccepter(unittest2.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_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.account = Account(
email="[email protected]",
)
self.account.put()
self.suggestion = Suggestion(
author=self.account.key,
contents_json="{\"youtube_videos\":[\"123456\"]}",
target_key="2012ct_qm1",
target_model="match"
)
self.suggestion.put()
self.event = Event(
id="2012ct",
event_short="ct",
year=2012,
event_type_enum=EventType.REGIONAL,
)
self.event.put()
self.match = Match(
id="2012ct_qm1",
alliances_json="""{"blue": {"score": -1, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": -1, "teams": ["frc69", "frc571", "frc176"]}}""",
comp_level="qm",
event=self.event.key,
year=2012,
set_number=1,
match_number=1,
team_key_names=[u'frc69', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073'],
youtube_videos=["abcdef"]
)
self.match.put()
def tearDown(self):
self.testbed.deactivate()
def test_accept_suggestions(self):
MatchSuggestionAccepter.accept_suggestion(self.match, self.suggestion)
match = Match.get_by_id("2012ct_qm1")
self.assertTrue("abcdef" in match.youtube_videos)
self.assertTrue("123456" in match.youtube_videos)
示例4: TestDatafeedUsfirstTeams
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import put [as 别名]
class TestDatafeedUsfirstTeams(unittest2.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
self.event = Event(
id = "2010sc",
name = "Palmetto Regional",
event_type = "Regional",
short_name = "Palmetto",
event_short = "sc",
year = 2010,
end_date = datetime.datetime(2010, 03, 27),
official = True,
location = 'Clemson, SC',
start_date = datetime.datetime(2010, 03, 24),
)
self.event.put()
self.match = Match(
id = "2010sc_qm1",
alliances_json = """{"blue": {"score": -1, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": -1, "teams": ["frc69", "frc571", "frc176"]}}""",
comp_level = "qm",
event = self.event.key,
game = "frc_2010_bkwy",
set_number = 1,
match_number = 1,
team_key_names = [u'frc69', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073']
)
self.match.put()
def tearDown(self):
self.testbed.deactivate()
def test_doEventTeamUpdate(self):
# call EventTeamUpdate with 2010sc
eventteamupdate = EventTeamUpdate()
eventteamupdate.response = Response()
eventteamupdate.get("2010sc")
# Teams were generated by EventTeamUpdate, make sure EventTeams
# exist and feature Team Keys
event_team_from_match_one = EventTeam.get_by_id("2010sc_frc69")
self.assertEqual(event_team_from_match_one.event, self.event.key)
self.assertEqual(event_team_from_match_one.team, ndb.Key(Team, "frc69"))
event_team_from_match_two = EventTeam.get_by_id("2010sc_frc20")
self.assertEqual(event_team_from_match_two.event, self.event.key)
self.assertEqual(event_team_from_match_two.team, ndb.Key(Team, "frc20"))
示例5: test_match_videos_add
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import put [as 别名]
def test_match_videos_add(self):
self.video_auth.put()
match1 = Match(
id="2014casj_qm1",
alliances_json="""{"blue": {"score": -1, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": -1, "teams": ["frc69", "frc571", "frc176"]}}""",
comp_level="qm",
event=ndb.Key(Event, '2014casj'),
year=2014,
set_number=1,
match_number=1,
team_key_names=[u'frc69', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073'],
youtube_videos=["abcdef"]
)
match1.put()
match2 = Match(
id="2014casj_sf1m1",
alliances_json="""{"blue": {"score": -1, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": -1, "teams": ["frc69", "frc571", "frc176"]}}""",
comp_level="sf",
event=ndb.Key(Event, '2014casj'),
year=2014,
set_number=1,
match_number=1,
team_key_names=[u'frc69', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073'],
)
match2.put()
match_videos = {'qm1': 'aFZy8iibMD0', 'sf1m1': 'RpSgUrsghv4'}
request_body = json.dumps(match_videos)
request_path = '/api/trusted/v1/event/2014casj/match_videos/add'
sig = md5.new('{}{}{}'.format('321tEsTsEcReT', request_path, request_body)).hexdigest()
response = self.testapp.post(request_path, request_body, headers={'X-TBA-Auth-Id': 'tEsT_id_5', 'X-TBA-Auth-Sig': sig}, expect_errors=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(set(Match.get_by_id('2014casj_qm1').youtube_videos), {'abcdef', 'aFZy8iibMD0'})
self.assertEqual(set(Match.get_by_id('2014casj_sf1m1').youtube_videos), {'RpSgUrsghv4'})
示例6: TestMatchManipulator
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import put [as 别名]
class TestMatchManipulator(unittest2.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
self.event = Event(
id = "2012ct",
event_short = "ct",
year = 2012
)
self.old_match = Match(
id = "2012ct_qm1",
alliances_json = """{"blue": {"score": -1, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": -1, "teams": ["frc69", "frc571", "frc176"]}}""",
comp_level = "qm",
event = self.event.key,
game = "frc_2012_rebr",
set_number = 1,
match_number = 1,
team_key_names = [u'frc69', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073']
)
self.new_match = Match(
id = "2012ct_qm1",
alliances_json = """{"blue": {"score": 57, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": 74, "teams": ["frc69", "frc571", "frc176"]}}""",
comp_level = "qm",
event = self.event.key,
game = "frc_2012_rebr",
set_number = 1,
match_number = 1,
team_key_names = [u'frc69', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073']
)
def tearDown(self):
self.testbed.deactivate()
def assertMergedMatch(self, match):
self.assertOldMatch(match)
self.assertEqual(match.alliances_json, """{"blue": {"score": 57, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": 74, "teams": ["frc69", "frc571", "frc176"]}}""")
def assertOldMatch(self, match):
self.assertEqual(match.comp_level, "qm")
self.assertEqual(match.set_number, 1)
self.assertEqual(match.match_number, 1)
self.assertEqual(match.team_key_names, [u'frc69', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073'])
def test_createOrUpdate(self):
MatchManipulator.createOrUpdate(self.old_match)
self.assertOldMatch(Match.get_by_id("2012ct_qm1"))
self.assertEqual(Match.get_by_id("2012ct_qm1").alliances_json, """{"blue": {"score": -1, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": -1, "teams": ["frc69", "frc571", "frc176"]}}""")
MatchManipulator.createOrUpdate(self.new_match)
self.assertMergedMatch(Match.get_by_id("2012ct_qm1"))
def test_findOrSpawn(self):
self.old_match.put()
self.assertMergedMatch(MatchManipulator.findOrSpawn(self.new_match))
def test_updateMerge(self):
self.assertMergedMatch(MatchManipulator.updateMerge(self.new_match, self.old_match))
示例7: TestMatchManipulator
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import put [as 别名]
class TestMatchManipulator(unittest2.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
self.testbed.init_taskqueue_stub()
self.event = Event(
id="2012ct",
event_short="ct",
year=2012
)
self.old_match = Match(
id="2012ct_qm1",
alliances_json="""{"blue": {"score": -1, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": -1, "teams": ["frc69", "frc571", "frc176"]}}""",
comp_level="qm",
event=self.event.key,
game="frc_2012_rebr",
set_number=1,
match_number=1,
team_key_names=[u'frc69', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073'],
youtube_videos=[u'P3C2BOtL7e8', u'tst1', u'tst2', u'tst3']
)
self.new_match = Match(
id="2012ct_qm1",
alliances_json="""{"blue": {"score": 57, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": 74, "teams": ["frc69", "frc571", "frc176"]}}""",
comp_level="qm",
event=self.event.key,
game="frc_2012_rebr",
set_number=1,
match_number=1,
team_key_names=[u'frc69', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073'],
youtube_videos=[u'TqY324xLU4s', u'tst1', u'tst3', u'tst4']
)
def tearDown(self):
self.testbed.deactivate()
def assertMergedMatch(self, match, is_auto_union):
self.assertOldMatch(match)
self.assertEqual(match.alliances_json, """{"blue": {"score": 57, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": 74, "teams": ["frc69", "frc571", "frc176"]}}""")
if is_auto_union:
self.assertEqual(set(match.youtube_videos), {u'P3C2BOtL7e8', u'TqY324xLU4s', u'tst1', u'tst2', u'tst3', u'tst4'})
else:
self.assertEqual(match.youtube_videos, [u'TqY324xLU4s', u'tst1', u'tst3', u'tst4'])
def assertOldMatch(self, match):
self.assertEqual(match.comp_level, "qm")
self.assertEqual(match.set_number, 1)
self.assertEqual(match.match_number, 1)
self.assertEqual(match.team_key_names, [u'frc69', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073'])
def test_createOrUpdate(self):
MatchManipulator.createOrUpdate(self.old_match)
self.assertOldMatch(Match.get_by_id("2012ct_qm1"))
self.assertEqual(Match.get_by_id("2012ct_qm1").alliances_json, """{"blue": {"score": -1, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": -1, "teams": ["frc69", "frc571", "frc176"]}}""")
MatchManipulator.createOrUpdate(self.new_match)
self.assertMergedMatch(Match.get_by_id("2012ct_qm1"), True)
def test_findOrSpawn(self):
self.old_match.put()
self.assertMergedMatch(MatchManipulator.findOrSpawn(self.new_match), True)
def test_updateMerge(self):
self.assertMergedMatch(MatchManipulator.updateMerge(self.new_match, self.old_match), True)
def test_createOrUpdate_no_auto_union(self):
MatchManipulator.createOrUpdate(self.old_match)
self.assertOldMatch(Match.get_by_id("2012ct_qm1"))
self.assertEqual(Match.get_by_id("2012ct_qm1").alliances_json, """{"blue": {"score": -1, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": -1, "teams": ["frc69", "frc571", "frc176"]}}""")
MatchManipulator.createOrUpdate(self.new_match, auto_union=False)
self.assertMergedMatch(Match.get_by_id("2012ct_qm1"), False)
def test_findOrSpawn_no_auto_union(self):
self.old_match.put()
self.assertMergedMatch(MatchManipulator.findOrSpawn(self.new_match, auto_union=False), False)
def test_updateMerge_no_auto_union(self):
self.assertMergedMatch(MatchManipulator.updateMerge(self.new_match, self.old_match, auto_union=False), False)
示例8: TestSuggestMatchVideoController
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import put [as 别名]
class TestSuggestMatchVideoController(unittest2.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
self.testbed.init_user_stub()
ndb.get_context().clear_cache() # Prevent data from leaking between tests
app = webapp2.WSGIApplication([
RedirectRoute(r'/suggest/match/video', SuggestMatchVideoController, 'suggest-match-video', strict_slash=True),
], debug=True)
self.testapp = webtest.TestApp(app)
self.event = Event(
id="2016necmp",
name="New England District Championship",
event_type_enum=EventType.DISTRICT_CMP,
event_district_enum=DistrictType.NEW_ENGLAND,
short_name="New England",
event_short="necmp",
year=2016,
end_date=datetime(2016, 03, 27),
official=False,
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),
webcast_json="",
website="http://www.firstsv.org"
)
self.event.put()
self.match = Match(
id="2016necmp_f1m1",
event=ndb.Key(Event, "2016necmp"),
year=2016,
comp_level="f",
set_number=1,
match_number=1,
team_key_names=['frc846', 'frc2135', 'frc971', 'frc254', 'frc1678', 'frc973'],
time=datetime.fromtimestamp(1409527874),
time_string="4:31 PM",
youtube_videos=["JbwUzl3W9ug"],
tba_videos=[],
alliances_json='{\
"blue": {\
"score": 270,\
"teams": [\
"frc846",\
"frc2135",\
"frc971"]},\
"red": {\
"score": 310,\
"teams": [\
"frc254",\
"frc1678",\
"frc973"]}}',
score_breakdown_json='{\
"blue": {\
"auto": 70,\
"teleop_goal+foul": 40,\
"assist": 120,\
"truss+catch": 40\
},"red": {\
"auto": 70,\
"teleop_goal+foul": 50,\
"assist": 150,\
"truss+catch": 40}}'
)
self.match.put()
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
)
Account.get_or_insert(
"123",
email="[email protected]",
registered=True
)
def getSuggestionForm(self, match_key):
response = self.testapp.get('/suggest/match/video?match_key={}'.format(match_key))
self.assertEqual(response.status_int, 200)
form = response.forms.get('suggest_match_video', None)
self.assertIsNotNone(form)
return form
#.........这里部分代码省略.........
示例9: TestMatchApiController
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import put [as 别名]
class TestMatchApiController(unittest2.TestCase):
def setUp(self):
app = webapp2.WSGIApplication([webapp2.Route(r'/<match_key:>', ApiMatchController, 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.match = Match(
id="2014cc_f1m1",
event=ndb.Key(Event, "2014cc"),
year=2014,
comp_level="f",
set_number=1,
match_number=1,
team_key_names=[u'frc846', u'frc2135', u'frc971', u'254', u'frc1678', u'frc973'],
time=datetime.datetime.fromtimestamp(1409527874),
time_string="4:31 PM",
youtube_videos=["JbwUzl3W9ug", "bHGyTjxbLz8"],
tba_videos=[],
alliances_json='{\
"blue": {\
"score": 270,\
"teams": [\
"frc846",\
"frc2135",\
"frc971"]},\
"red": {\
"score": 310,\
"teams": [\
"frc254",\
"frc1678",\
"frc973"]}}',
score_breakdown_json='{\
"blue": {\
"auto": 70,\
"teleop_goal+foul": 40,\
"assist": 120,\
"truss+catch": 40\
},"red": {\
"auto": 70,\
"teleop_goal+foul": 50,\
"assist": 150,\
"truss+catch": 40}}'
)
self.match.put()
def tearDown(self):
self.testbed.deactivate()
def assertMatchJson(self, match):
self.assertEqual(str(match["key"]), self.match.key.string_id())
self.assertEqual(match["comp_level"], self.match.comp_level)
self.assertEqual(match["event_key"], self.match.event.string_id())
self.assertEqual(match["set_number"], self.match.set_number)
self.assertEqual(match["match_number"], self.match.match_number)
self.assertEqual(match["alliances"], self.match.alliances)
self.assertEqual(match["score_breakdown"], self.match.score_breakdown)
self.assertEqual(match["videos"], self.match.videos)
self.assertEqual(match["time_string"], self.match.time_string)
if self.match.time is None:
self.assertEqual(match["time"], None)
else:
self.assertEqual(match["time"], 1409527874)
def test_match_api(self):
response = self.testapp.get('/2014cc_f1m1', headers={"X-TBA-App-Id": "tba-tests:match-controller-test:v01"})
match_json = json.loads(response.body)
self.assertMatchJson(match_json)
示例10: TestMatchController
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import put [as 别名]
class TestMatchController(unittest2.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
ndb.get_context().clear_cache() # Prevent data from leaking between tests
app = webapp2.WSGIApplication([
RedirectRoute(r'/match/<match_key>', MatchDetail, 'match-detail'),
])
self.testapp = webtest.TestApp(app)
self.match = Match(
id="2014cc_f1m1",
event=ndb.Key(Event, "2014cc"),
year=2014,
comp_level="f",
set_number=1,
match_number=1,
team_key_names=[u'frc846',u'frc2135',u'frc971',u'254',u'frc1678',u'frc973'],
time=datetime.fromtimestamp(1409527874),
time_string="4:31 PM",
youtube_videos=["JbwUzl3W9ug","bHGyTjxbLz8"],
tba_videos=[],
alliances_json='{\
"blue": {\
"score": 270,\
"teams": [\
"frc846",\
"frc2135",\
"frc971"]},\
"red": {\
"score": 310,\
"teams": [\
"frc254",\
"frc1678",\
"frc973"]}}',
score_breakdown_json='{\
"blue": {\
"auto": 70,\
"teleop_goal+foul": 40,\
"assist": 120,\
"truss+catch": 40\
},"red": {\
"auto": 70,\
"teleop_goal+foul": 50,\
"assist": 150,\
"truss+catch": 40}}'
)
self.event = Event(
id="2014cc",
name="Cheesy Champs",
event_type_enum=EventType.OFFSEASON,
short_name="Cheesy Champs",
event_short="cc",
year=2014,
end_date=datetime(2014, 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(2014, 03, 24),
)
self.match.put()
self.event.put()
def tearDown(self):
self.testbed.deactivate()
def testMatchDetail(self):
response = self.testapp.get("/match/2014cc_f1m1")
self.assertEqual(response.status_int, 200)
def testBadMatchDetail(self):
response = self.testapp.get("/match/2014cc_f1m2", status=404)
self.assertEqual(response.status_int, 404)
示例11: TestTeamApiController
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match 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()
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=datetime.now().year,
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()
self.match = Match(
id="2010sc_qm1",
alliances_json="""{"blue": {"score": 57, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": 74, "teams": ["frc281", "frc571", "frc176"]}}""",
comp_level="qm",
event=self.event.key,
game="frc_2012_rebr",
set_number=1,
match_number=1,
team_key_names=[u'frc281', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073'],
)
self.match.put()
self.award = Award(
name_str = "Engineering Inspiration",
award_type_enum = AwardType.ENGINEERING_INSPIRATION,
year=datetime.now().year,
event = self.event.key,
event_type_enum = EventType.REGIONAL,
team_list = [self.team.key],
recipient_json_list=[json.dumps({'team_number': 281, 'awardee': None})],
)
self.award.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)
def assertEventJson(self, event):
self.assertEqual(event["key"], self.event.key_name)
self.assertEqual(event["name"], self.event.name)
self.assertEqual(event["short_name"], self.event.short_name)
self.assertEqual(event["official"], self.event.official)
self.assertEqual(event["start_date"], self.event.start_date.date().isoformat())
self.assertEqual(event["end_date"], self.event.end_date.date().isoformat())
self.assertEqual(event["event_type_string"], self.event.event_type_str)
self.assertEqual(event["event_type"], self.event.event_type_enum)
def assertMatchJson(self, match):
self.assertEqual(str(match["key"]), self.match.key.string_id())
self.assertEqual(match["comp_level"], self.match.comp_level)
self.assertEqual(match["event_key"], self.match.event.string_id())
#.........这里部分代码省略.........
示例12: TestMatchManipulator
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import put [as 别名]
class TestMatchManipulator(unittest2.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_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.event = Event(
id="2012ct",
event_short="ct",
year=2012
)
self.old_match = Match(
id="2012ct_qm1",
alliances_json="""{"blue": {"score": -1, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": -1, "teams": ["frc69", "frc571", "frc176"]}}""",
score_breakdown_json=json.dumps({
'red': {'auto': 20, 'assist': 40, 'truss+catch': 20, 'teleop_goal+foul': 20},
'blue': {'auto': 40, 'assist': 60, 'truss+catch': 10, 'teleop_goal+foul': 40},
}),
comp_level="qm",
event=self.event.key,
year=2012,
set_number=1,
match_number=1,
team_key_names=[u'frc69', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073'],
youtube_videos=[u'P3C2BOtL7e8', u'tst1', u'tst2', u'tst3']
)
self.new_match = Match(
id="2012ct_qm1",
alliances_json="""{"blue": {"score": 57, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": 74, "teams": ["frc69", "frc571", "frc176"]}}""",
score_breakdown_json=json.dumps({
'red': {'auto': 80, 'assist': 40, 'truss+catch': 20, 'teleop_goal+foul': 20},
'blue': {'auto': 40, 'assist': 60, 'truss+catch': 10, 'teleop_goal+foul': 40},
}),
comp_level="qm",
event=self.event.key,
year=2012,
set_number=1,
match_number=1,
team_key_names=[u'frc69', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073'],
youtube_videos=[u'TqY324xLU4s', u'tst1', u'tst3', u'tst4']
)
def tearDown(self):
self.testbed.deactivate()
def assertMergedMatch(self, match, is_auto_union):
self.assertOldMatch(match)
self.assertEqual(match.alliances_json, """{"blue": {"score": 57, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": 74, "teams": ["frc69", "frc571", "frc176"]}}""")
if is_auto_union:
self.assertEqual(set(match.youtube_videos), {u'P3C2BOtL7e8', u'TqY324xLU4s', u'tst1', u'tst2', u'tst3', u'tst4'})
else:
self.assertEqual(match.youtube_videos, [u'TqY324xLU4s', u'tst1', u'tst3', u'tst4'])
self.assertEqual(match.score_breakdown['red']['auto'], 80)
def assertOldMatch(self, match):
self.assertEqual(match.comp_level, "qm")
self.assertEqual(match.set_number, 1)
self.assertEqual(match.match_number, 1)
self.assertEqual(match.team_key_names, [u'frc69', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073'])
def test_createOrUpdate(self):
MatchManipulator.createOrUpdate(self.old_match)
self.assertOldMatch(Match.get_by_id("2012ct_qm1"))
self.assertEqual(Match.get_by_id("2012ct_qm1").alliances_json, """{"blue": {"score": -1, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": -1, "teams": ["frc69", "frc571", "frc176"]}}""")
self.assertEqual(Match.get_by_id("2012ct_qm1").score_breakdown['red']['auto'], 20)
MatchManipulator.createOrUpdate(self.new_match)
self.assertMergedMatch(Match.get_by_id("2012ct_qm1"), True)
def test_findOrSpawn(self):
self.old_match.put()
self.assertMergedMatch(MatchManipulator.findOrSpawn(self.new_match), True)
def test_updateMerge(self):
self.assertMergedMatch(MatchManipulator.updateMerge(self.new_match, self.old_match), True)
def test_createOrUpdate_no_auto_union(self):
MatchManipulator.createOrUpdate(self.old_match)
self.assertOldMatch(Match.get_by_id("2012ct_qm1"))
self.assertEqual(Match.get_by_id("2012ct_qm1").alliances_json, """{"blue": {"score": -1, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": -1, "teams": ["frc69", "frc571", "frc176"]}}""")
MatchManipulator.createOrUpdate(self.new_match, auto_union=False)
self.assertMergedMatch(Match.get_by_id("2012ct_qm1"), False)
def test_findOrSpawn_no_auto_union(self):
self.old_match.put()
self.assertMergedMatch(MatchManipulator.findOrSpawn(self.new_match, auto_union=False), False)
def test_updateMerge_no_auto_union(self):
self.assertMergedMatch(MatchManipulator.updateMerge(self.new_match, self.old_match, auto_union=False), False)
示例13: TestApiMatchDetails
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import put [as 别名]
class TestApiMatchDetails(unittest2.TestCase):
def setUp(self):
app = webapp2.WSGIApplication([(r'/', ApiMatchDetails)], 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.event = Event(
id = "2010sc",
name = "Palmetto Regional",
event_type = "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.match_json = '{"blue": {"score": "14", "teams": ["frc469", "frc1114", "frc2041"]}, "red": {"score": "16", "teams": ["frc177", "frc67", "frc294"]}}'
match_team_key_names = ["frc177", "frc67", "frc294", "frc469", "frc1114", "frc2041"]
self.match = Match(
id = '2010cmp_f1m1',
comp_level = 'f',
match_number = 1,
team_key_names = match_team_key_names,
alliances_json = self.match_json,
set_number = 1,
game = 'frc_2010_bkwy',
event = self.event.key
)
self.match.put()
def tearDown(self):
self.testbed.deactivate()
def assertMatch(self, match_dict):
self.assertEqual(match_dict["key"], self.match.key_name)
self.assertEqual(match_dict["event"], self.event.key_name)
self.assertEqual(match_dict["competition_level"], self.match.name)
self.assertEqual(match_dict["set_number"], self.match.set_number)
self.assertEqual(match_dict["match_number"], self.match.match_number)
self.assertEqual(match_dict["team_keys"], self.match.team_key_names)
#FIXME: urgh. strings. - brandondean 10/21/2012
#self.assertEqual(match_dict["alliances"], self.match_json)
def testMatchDetails(self):
response = self.testapp.get("/?match=2010cmp_f1m1")
match_dict = json.loads(response.body)
match_dict["alliances"] = str(match_dict["alliances"])
self.assertMatch(match_dict)
示例14: TestSuggestEventWebcastController
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import put [as 别名]
class TestSuggestEventWebcastController(unittest2.TestCase):
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 givePermission(self):
self.account.permissions.append(AccountPermissions.REVIEW_MEDIA)
self.account.put()
def createSuggestion(self):
status = SuggestionCreator.createMatchVideoYouTubeSuggestion(self.account.key,
"H-54KMwMKY0",
"2016necmp_f1m1")
self.assertEqual(status, 'success')
return Suggestion.render_media_key_name(2016, 'match', '2016necmp_f1m1', 'youtube', 'H-54KMwMKY0')
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'/suggest/match/video/review', SuggestMatchVideoReviewController, 'suggest-video', strict_slash=True),
], debug=True)
self.testapp = webtest.TestApp(app)
self.event = Event(
id="2016necmp",
name="New England District Championship",
event_type_enum=EventType.DISTRICT_CMP,
event_district_enum=DistrictType.NEW_ENGLAND,
short_name="New England",
event_short="necmp",
year=2016,
end_date=datetime(2016, 03, 27),
official=False,
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),
webcast_json="",
website="http://www.firstsv.org",
)
self.event.put()
self.match = Match(
id="2016necmp_f1m1",
event=ndb.Key(Event, "2016necmp"),
year=2016,
comp_level="f",
set_number=1,
match_number=1,
team_key_names=['frc846', 'frc2135', 'frc971', 'frc254', 'frc1678', 'frc973'],
time=datetime.fromtimestamp(1409527874),
time_string="4:31 PM",
tba_videos=[],
alliances_json='{\
"blue": {\
"score": 270,\
"teams": [\
"frc846",\
"frc2135",\
"frc971"]},\
"red": {\
"score": 310,\
"teams": [\
"frc254",\
"frc1678",\
"frc973"]}}',
score_breakdown_json = '{\
"blue": {\
"auto": 70,\
"teleop_goal+foul": 40,\
"assist": 120,\
"truss+catch": 40\
},"red": {\
"auto": 70,\
"teleop_goal+foul": 50,\
"assist": 150,\
"truss+catch": 40}}'
)
self.match.put()
#.........这里部分代码省略.........
开发者ID:CarlColglazier,项目名称:the-blue-alliance,代码行数:103,代码来源:test_suggest_match_video_review_controller.py