def test_athlete_constructor(self): sue = Athlete("Susan", "K", "Raisty", "F", "7") # school was not provided, so should be unattached db.session.add(sue) db.session.commit() ath = Athlete.query.filter_by(fname="Susan", lname="Raisty").one() self.assertEqual(ath.school.name, "Unattached") self.assertEqual(ath.school.code, "UNA") self.assertIsNone(ath.phone) self.assertEqual(ath.division.code, "7F") self.assertEqual(ath.division.name, "Grade 7 Girls")
def parse_athlete(tokens): """ Parses an "I" line record from a Hytek meet entry file that contains athlete information, and adds the athlete to our database. SIDE EFFECTS: Adds athlete to the Database. Also adds the athlete's school to the database if it isn't already in it. I LINE FORMAT: <token #> <data> <numchars> <notes> 0 I 1 Information Record 1 Last Name 20 (Required) 2 First Name 20 (Required) 3 Initial 1 4 Gender 1 M = Male, F = Female (Required) 5 Birth Date 10 MM/DD/YYYY (Optional) 6 Team Code 4 4 character max; use UNA if unknown (Required) 7 Team Name 30 Use Unattached if unknown (Required) 8 Age 3 Optional if birth date provided 9 School Year 2 (Optional according to HyTek, but TMS requires it) 17 Home Phone 20 (Optional) NOTE: We REQUIRE School Year, even though valid HyTek files might not. """ tokens = tokens[:] # make a copy so we don't mutate the original list if len(tokens) < 10: error(f"I-Line requires at least 10 fields. <{tokens}>") (_junk1, last_name, first_name, middle, gender, _junk2, team_code, team_name, _junk3, grade) = tokens[0:10] athlete = Athlete.add_athlete_to_db(first_name, middle, last_name, gender, grade, team_code, team_name) if athlete is None: # athlete might be null because there were issues with the file's # record (such as no matching division. if that's the case, just move # on to the next record # TODO - message user about problem with adding user return # If present in this I-record, add the athlete's phone (for SMS) to db # This will override any previous phone numbers for this athlete if len(tokens) > 17: if tokens[17] != "": athlete.phone = tokens[17] db.session.commit()
def test_athlete_get_full_name(self): fullname = Athlete._get_full_name("Susan", "Kathleen", "Raisty") self.assertEqual("Susan K. Raisty", fullname) fullname = Athlete._get_full_name("Jane", "", "Doe") self.assertEqual(fullname, "Jane Doe") fullname = Athlete._get_full_name("William", "H.", "Macy") self.assertEqual(fullname, "William H. Macy") fullname = Athlete._get_full_name("William", "H", "Macy") self.assertEqual(fullname, "William H. Macy") with self.assertRaises(Exception) as cm: Athlete._get_full_name("", "", "Raisty") err = cm.exception self.assertEqual(str(err), "Must provide first and last name.") with self.assertRaises(Exception) as cm: Athlete._get_full_name("Susan", "", "") err = cm.exception self.assertEqual(str(err), "Must provide first and last name.")
def register_process(): """Registration processing page""" member = request.form.get('member-type') fname = request.form.get('fname') lname = request.form.get('lname') phone = request.form.get('ath-phone') email = request.form.get('ath-email') team = request.form.get('ath-team-name') language = request.form.get('lang') team = db.session.query(Team).filter(Team.team_name == team).first() team_id = team.team_id if member == 'athlete': new_athlete = Athlete(a_fname=fname, a_lname=lname, a_phone=phone, a_email=email, team_id=team_id, language=language) db.session.add(new_athlete) db.session.commit() return render_template('thanks.html')
def write_data(): """Write trial user data""" athlete1 = Athlete(a_fname="Brian", a_lname="Bestie", a_phone="+17196440060", a_email="*****@*****.**", team_id=1, language="de") team1 = Team(team_name="Affy", coach_fname="Kari", coach_lname="Bestova", coach_phone="+18595823016", coach_email="*****@*****.**", password=bcrypt.hashpw('sugar', bcrypt.gensalt())) # db.session.add_all([coach1]) # db.session.commit() db.session.add_all([team1]) db.session.commit() db.session.add_all([athlete1]) db.session.commit()
def test_entry_to_event_relationship(self): veronica = Athlete("Veronica", "", "Rodriguez", "F", "6") self.assertIsNotNone(veronica) self.assertEqual(veronica.division.code, "6F") db.session.add(veronica) db.session.commit() e_code = "DT" mde = MeetDivisionEvent.query.filter_by( meet=self.meet1, event_code=e_code, div_id=veronica.division.id).one() entry = Entry(athlete=veronica, mde=mde) db.session.add(entry) db.session.commit() self.assertIsNotNone(entry.mde) self.assertIsNotNone(entry.athlete) self.assertIsNotNone(mde.entries) self.assertIsNotNone(veronica.entries) self.assertEqual(entry.event, entry.mde.event) self.assertEqual(mde.entries[0].athlete.fname, "Veronica")
def setUp(self): setup_test_app_db() db.create_all() self.client = app.test_client() TmsApp() self.meet = Meet.init_meet({ 'name': 'TestEntryMarks Meet', 'date': "August 5, 2018", 'division_order': ['7F'], 'event_order': ['1600M', 'LJ'] }) athlete = Athlete("Sue", "K", "Raisty", "F", "7") db.session.add(athlete) db.session.commit() self.athlete = athlete self.mde_1600m = MeetDivisionEvent.query.filter_by( meet=self.meet, event_code="1600M").one() self.mde_longjump = MeetDivisionEvent.query.filter_by( meet=self.meet, event_code="LJ").one()
def parse_entry(tokens, meet): """ Parses a "D-Line" in a Hytek entry file that corresponds to an athlete's entry into a particular event within a meet. D-Line format <Token#> <Data> <MaxChar> <Description> 0 D 1 Individual Entry Record 1 Last Name 20 (Required) 2 First Name 20 (Required) 3 Initial 1 (Optional) 4 Gender 1 M = Male, F = Female (Required) 5 Birth Date 10 MM/DD/YYYY (Optional) 6 Team Code 4 4 characters max; use UNA if unknown (Required) 7 Team Name 30 Use Unattached if unknown (Required) 8 Age 3 Age is optional if birth date provided 9 School Year 2 (Optional for HyTek, but not for TMS) 10 Event Code 10 Examples: 100, 5000S, 10000W, SP, HJ, DEC 11 Entry Mark 11 Time: hh:mm:ss.tt (1:23.44.55, 1:19.14, 58.83, 13.4h) Field Metric: 12.33, 1233; Field English: 12-10.25", 12', 121025, 12' 10 Combined-event: 3020 (points) 12 Mark measure 1 M for Metric, E for English (Required if Entry Mark provided) """ if len(tokens) < 11: error(f"HyTek D-Line requires at least 11 fields. <{tokens}>") (_junk1, last_name, first_name, middle, gender, _junk2, team_code, team_name, _junk3, grade, ht_event_code) = tokens[0:11] athlete = Athlete.add_athlete_to_db(first_name, middle, last_name, gender, grade, team_code, team_name) # If the athlete's record in file was bad, add_athlete_to_db returns None. if athlete is None: warning(f"Skipping athlete {first_name} {last_name}") return # translate the HyTek event names into TMS event codes event_code = ht_event_translator.get(ht_event_code, ht_event_code) q = MeetDivisionEvent.query try: mde = q.filter_by(meet_id=meet.id, event_code=event_code, div_id=athlete.division.id).one() except NoResultFound: raise TmsError("MDE doesn't exist: meet #{}, event {}, div {}".format( meet.id, event_code, athlete.division.code)) entry = Entry(athlete=athlete, mde=mde) # we need to commit here, or else we can't see the event in the below call # of entry.set_mark method. db.session.add(entry) db.session.commit() info(f"Added entry: {entry}") # If the athlete's entry includes a seed mark for this event, set it if len(tokens[11:13]) == 2: entry.set_mark(mark_string=tokens[11], mark_measure_type=tokens[12]) # I don't understand why, but at this point the entry thinks its "event" # attribute is "None", even after I setup the relationship with the mde, # which should also get me the event. I believe this shoudl be possible # without adding the entry to the session and commiting. db.session.commit() info("Set entry's mark. Entry: {}. Mark:{}".format(entry.event.code, entry.mark_to_string()))