def clean(self): if 'summoner_name' not in self.cleaned_data: raise ValidationError("Please enter a summoner name") try: get_summoner(self.cleaned_data['summoner_name'], self.cleaned_data['region']) except HTTPError: raise ValidationError("Summoner was not found") return super().clean()
def index(request): if request.method == "POST": form = SummonerNameForm(request.POST) if form.is_valid(): region = form.cleaned_data["region"] summoner_name = form.cleaned_data["summoner_name"] summoner = get_summoner(summoner_name, region) try: calc = Calculation.objects.filter( summoner=summoner, created__gt=datetime.now() - timedelta(days=settings.CALC_DAYS)).latest("created") if calc.finished: return redirect("result", calc_id=calc.pk) return redirect("wait", calc_id=calc.pk) except Calculation.DoesNotExist: calc = Calculation.objects.create(summoner=summoner, finished=False) calculate_score.delay(summoner.pk, calc.pk) return redirect("wait", calc_id=calc.pk) else: form = SummonerNameForm() return render(request, 'analysis/index.html', { 'form': form, })
def test_get_match(self): summoner = get_summoner("mogl", "euw1") match_list = get_matchlist(summoner) match = get_match(summoner, match_list['matches'][0]["gameId"]) self.assertTrue( Match.objects.filter(summoner__name="mogl", riot_id=match.riot_id).exists())
def test_summoner(self): summoner = get_summoner("mogl", "euw1") self.assertTrue(Summoner.objects.filter(name="mogl").exists())
def test_get_latest_matches(self): summoner = get_summoner("mogl", "euw1") matches = list(get_latest_matches(summoner, limit=10)) sorted_matches = sorted(matches, key=lambda m: m.time, reverse=True) self.assertEquals(matches, sorted_matches)
def test_match_list(self): summoner = get_summoner("mogl", "euw1") match_list = get_matchlist(summoner) self.assertTrue(match_list)