def _process_request(self, request, event_key): to_put = [] for zebra_data in JSONZebraMotionWorksParser.parse(request.body): match_key = zebra_data['key'] # Check that match_key matches event_key if match_key.split('_')[0] != event_key: self._errors = json.dumps({"Error": "Match key {} does not match Event key {}!".format(match_key, event_key)}) self.abort(400) # Check that match exists match = Match.get_by_id(match_key) if match is None: self._errors = json.dumps({"Error": "Match {} does not exist!".format(match_key)}) self.abort(400) # Check that teams in Zebra data and teams in Match are the same for color in ['red', 'blue']: match_teams = match.alliances[color]['teams'] zebra_teams = [team['team_key'] for team in zebra_data['alliances'][color]] if match_teams != zebra_teams: self._errors = json.dumps({"Error": "Match {} teams are not valid!".format(match_key)}) self.abort(400) to_put.append(ZebraMotionWorks(id=match_key, event=ndb.Key(Event, event_key), data=zebra_data)) ndb.put_multi(to_put)
def testIntCoords(self): self.data[0]['alliances']['red'][0]['xs'][0] = 0 with self.assertRaises(ParserInputException): JSONZebraMotionWorksParser.parse(json.dumps(self.data))
def testMalformattedTeamKey(self): self.data[0]['alliances']['red'][0]['team_key'] = '254' with self.assertRaises(ParserInputException): JSONZebraMotionWorksParser.parse(json.dumps(self.data))
def testMissingTeamKey(self): del self.data[0]['alliances']['red'][0]['team_key'] with self.assertRaises(ParserInputException): JSONZebraMotionWorksParser.parse(json.dumps(self.data))
def testIntTimes(self): self.data[0]['times'][0] = 0 with self.assertRaises(ParserInputException): JSONZebraMotionWorksParser.parse(json.dumps(self.data))
def testMissingTimes(self): del self.data[0]['times'] with self.assertRaises(ParserInputException): JSONZebraMotionWorksParser.parse(json.dumps(self.data))
def testParser(self): parsed = JSONZebraMotionWorksParser.parse(json.dumps(self.data)) self.assertEqual(parsed, self.data)
def testMismatchedNullCoords(self): self.data[0]['alliances']['red'][0]['xs'][1] = None with self.assertRaises(ParserInputException): JSONZebraMotionWorksParser.parse(json.dumps(self.data))