Esempio n. 1
0
    def test_team_manager_results_upload_error(self):
        """
        An error message is displayed if results can't be uploaded, or files or
        the meet date can't be found.
        """
        swimmer1 = test.create_swimmer(team=self.team)
        swimmer2 = test.create_swimmer(team=self.team,
                                       first='David',
                                       last='Thornton')
        with open(
                '/Users/hgridley/Documents/Code/projects/CoachMate/teams/tests/test_files/RED-NE-Results005_bad_date.zip',
                'r') as f:
            tm = TeamManager(team=self.team, zip_file=f)
            msg = tm.load_results()
            self.assertEqual(msg[0], ('error', 'Couldn\'t find meet date'))

        with open(
                '/Users/hgridley/Documents/Code/projects/CoachMate/teams/tests/test_files/RED-NE-Results005_bad_events.zip',
                'r') as f:
            tm = TeamManager(team=self.team, zip_file=f)
            msg = tm.load_results()
            self.assertEqual(
                msg[0], ('error', 'Couldn\'t import event for David Thornton'))
            self.assertEqual(
                msg[1], ('error', 'Couldn\'t import event for David Thornton'))
            self.assertEqual(
                msg[2], ('error', 'Couldn\'t import event for Henry Gridley'))

        with open(
                '/Users/hgridley/Documents/Code/projects/CoachMate/teams/tests/test_files/fftlighttest-Results.zip'
        ) as f:
            tm = TeamManager(team=self.team, zip_file=f)
            msg = tm.load_results()
            self.assertEqual(msg[0],
                             ('error', 'Couldn\'t find .HY3 file in zip file'))
Esempio n. 2
0
    def test_team_manager_load_results(self):
        """
        Loads meet results from a .HY3 file in the zip file.
        """
        swimmer = test.create_swimmer(team=self.team)
        with open(
                '/Users/hgridley/Documents/Code/projects/CoachMate/teams/tests/test_files/RED-NE-Results005.zip',
                'r') as f:
            tm = TeamManager(team=self.team, zip_file=f)
            msg = tm.load_results()
            self.assertEqual(msg[0], ('success', 'Results imported'))

        events = Event.objects.filter(swimmer=swimmer)
        self.assertEqual(events[0].name, 'Henry Gridley')
        self.assertEqual(events[0].gender, 'M')
        self.assertEqual(events[0].team, self.team)
        self.assertEqual(events[0].event, '50 breast')
        self.assertEqual(events[0].time, timedelta(seconds=35.88))
        self.assertEqual(events[0].place, 7)
        self.assertEqual(events[0].date, date(2017, 2, 4))
        self.assertEqual(events[1].name, 'Henry Gridley')
        self.assertEqual(events[1].gender, 'M')
        self.assertEqual(events[1].team, self.team)
        self.assertEqual(events[1].event, '50 free')
        self.assertEqual(events[1].time, timedelta(seconds=23.34))
        self.assertEqual(events[1].place, 1)
        self.assertEqual(events[1].date, date(2017, 2, 4))
Esempio n. 3
0
 def test_team_manager_load_invalid_zip_file(self):
     """
     An error message is displayed if the file is not named correctly.
     """
     with open(
             '/Users/hgridley/Documents/Code/projects/CoachMate/teams/tests/test_files/fftlighttest.zip'
     ) as f:
         tm = TeamManager(team=self.team, zip_file=f)
         msg = tm.load_results()
         self.assertEqual(msg[0], ('error', 'Invalid file'))
Esempio n. 4
0
    def test_team_manager_load_roster_and_results(self):
        """
        Loads a team roster from a zip file then loads meet results for that team
        from a different zip file.
        """
        with open(
                '/Users/hgridley/Documents/Code/projects/CoachMate/teams/tests/test_files/NUSC-NE-Roster003.zip',
                'r') as f:
            tm = TeamManager(team=self.team, zip_file=f)
            msg = tm.load_roster()
            self.assertEqual(msg[0], ('success', 'Roster imported'))

        with open(
                '/Users/hgridley/Documents/Code/projects/CoachMate/teams/tests/test_files/RED-NE-Results005.zip',
                'r') as f:
            tm = TeamManager(team=self.team, zip_file=f)
            msg = tm.load_results()
            self.assertEqual(msg[0], ('success', 'Results imported'))

        events = Event.objects.all()
        self.assertEqual(len(events), 113)
Esempio n. 5
0
def swimmerList(request, abbr):
    team = get_object_or_404(Team, Q(user=request.user), abbr=abbr)
    if request.method == 'POST':
        if 'swimmer_create' in request.POST:
            swimmer_form = SwimmerForm(request.POST, team=team)
            if swimmer_form.is_valid():
                last_name = swimmer_form.cleaned_data['l_name']
                first_name = swimmer_form.cleaned_data['f_name']
                try:
                    # do nothing if swimmer already exists
                    swimmer = Swimmer.objects.filter(team=team).filter(
                        l_name=last_name).get(f_name=first_name)
                except:
                    # else create new swimmer
                    new_swimmer = swimmer_form.save()
                    return redirect('teams:swimmerList', abbr=team.abbr)
            else:
                team_form = TeamForm(instance=team)
                upload_form = UploadZipForm()

        elif 'team_edit' in request.POST:
            team_form = TeamForm(request.POST, instance=team, user=request.user)
            if team_form.is_valid():
                team_form.save()
                return redirect('teams:swimmerList', abbr=team.abbr)
            else:
                swimmer_form = SwimmerForm()
                upload_form = UploadZipForm()

        # upload team rosters and meet results
        elif 'upload' in request.POST:
            upload_form = UploadZipForm(request.POST, request.FILES)
            if upload_form.is_valid():
                zip_file = request.FILES['zip_file']
                tm = TeamManager(team=team, zip_file=zip_file) # team manager object
                # msgs contains error or success messages
                if 'Roster' in zip_file.name:
                    msgs = tm.load_roster()
                elif 'Results' in zip_file.name:
                    msgs = tm.load_results()
                else:
                    msgs = ('error', 'Invalid file')

                for message in msgs:
                    if message[0] == 'success':
                        messages.success(request, message[1])
                    else:
                        messages.error(request, message[1])
                return redirect('teams:swimmerList', abbr=team.abbr)
            else:
                team_form = TeamForm(instance=team)
                swimmer_form = SwimmerForm()
    else:
        swimmer_form = SwimmerForm()
        team_form = TeamForm(instance=team)
        upload_form = UploadZipForm()

    swimmer_list  = Swimmer.objects.filter(team=team)
    context = {
        'team': team,
        'team_form': team_form,
        'swimmer_list': swimmer_list,
        'swimmer_form': swimmer_form,
        'upload_form': upload_form,
    }

    if DEBUG == True:
        return render(request, 'teams/swimmer_list.html', context)
    else:
        return render(request, 'teams/swimmer_list.min.html', context)