Пример #1
0
 def save(self, *args, **kwargs):
     from apps.game import functions
     self.token = functions.upload_file(self.file)
     super(Map, self).save(args, kwargs)
Пример #2
0
    def test_functions(self):
        teams = Team.objects.all()
        competition = Competition.objects.get(type='elim')
        challenge = Challenge.objects.all()[0]
        team_participation = []
        for team in teams:
            participation = TeamParticipatesChallenge()
            participation.team = team
            participation.challenge = challenge
            participation.save()
            team_participation.append(participation)

        matches = []
        for i in range(3):
            matches.append(Match())
            participants = []
            for j in range(2):
                participant = Participant()
                participant.depend = team_participation[(i + j) % 3]
                participant.save()
                participants.append(participant)
            matches[i].part1 = participants[0]
            matches[i].part2 = participants[1]
            matches[i].competition = competition
            matches[i].save()

        challenge.competitions = [competition]
        challenge.save()
        ''' teams and matches initialized '''

        self.assertTrue(
            functions.upload_file(open("README.md", "r")) is not None)

        file_token1 = functions.upload_file(open("README.md", "r"))

        submit_tokens1 = functions.compile_submissions([file_token1])
        TeamSubmission.objects.create(team=team_participation[0],
                                      infra_token=submit_tokens1[0]["run_id"])

        time.sleep(0.4)  # Wait for the compilation results

        submission = TeamSubmission.objects.create(team=team_participation[1])
        submission.handle()

        client = Client()

        json_str = json.dumps({
            'id': submission.infra_compile_token,
            'operation': 'compile',
            'status': 2,
            'parameters': {
                'code_compiled_zip': functions.random_token(),
                'code_log': functions.random_token()
            }
        })
        response = client.post(
            '/game/api/report',
            data=json_str,
            content_type='application/json',
            **{'HTTP_AUTHORIZATION': settings.INFRA_AUTH_TOKEN})

        self.assertEqual(response.status_code, 200)

        single_match = SingleMatch.objects.create(match=matches[0],
                                                  map=Map.objects.first())
        single_match.handle()

        time.sleep(0.4)  # Wait for the matches results

        self.assertEqual(
            TeamSubmission.objects.get(
                infra_token=submit_tokens1[0]["run_id"]).infra_compile_message,
            None)

        # TODO successful run coverage

        # timeout coverage
        json_str = '{"id": "' + single_match.infra_token + '", "operation": "run", "status": 3, "end_time": ' \
                   '"2018-02-04T10:18:11.128063Z", "log": "ERROR: Killing manager due to timeout after ' \
                   '402.2596387863159 seconds\n", "parameters": {}} '
        response = client.post(
            '/game/api/report',
            data=json_str,
            content_type='application/json',
            **{'HTTP_AUTHORIZATION': settings.INFRA_AUTH_TOKEN})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(matches[0].single_matches.first().status, 'failed')
Пример #3
0
 def upload(self):
     from apps.game import functions
     self.infra_token = functions.upload_file(self.file)
     self.status = 'uploaded'
     self.save()