def test_parse_just_one_D_line(self): parse_hytek_file("seed_data/HT-test2-oneentry.txt", self.meet1) """ D;Rodriguez;Veronica;;F;;GONZ;Gonzales;;6;DT;53' 8;E;1;;;; """ self.assertEqual(Athlete.query.count(), 1) self.assertEqual(School.query.count(), 2) self.assertEqual(Entry.query.count(), 1) self.assertIsNotNone(School.query.filter_by(code="GONZ").one()) ath_q = Athlete.query veronica = ath_q.filter_by(fname="Veronica", lname="Rodriguez").one() self.assertEqual(veronica.division.code, "6F") v_entry = Entry.query.filter_by(athlete_id=veronica.id).one() self.assertEqual(v_entry.mark, 644) self.assertEqual(v_entry.mark_type, "inches") mde = MeetDivisionEvent.query.filter_by(meet_id=self.meet1.id, div_id=veronica.division.id, event_code="DT").one() self.assertIsNotNone(mde) self.assertIn(v_entry, mde.entries) self.assertEqual(v_entry.athlete, veronica) self.assertIn(v_entry, self.meet1.entries) self.assertIn(v_entry, veronica.entries) self.assertIn(v_entry, v_entry.event.entries) self.assertEqual(v_entry.meet.name, EXAMPLE_MEETS[0]['name'])
def do_upload_school_entries(meet_id): meet = Meet.query.get(meet_id) # check if the post request has the file part if 'entry_file' not in request.files: flash( "You must upload a file containing track meet entries in Hytek file format" ) return redirect(url_for('show_enter_meet_upload_form', meet_id=meet_id)) file = request.files['entry_file'] # if user does not select file, browser submits an empty part # without filename if file.filename == '': flash('No selected file') return redirect(url_for('show_enter_meet_upload_form', meet_id)) if file and allowed_file(file.filename): filename = "meet_{}_school_{}_{}".format(meet_id, session['user_school_name'], file.filename) filename = secure_filename(filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) parse_hytek_file(os.path.join(app.config['UPLOAD_FOLDER'], filename), meet) flash("Successfully added athletes from file to meet.", "success") return redirect(url_for('show_meet_detail', meet_id=meet_id))
def test_parse_two_D_line(self): # Two entries for the same athlete. Make sure we don't create # the athlete twice, nor create her school twice. # Make sure the athlete is linked to her entries. parse_hytek_file("seed_data/HT-test3-1M1A2E.txt", self.meet1) self.assertEqual(Athlete.query.count(), 1) self.assertEqual(School.query.count(), 2) self.assertEqual(Entry.query.count(), 2) q = Athlete.query veronica = q.filter_by(fname="Veronica", lname="Rodriguez").one() self.assertEqual(len(veronica.entries), 2)
def test_parse_just_I_lines(self): self.assertEqual(Athlete.query.count(), 0) self.assertEqual(School.query.one().name, "Unattached") parse_hytek_file("seed_data/HT_test1-1S-3A.txt", self.meet1) """ I;Aldrich;Eric;;M;;PCS;Pacific Collegiate;;6;;;;;;;;;;;; I;Antonino;Kevin;;M;;PCS;Pacific Collegiate;;8;;;;;;;;;;;; I;Armstrong;Elizabeth;;F;10/18/2001;PCS;Pacific Collegiate;;6 """ self.assertEqual(Athlete.query.count(), 3) self.assertEqual(School.query.count(), 2) self.assertIsNotNone(School.query.filter_by(code="PCS").one()) q = Athlete.query eric = q.filter_by(fname="Eric", lname="Aldrich").one() kevin = q.filter_by(fname="Kevin", lname="Antonino").one() elizabeth = q.filter_by(fname="Elizabeth", lname="Armstrong").one() self.assertEqual(eric.division.code, "6M") self.assertEqual(kevin.division.code, "8M") self.assertEqual(elizabeth.division.code, "6F") self.assertEqual(eric.school.code, "PCS")
from parse_hytek import parse_hytek_file from test_utils import EXAMPLE_MEETS from util import info NUM_MEETS = len(EXAMPLE_MEETS) # NUM_MEETS = 3 if __name__ == "__main__": # reset database app = Flask(__name__) connect_to_db(app, "tms-dev", debug=False) info("Connected to database") reset_database() db.create_all() # create divs & events that are standard across all our meegs TmsApp() for i in range(NUM_MEETS): meet = Meet.init_meet(EXAMPLE_MEETS[i]) parse_hytek_file("seed_data/{}".format(EXAMPLE_MEETS[i]['filename']), meet) # Fix Unattached meets. Assign to Carmel HS. carmel = School.get.filter_by(code="CARM") unattached_meets = Meets.query.filter_by(host_school_id=1) for m in unattached_meets: m.host_school = carmel db.session.commit()
def helper_file_to_meet(example_meet_idx): meet_info_dict = EXAMPLE_MEETS[example_meet_idx] meet = Meet.init_meet(EXAMPLE_MEETS[example_meet_idx]) parse_hytek_file(f"seed_data/{meet_info_dict['filename']}", meet) meet.host_school_id = meet_info_dict['host_school_id']
def test_no_time_mark(self): self.assertEqual(School.query.one().name, "Unattached") parse_hytek_file("seed_data/HT_test_no_time_mark.txt", self.meet1) holly_entry = Entry.query.one() self.assertEqual(holly_entry.mark, INFINITY_SECONDS) self.assertEqual(holly_entry.mark_type, "seconds")
def test_athlete_missing_grade(self): self.meet1 = Meet.init_meet(EXAMPLE_MEETS[0]) # this file has one athlete record with an empty grade field parse_hytek_file("seed_data/HT_test-no-grade.txt", self.meet1) # the athlete should not get added to the database self.assertEqual(Athlete.query.count(), 0)