def test_pohjolanmalja_access_object_with_staff(self): level = CompetitionLevel.objects.create(name='SM', abbreviation='SM') org1 = OrganizationFactory.create(abbreviation="A", name="AN") org2 = OrganizationFactory.create(abbreviation="B", name="BN") competition = CompetitionFactory.create(level=level) ResultFactory.create(organization=org1, competition=competition, position=1) ResultFactory.create(organization=org1, competition=competition, position=5) ResultFactory.create(organization=org1, competition=competition, position=15) ResultFactory.create(organization=org2, competition=competition, position=9) ResultFactory.create(organization=org2, competition=competition, position=5) user = User.objects.create(username="******", is_staff=True) self.client.force_login(user) response = self.client.get(self.url, follow=True) self.assertEqual(response.status_code, status.HTTP_200_OK) data = [ { "organization": { "id": 1, "name": "AN", "abbreviation": "A" }, "value": 12 }, { "organization": { "id": 2, "name": "BN", "abbreviation": "B" }, "value": 4 } ] self.assertEqual(response.content.decode(), json.dumps({"results": data}))
def test_approve_objects_within_date_limit(self): self.user = User.objects.create(username='******') ResultFactory.create(approved=False, competition__locked=False, competition__event__locked=False) call_command('approve', days=0, result=True, record=True, event=True, competition=True, verbosity=0) self.assertEqual(Result.objects.filter(approved=False).count(), 0) self.assertEqual(Event.objects.filter(locked=False).count(), 0) self.assertEqual(Competition.objects.filter(locked=False).count(), 0)
def test_record_creation_lower(self): self.model.objects.all().update(approved=True) ResultFactory.create(competition=self.competition, athlete=self.athlete_old, category=self.category_W, result=150) self.assertEqual(Record.objects.all().count(), 3) self.assertEqual(Record.objects.filter(approved=False).count(), 1)
def test_record_creation_same_value_setting_false(self): self.model.objects.all().update(approved=True) ResultFactory.create(competition=self.competition_later, athlete=self.athlete2, category=self.category_W, result=200) self.assertEqual(Record.objects.all().count(), 2) self.assertEqual(Record.objects.filter(approved=False).count(), 0)
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_team_record_creation(self): self.model.objects.all().update(approved=True) ResultFactory.create(competition=self.competition, athlete=self.athlete_old, category=self.category_team, result=300, team=True) self.assertEqual(Record.objects.filter(category__team=True).count(), 1) self.assertEqual(Record.objects.filter(result__team=True).count(), 1)
def test_record_creation_no_record_check(self): self.category_check.check_record = False self.category_check.save() ResultFactory.create(competition=self.competition, athlete=self.athlete_old, category=self.category_W, result=300) self.assertEqual(Record.objects.all().count(), 2) self.assertEqual(Record.objects.filter(approved=False).count(), 2)
def test_record_creation_higher_area(self): self.model.objects.all().update(approved=True) self.athlete_old.organization.areas.add(self.area) ResultFactory.create(competition=self.competition, athlete=self.athlete_old, organization=self.athlete_old.organization, category=self.category_W, result=300) self.assertEqual(Record.objects.all().count(), 6) self.assertEqual(Record.objects.filter(approved=False).count(), 4)
def test_record_approval_ending(self): self.model.objects.all().update(approved=True) ResultFactory.create(competition=self.competition, athlete=self.athlete_old, category=self.category_W, result=300) self.assertEqual(Record.objects.all().count(), 4) self.assertEqual(Record.objects.filter(approved=False).count(), 2) for record in self.model.objects.all(): if not record.approved: record.approved = True record.save() self.assertEqual(Record.objects.all().count(), 4) self.assertEqual(Record.objects.filter(date_end=None).count(), 3)
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 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.result = ResultFactory.create() self.competition_result_type = CompetitionResultTypeFactory.create( competition_type=self.result.competition.type) self.incorrect_competition_result_type = CompetitionResultTypeFactory.create( abbreviation="part") self.object = ResultPartialFactory.create( result=self.result, type=self.competition_result_type) self.result.competition.organization.group = self.group self.result.competition.organization.save() self.data = { 'result': self.object.result.id, 'type': self.object.type.id, 'order': self.object.order, 'value': self.object.value } self.newdata = { 'result': self.object.result.id, 'type': self.object.type.id, 'order': 2, 'value': Decimal('10.000') } self.url = '/api/resultpartials/' self.viewset = ResultPartialViewSet self.model = ResultPartial
def test_partial_record_creation_same_value_setting_true(self): result = ResultFactory.create(competition=self.competition_later, athlete=self.athlete2, category=self.category_W20, result=150) self.object = ResultPartialFactory.create( result=self.result, type=self.competition_result_type, value=50) self.model.objects.all().update(approved=True) self.object = ResultPartialFactory.create( result=result, type=self.competition_result_type, value=50) self.assertEqual(Record.objects.all().count(), 6) self.assertEqual(Record.objects.filter(approved=False).count(), 2) self.assertEqual( Record.objects.exclude(partial_result=None).count(), 4)
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