本文整理汇总了Python中oioioi.participants.models.Participant.save方法的典型用法代码示例。如果您正苦于以下问题:Python Participant.save方法的具体用法?Python Participant.save怎么用?Python Participant.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oioioi.participants.models.Participant
的用法示例。
在下文中一共展示了Participant.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_participants_unregister_forbidden
# 需要导入模块: from oioioi.participants.models import Participant [as 别名]
# 或者: from oioioi.participants.models.Participant import save [as 别名]
def test_participants_unregister_forbidden(self):
contest = Contest.objects.get()
url = reverse('participants_unregister',
kwargs={'contest_id': contest.id})
self.assertTrue(self.client.login(username='test_user'))
response = self.client.post(url, {'post': 'yes'})
self.assertEqual(403, response.status_code)
user = User.objects.get(username='test_user')
p = Participant(contest=contest, user=user, status='BANNED')
p.save()
self.assertEqual(Participant.objects.count(), 1)
self.assertTrue(self.client.login(username='test_user'))
response = self.client.post(url, {'post': 'yes'})
self.assertEqual(403, response.status_code)
p.status = 'ACTIVE'
p.save()
self.assertTrue(self.client.login(username='test_user'))
response = self.client.post(url, {'post': 'yes'})
self.assertEqual(403, response.status_code)
示例2: test_participants_unregister
# 需要导入模块: from oioioi.participants.models import Participant [as 别名]
# 或者: from oioioi.participants.models.Participant import save [as 别名]
def test_participants_unregister(self):
contest = Contest.objects.get()
contest.controller_name = \
'oioioi.oi.controllers.OIOnsiteContestController'
contest.save()
self.client.login(username='test_user')
response = self.client.post('/c/%s/unregister' % (contest.id,),
{'post': 'yes'})
self.assertEqual(404, response.status_code)
user = User.objects.get(username='test_user')
p = Participant(contest=contest, user=user, status='BANNED')
p.save()
self.assertEqual(Participant.objects.count(), 1)
self.client.login(username='test_user')
response = self.client.post('/c/%s/unregister' % (contest.id,),
{'post': 'yes'})
self.assertEqual(403, response.status_code)
p.status = 'ACTIVE'
p.save()
self.client.login(username='test_user')
response = self.client.post('/c/%s/unregister' % (contest.id,),
{'post': 'yes'})
self.assertEqual(403, response.status_code)
示例3: test_participants_contest_access
# 需要导入模块: from oioioi.participants.models import Participant [as 别名]
# 或者: from oioioi.participants.models.Participant import save [as 别名]
def test_participants_contest_access(self):
contest = Contest.objects.get()
contest.controller_name = \
'oioioi.participants.tests.ParticipantsContestController'
contest.save()
user = User.objects.get(username='test_user')
p = Participant(contest=contest, user=user, status='BANNED')
p.save()
self.client.login(username='test_user2')
response = self.client.get('/c/%s/' % (contest.id,), follow=True)
self.assertEqual(403, response.status_code)
self.client.login(username='test_user')
response = self.client.get('/c/%s/' % (contest.id,), follow=True)
self.assertEqual(403, response.status_code)
p.status = 'ACTIVE'
p.save()
self.client.login(username='test_user')
response = self.client.get('/c/%s/' % (contest.id,), follow=True)
self.assertEqual(200, response.status_code)
示例4: test_both_hands_cascading_on_registration_delete
# 需要导入模块: from oioioi.participants.models import Participant [as 别名]
# 或者: from oioioi.participants.models.Participant import save [as 别名]
def test_both_hands_cascading_on_registration_delete(self):
def _assert_equals_len(expectedLen=None):
self.assertEquals(Participant.objects.count(),
TestRegistration.objects.count())
if expectedLen:
self.assertEquals(Participant.objects.count(), expectedLen)
contest = Contest.objects.get()
contest.controller_name = \
'oioioi.participants.tests.ParticipantsContestController'
contest.save()
reg = []
for user in User.objects.all():
p = Participant(contest=contest, user=user)
p.save()
r = TestRegistration(participant=p, name='trolololo')
r.save()
reg.append(r)
_assert_equals_len(len(reg))
reg[0].delete()
_assert_equals_len(len(reg) - 1)
reg[1].participant.delete()
_assert_equals_len(len(reg) - 2)
reg = TestRegistration.objects.filter(name='trolololo').delete()
_assert_equals_len(0)
示例5: test_submit_permissions
# 需要导入模块: from oioioi.participants.models import Participant [as 别名]
# 或者: from oioioi.participants.models.Participant import save [as 别名]
def test_submit_permissions(self):
contest = Contest.objects.get()
contest.controller_name = \
'oioioi.participants.tests.ParticipantsContestController'
contest.save()
round = Round.objects.get(pk=1)
problem_instance = ProblemInstance.objects.get(pk=1)
self.assertTrue(problem_instance.round == round)
round.start_date = datetime(2012, 7, 31, tzinfo=utc)
round.end_date = datetime(2012, 8, 5, tzinfo=utc)
round.save()
user = User.objects.get(username='test_user')
p = Participant(contest=contest, user=user, status='BANNED')
p.save()
with fake_time(datetime(2012, 8, 4, 0, 5, tzinfo=utc)):
self.client.login(username='test_user2')
response = self.submit_file(contest, problem_instance)
self.assertEqual(403, response.status_code)
self.client.login(username='test_user')
response = self.submit_file(contest, problem_instance)
self.assertEqual(403, response.status_code)
p.status = 'ACTIVE'
p.save()
self.client.login(username='test_user')
response = self.submit_file(contest, problem_instance)
self._assertSubmitted(contest, response)
示例6: test_participants_contest_visibility
# 需要导入模块: from oioioi.participants.models import Participant [as 别名]
# 或者: from oioioi.participants.models.Participant import save [as 别名]
def test_participants_contest_visibility(self):
contest = Contest(id='invisible', name='Invisible Contest')
contest.controller_name = \
'oioioi.participants.tests.ParticipantsContestController'
contest.save()
user = User.objects.get(username='test_user')
response = self.client.get(reverse('select_contest'))
self.assertIn('contests/select_contest.html',
[t.name for t in response.templates])
self.assertEqual(len(response.context['contests']), 1)
self.client.login(username='test_user')
response = self.client.get(reverse('select_contest'))
self.assertEqual(len(response.context['contests']), 1)
p1 = Participant(contest=contest, user=user, status='BANNED')
p1.save()
self.client.login(username='test_user')
response = self.client.get(reverse('select_contest'))
self.assertEqual(len(response.context['contests']), 1)
p1.status = 'ACTIVE'
p1.save()
self.client.login(username='test_user')
response = self.client.get(reverse('select_contest'))
self.assertEqual(len(response.context['contests']), 2)
self.client.login(username='test_admin')
response = self.client.get(reverse('select_contest'))
self.assertEqual(len(response.context['contests']), 2)
self.assertIn('Invisible Contest', response.content)
示例7: test_contest_access
# 需要导入模块: from oioioi.participants.models import Participant [as 别名]
# 或者: from oioioi.participants.models.Participant import save [as 别名]
def test_contest_access(self):
contest = Contest.objects.get()
contest.controller_name = \
'oioioi.oi.controllers.OIContestController'
contest.save()
user = User.objects.get(username='test_user')
p = Participant(contest=contest, user=user, status='BANNED')
p.save()
url = reverse('default_contest_view',
kwargs={'contest_id': contest.id})
self.client.login(username='test_user2')
response = self.client.get(url, follow=True)
self.assertEqual(200, response.status_code)
self.client.login(username='test_user')
response = self.client.get(url, follow=True)
self.assertEqual(200, response.status_code)
p.status = 'ACTIVE'
p.save()
self.client.login(username='test_user')
response = self.client.get(url, follow=True)
self.assertEqual(200, response.status_code)
示例8: test_participants_unregister
# 需要导入模块: from oioioi.participants.models import Participant [as 别名]
# 或者: from oioioi.participants.models.Participant import save [as 别名]
def test_participants_unregister(self):
contest = Contest.objects.get()
contest.controller_name = \
'oioioi.participants.tests.OpenRegistrationContestController'
contest.save()
url = reverse('participants_unregister',
kwargs={'contest_id': contest.id})
self.client.login(username='test_user')
response = self.client.post(url, {'post': 'yes'})
self.assertEqual(403, response.status_code)
user = User.objects.get(username='test_user')
p = Participant(contest=contest, user=user, status='BANNED')
p.save()
self.assertEqual(Participant.objects.count(), 1)
self.client.login(username='test_user')
response = self.client.post(url, {'post': 'yes'})
self.assertEqual(403, response.status_code)
p.status = 'ACTIVE'
p.save()
self.client.login(username='test_user')
response = self.client.post(url, {'post': 'yes'})
self.assertEqual(302, response.status_code)
self.assertEqual(Participant.objects.count(), 0)
示例9: test_participants_contest_access
# 需要导入模块: from oioioi.participants.models import Participant [as 别名]
# 或者: from oioioi.participants.models.Participant import save [as 别名]
def test_participants_contest_access(self):
contest = Contest.objects.get()
contest.controller_name = \
'oioioi.participants.tests.ParticipantsContestController'
contest.save()
user = User.objects.get(username='test_user')
p = Participant(contest=contest, user=user, status='BANNED')
p.save()
url = reverse('default_contest_view',
kwargs={'contest_id': contest.id})
self.client.login(username='test_user2')
response = self.client.get(url, follow=True)
self.assertEqual(403, response.status_code)
# Make sure we get nice page, allowing to log out.
self.assertNotIn('My submissions', response.content)
self.assertIn('OIOIOI', response.content)
self.assertIn('Log out', response.content)
self.client.login(username='test_user')
response = self.client.get(url, follow=True)
self.assertEqual(403, response.status_code)
p.status = 'ACTIVE'
p.save()
self.client.login(username='test_user')
response = self.client.get(url, follow=True)
self.assertEqual(200, response.status_code)
示例10: setUp
# 需要导入模块: from oioioi.participants.models import Participant [as 别名]
# 或者: from oioioi.participants.models.Participant import save [as 别名]
def setUp(self):
contest = Contest.objects.get()
user = User.objects.get(username="test_user")
p = Participant(contest=contest, user=user, status="ACTIVE")
p.save()
user = User.objects.get(username="test_user2")
p = Participant(contest=contest, user=user, status="ACTIVE")
p.save()
示例11: test_missing_registration_model
# 需要导入模块: from oioioi.participants.models import Participant [as 别名]
# 或者: from oioioi.participants.models.Participant import save [as 别名]
def test_missing_registration_model(self):
contest = Contest.objects.get()
user = User.objects.get(username='test_user')
p = Participant(contest=contest, user=user)
p.save()
self.assertRaises(ObjectDoesNotExist,
lambda: getattr(p, 'registration_model'))
示例12: test_contest_info
# 需要导入模块: from oioioi.participants.models import Participant [as 别名]
# 或者: from oioioi.participants.models.Participant import save [as 别名]
def test_contest_info(self):
contest = Contest.objects.get()
user = User.objects.get(username='test_user')
p = Participant(contest=contest, user=user)
p.save()
OpenRegistration(participant_id=p.id, **self.reg_data).save()
url = reverse('contest_info', kwargs={'contest_id': contest.id})
data = self.client.get(url).json()
self.assertEqual(data['users_count'], 1)
示例13: test_making_complaint
# 需要导入模块: from oioioi.participants.models import Participant [as 别名]
# 或者: from oioioi.participants.models.Participant import save [as 别名]
def test_making_complaint(self):
contest = Contest.objects.get()
contest.controller_name = \
'oioioi.oi.controllers.OIOnsiteContestController'
contest.save()
user = User.objects.get(username='test_user')
p = Participant(contest=contest, user=user, status='ACTIVE')
p.save()
with fake_time(datetime(2012, 8, 11, tzinfo=utc)):
self.client.login(username='test_user')
response = self.client.post(reverse('add_complaint',
kwargs={'contest_id': contest.id}),
{'complaint': "I am innocent! It is your fault!"}, follow=True)
self.assertEqual(response.status_code, 403)
cconfig = ComplaintsConfig(contest=contest, enabled=True,
start_date=datetime(2012, 8, 10, tzinfo=utc),
end_date=datetime(2012, 8, 12, tzinfo=utc))
cconfig.save()
with fake_time(datetime(2012, 8, 9, tzinfo=utc)):
response = self.client.get(reverse('add_complaint',
kwargs={'contest_id': contest.id}))
self.assertEqual(response.status_code, 403)
with fake_time(datetime(2012, 8, 13, tzinfo=utc)):
response = self.client.get(reverse('add_complaint',
kwargs={'contest_id': contest.id}))
self.assertEqual(response.status_code, 403)
with fake_time(datetime(2012, 8, 11, tzinfo=utc)):
response = self.client.post(reverse('add_complaint',
kwargs={'contest_id': contest.id}),
{'complaint': "I am innocent! It is your fault!"}, follow=True)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "has been sent")
jurym = mail.outbox[0].message()
userm = mail.outbox[1].message()
del mail.outbox
# Header class doesn't offer 'in' operator
self.assertEqual("[oioioi-complaints] Complaint: Test User (test_user)",
jurym['Subject'])
self.assertEqual("[oioioi-complaints] Complaint: Test User (test_user)",
userm['Subject'])
self.assertEquals("[email protected]", jurym['To'])
self.assertEquals("[email protected]", userm['To'])
self.assertEquals(jurym['Message-ID'], userm['References'])
self.assertEquals(userm['Message-ID'], jurym['References'])
self.assertIn("your fault!", jurym.as_string())
self.assertIn("your fault!", userm.as_string())
示例14: test_participants_accounts_menu
# 需要导入模块: from oioioi.participants.models import Participant [as 别名]
# 或者: from oioioi.participants.models.Participant import save [as 别名]
def test_participants_accounts_menu(self):
contest = Contest.objects.get()
user = User.objects.get(username='test_user')
p = Participant(contest=contest, user=user)
p.save()
self.assertTrue(self.client.login(username='test_user'))
url = reverse('default_contest_view',
kwargs={'contest_id': contest.id})
response = self.client.get(url, follow=True)
self.assertNotContains(response, 'Register to the contest')
self.assertNotContains(response, 'Edit contest registration')
示例15: test_participants_accounts_menu
# 需要导入模块: from oioioi.participants.models import Participant [as 别名]
# 或者: from oioioi.participants.models.Participant import save [as 别名]
def test_participants_accounts_menu(self):
contest = Contest.objects.get()
contest.controller_name = \
'oioioi.oi.controllers.OIOnsiteContestController'
contest.save()
user = User.objects.get(username='test_user')
p = Participant(contest=contest, user=user)
p.save()
self.client.login(username='test_user')
response = self.client.get('/c/%s/' % (contest.id,), follow=True)
self.assertNotIn('Register to the contest', response.content)
self.assertNotIn('Edit contest registration', response.content)