add some tests
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
# coding=utf-8
|
||||
import shutil
|
||||
import os
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
from problem.models import Problem
|
||||
from contest.models import ContestProblem
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""
|
||||
清除测试用例文件夹中无用的测试用例
|
||||
"""
|
||||
def handle(self, *args, **options):
|
||||
self.stdout.write(self.style.WARNING("Please backup your test case dir firstly!"))
|
||||
problem_test_cases = [item.test_case_id for item in Problem.objects.all()]
|
||||
contest_problem_test_cases = [item.test_case_id for item in ContestProblem.objects.all()]
|
||||
|
||||
test_cases = list(set(problem_test_cases + contest_problem_test_cases))
|
||||
test_cases_dir = os.listdir(settings.TEST_CASE_DIR)
|
||||
|
||||
# 在 test_cases_dir 而不在 test_cases 中的
|
||||
dir_to_be_removed = list(set(test_cases_dir).difference(set(test_cases)))
|
||||
if dir_to_be_removed:
|
||||
self.stdout.write(self.style.ERROR("Following dirs will be removed: "))
|
||||
for item in dir_to_be_removed:
|
||||
self.stdout.write(self.style.WARNING(os.path.join(settings.TEST_CASE_DIR, item)))
|
||||
self.stdout.write(self.style.ERROR("Input yes to confirm: "))
|
||||
if raw_input() == "yes":
|
||||
for item in dir_to_be_removed:
|
||||
shutil.rmtree(os.path.join(settings.TEST_CASE_DIR, item), ignore_errors=True)
|
||||
self.stdout.write(self.style.SUCCESS("Done"))
|
||||
else:
|
||||
self.stdout.write(self.style.SUCCESS("Nothing happened"))
|
||||
else:
|
||||
self.stdout.write(self.style.SUCCESS("Test case dir is clean, nothing to do"))
|
||||
@@ -1,21 +0,0 @@
|
||||
# coding=utf-8
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
import os
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
try:
|
||||
if os.system("python manage.py migrate") != 0:
|
||||
self.stdout.write(self.style.ERROR("Failed to execute command 'migrate'"))
|
||||
exit(1)
|
||||
if os.system("python manage.py migrate --database=submission") != 0:
|
||||
self.stdout.write(self.style.ERROR("Failed to execute command 'migrate --database=submission'"))
|
||||
exit(1)
|
||||
if os.system("python manage.py initadmin") != 0:
|
||||
self.stdout.write(self.style.ERROR("Failed to execute command 'initadmin'"))
|
||||
exit(1)
|
||||
self.stdout.write(self.style.SUCCESS("Done"))
|
||||
except Exception as e:
|
||||
self.stdout.write(self.style.ERROR("Failed to initialize, error: " + str(e)))
|
||||
@@ -1,19 +0,0 @@
|
||||
# coding=utf-8
|
||||
from django.core.management.base import BaseCommand
|
||||
from account.models import UserProfile
|
||||
from submission.models import Submission
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
self.stdout.write(self.style.SUCCESS("Please wait a minute"))
|
||||
for profile in UserProfile.objects.all():
|
||||
submissions = Submission.objects.filter(user_id=profile.user.id)
|
||||
profile.submission_number = submissions.count()
|
||||
accepted_problem_number = len(set(Submission.objects.filter(user_id=profile.user.id, contest_id__isnull=True)\
|
||||
.values_list("problem_id", flat=True)))
|
||||
accepted_contest_problem_number = len(set(Submission.objects.filter(user_id=profile.user.id, contest_id__isnull=False)\
|
||||
.values_list("problem_id", flat=True)))
|
||||
profile.accepted_problem_number = accepted_problem_number + accepted_contest_problem_number
|
||||
profile.save()
|
||||
self.stdout.write(self.style.SUCCESS("Succeeded"))
|
||||
Reference in New Issue
Block a user