def test_update_licences(self, mock_logger): User.objects.create_user('log') OrganizationFactory.create(sport_id=1) AthleteFactory.create(sport_id='123456789') obj = TestSuomiSport() obj.update_licences(update_only_latest=True, print_to_stdout=False) mock_logger.info.assert_called_with('Created new athlete from Suomisport: %s', '987654321') self.assertEqual(Athlete.objects.count(), 2) self.assertEqual(Athlete.objects.get(id=1).first_name, 'Matti') self.assertEqual(Athlete.objects.get(id=2).gender, 'W') self.assertEqual(Athlete.objects.get(id=2).first_name, 'Maju')
def setUp(self): self.factory = APIRequestFactory() self.user = User.objects.create(username='******') self.group = Group.objects.create(name="testgroup") self.organization_user = User.objects.create(username='******') self.organization_user.groups.add(self.group) self.staff_user = User.objects.create(username="******", is_staff=True) self.superuser = User.objects.create(username="******", is_superuser=True) self.object = ResultFactory.create(athlete=AthleteFactory.create( gender="M", date_of_birth=date.today() - relativedelta(years=18))) self.object.competition.organization.group = self.group self.object.competition.organization.save() self.athlete = AthleteFactory.create(gender="M", date_of_birth=date.today() - relativedelta(years=18)) self.data = { 'competition': self.object.competition.id, 'athlete': self.object.athlete.id, 'first_name': self.object.athlete.first_name, 'last_name': self.object.athlete.last_name, 'organization': self.object.organization.id, 'category': self.object.category.id, 'elimination_category': self.object.elimination_category.id, 'result': self.object.result, 'result_code': self.object.result_code, 'decimals': self.object.decimals, 'position': self.object.position, 'approved': self.object.approved } self.newdata = { 'competition': self.object.competition.id, 'athlete': self.athlete.id, 'first_name': 'John', 'last_name': 'Doe', 'organization': self.object.organization.id, 'category': self.object.category.id, 'elimination_category': self.object.elimination_category.id, 'result': None, 'result_code': 'DNF', 'decimals': 0, 'position': None, 'approved': False } self.competition_result_type = CompetitionResultTypeFactory.create( competition_type=self.object.competition.type) self.url = '/api/results/' self.viewset = ResultViewSet self.model = Result
def test_result_create_old_enough_exact_limit(self): self.object.category.age_exact = True self.object.category.save() athlete_young = AthleteFactory.create(gender="M", date_of_birth=date.today() - relativedelta(years=17)) self.data['athlete'] = athlete_young.pk response = self._test_create(user=self.superuser, data=self.data, locked=True) self.assertEqual(response.status_code, status.HTTP_201_CREATED)
def setUp(self): self.factory = APIRequestFactory() self.user = User.objects.create(username='******') self.staff_user = User.objects.create(username="******", is_staff=True) self.superuser = User.objects.create(username="******", is_superuser=True) self.athlete = AthleteFactory.create() self.object = AthleteInformationFactory.create(athlete=self.athlete) self.object_private = AthleteInformationFactory.create( athlete=self.athlete, visibility='S') self.data = { 'id': 1, 'athlete': self.object.athlete.pk, 'type': self.object.type, 'value': self.object.value, 'visibility': self.object.visibility } self.update_data = { 'id': 1, 'athlete': self.object.athlete.pk, 'type': self.object.type, 'value': "Field Champion 2018", 'visibility': self.object.visibility } self.newdata = { 'athlete': self.object.athlete.pk, 'type': self.object.type, 'value': "Field Champion 2000", 'visibility': 'A' } self.url = '/api/athleteinformation/' self.viewset = AthleteInformationViewSet self.model = AthleteInformation
def test_result_create_too_old_exact_limit(self): self.object.category.age_exact = True self.object.category.save() athlete_old = AthleteFactory.create(gender="M", date_of_birth=date.today() - relativedelta(years=20)) self.data['athlete'] = athlete_old.pk response = self._test_create(user=self.superuser, data=self.data, locked=True) self.assertEqual(response.data['non_field_errors'][0], "Athlete is too old for this category.") self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_result_create_with_team_result(self): team_members = [ self.athlete.pk, AthleteFactory.create(gender="M", date_of_birth=date.today() - relativedelta(years=19)).pk, AthleteFactory.create(gender="M", date_of_birth=date.today() - relativedelta(years=20)).pk ] self.newdata['athlete'] = None self.newdata['team_members'] = team_members self.newdata['team'] = True response = self._test_create(user=self.superuser, data=self.newdata, locked=False) self.assertEqual(len(response.data['team_members']), 3)
def setUp(self): self.user = User.objects.create(username='******') self.factory = APIRequestFactory() self.result = ResultFactory.create(athlete=AthleteFactory.create( gender="M", date_of_birth=date.today() - relativedelta(years=18))) self.result2 = ResultFactory.create(athlete=self.result.athlete) self.url = '/api/resultlist/' self.viewset = ResultList self.model = Result
def test_ignore_athlete_updates(self): User.objects.create_user('log') OrganizationFactory.create(sport_id=1) athlete = AthleteFactory.create(sport_id='123456789', no_auto_update=True) name = athlete.last_name obj = TestSuomiSport() obj.update_licences(update_only_latest=True, print_to_stdout=False) self.assertNotEqual(Athlete.objects.get(id=1).first_name, 'Matti') self.assertEqual(Athlete.objects.get(id=1).last_name, name)
def test_result_create_too_young(self): athlete_young = AthleteFactory.create(gender="M", date_of_birth=date.today() - relativedelta(years=16)) self.data['athlete'] = athlete_young.pk response = self._test_create(user=self.superuser, data=self.data, locked=True) self.assertEqual(response.data['non_field_errors'][0], "Athlete is too young for this category.") self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_result_create_incorrect_gender(self): athlete_gender = AthleteFactory.create(gender="W", date_of_birth=date.today() - relativedelta(years=18)) self.data['athlete'] = athlete_gender.pk response = self._test_create(user=self.superuser, data=self.data, locked=True) self.assertEqual(response.data['non_field_errors'][0], "Athlete's gender is not allowed for this category.") self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def setUp(self): self.factory = APIRequestFactory() self.user = User.objects.create(username='******') self.staff_user = User.objects.create(username="******", is_staff=True) self.superuser = User.objects.create(username="******", is_superuser=True) self.object = AthleteFactory.create() self.data = { 'id': 1, 'first_name': self.object.first_name, 'last_name': self.object.last_name, 'sport_id': self.object.sport_id, 'organization': self.object.organization.pk, 'date_of_birth': self.object.date_of_birth.strftime("%Y-%m-%d"), 'gender': self.object.gender } self.limited_data = { 'id': 1, 'first_name': self.object.first_name, 'last_name': self.object.last_name, 'sport_id': self.object.sport_id, 'organization': self.object.organization.pk } self.update_data = { 'id': 1, 'first_name': 'John', 'last_name': 'Doe', 'sport_id': '1234567890', 'organization': self.object.organization.pk, 'date_of_birth': '1983-02-03', 'gender': 'M' } self.newdata = { 'first_name': 'John', 'last_name': 'Doe', 'sport_id': '222222222', 'organization': self.object.organization.pk, 'date_of_birth': '1983-02-03', 'gender': 'M' } self.url = '/api/athletes/' self.viewset = AthleteViewSet self.model = Athlete
def _create_athletes(number, verbosity=1): """ Creates number athletes, 50% men / 50% women """ if verbosity: print('Creating athletes...') gender = 'W' for x in range(0, number): if gender == 'W': first_name = factory.Faker('first_name_female', locale=settings.FAKER_LOCALE) else: first_name = factory.Faker('first_name_male', locale=settings.FAKER_LOCALE) athlete = AthleteFactory.create( gender=gender, first_name=first_name, organization=Organization.objects.order_by('?').first()) gender = 'M' if gender == 'W' else 'W' if verbosity > 1: print('%s: %s' % (x, athlete))
def setUp(self): self.factory = APIRequestFactory() self.user = User.objects.create(username='******') self.staff_user = User.objects.create(username="******", is_staff=True) self.superuser = User.objects.create(username="******", is_superuser=True) self.competition = CompetitionFactory.create() self.competition_later = CompetitionFactory( date_start=self.competition.date_start + timedelta(days=2), date_end=self.competition.date_end + timedelta(days=2), type=self.competition.type, level=self.competition.level) sport = self.competition.type.sport self.category_W = Category.objects.create(name="W", abbreviation="W", max_age=None, min_age=None, gender="W", sport=sport) self.category_M = Category.objects.create(name="M", abbreviation="M", max_age=None, min_age=None, gender="M", sport=sport) self.category_W20_2 = Category.objects.create(name="W2", abbreviation="W2", max_age=20, min_age=None, gender="W", sport=sport) self.category_W20 = Category.objects.create(name="W", abbreviation="W", max_age=20, min_age=None, gender="W", sport=sport) self.category_W50 = Category.objects.create(name="W", abbreviation="W", max_age=None, min_age=50, gender="W", sport=sport) self.category_team = Category.objects.create(name="Team", abbreviation="Team", max_age=None, min_age=None, gender=None, team=True, sport=sport) self.category_check = CategoryForCompetitionType.objects.create( type=self.competition.type, category=self.category_W, record_group=1) CategoryForCompetitionType.objects.create(type=self.competition.type, category=self.category_M, record_group=1) CategoryForCompetitionType.objects.create(type=self.competition.type, category=self.category_W20, record_group=1) CategoryForCompetitionType.objects.create(type=self.competition.type, category=self.category_W50, record_group=1) CategoryForCompetitionType.objects.create(type=self.competition.type, category=self.category_W20_2, record_group=2) self.athlete = AthleteFactory.create(gender="W", date_of_birth=date.today() - timedelta(days=18 * 365)) self.athlete2 = AthleteFactory.create( gender="W", date_of_birth=date.today() - timedelta(days=18 * 365), sport_id=self.athlete.sport_id + "2") self.athlete_old = AthleteFactory.create(gender="W", date_of_birth=date.today() - timedelta(days=70 * 365)) self.record_level = RecordLevel.objects.create(name="SE", abbreviation="SE", base=True, decimals=True, team=True) self.record_level_partial = RecordLevel.objects.create( name="Finals SE", abbreviation="FSE", base=False, decimals=True, partial=True) self.record_level.types.add(self.competition.type) self.record_level_partial.types.add(self.competition.type) self.record_level.levels.add(self.competition.level) self.record_level_partial.levels.add(self.competition.level) self.area = Area.objects.create(name="Area", abbreviation="A") self.record_level_area = RecordLevel.objects.create(name="Area", abbreviation="A", area=self.area, base=True, team=True, decimals=True) self.record_level_area.types.add(self.competition.type) self.record_level_area.levels.add(self.competition.level) self.result = ResultFactory.create(competition=self.competition, athlete=self.athlete, category=self.category_W20, result=200) self.competition_result_type = CompetitionResultTypeFactory.create( competition_type=self.result.competition.type) self.object = Record.objects.all().first() self.data = { 'result': self.object.result.id, 'partial_result': None, 'level': self.object.level.id, 'type': self.object.type.id, 'category': self.object.category.id, 'approved': self.object.approved, 'date_start': self.object.date_start.strftime('%Y-%m-%d'), 'date_end': None, 'info': self.object.info, 'historical': self.object.historical } self.newdata = { 'result': self.object.result.id, 'partial_result': None, 'level': self.object.level.id, 'type': self.object.type.id, 'category': self.object.category.id, 'approved': True, 'date_start': self.object.date_start.strftime('%Y-%m-%d'), 'date_end': None, 'info': self.object.info, 'historical': self.object.historical } self.url = '/api/results/' self.viewset = RecordViewSet self.model = Record