-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #287 from aiarena/staging
Release v1.4.2
- Loading branch information
Showing
9 changed files
with
140 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,13 @@ | |
|
||
from aiarena import settings | ||
from aiarena.core.models import User, Map, Bot, News, \ | ||
CompetitionParticipation, MapPool | ||
CompetitionParticipation, MapPool, WebsiteUser | ||
from aiarena.core.tests.testing_utils import TestingClient | ||
from aiarena.core.tests.tests import BaseTestMixin | ||
from aiarena.core.utils import EnvironmentType | ||
|
||
def run_seed(matches, token): | ||
devadmin = User.objects.create_superuser(username='devadmin', password='x', email='[email protected]') | ||
devadmin = WebsiteUser.objects.create_superuser(username='devadmin', password='x', email='[email protected]') | ||
|
||
client = TestingClient() | ||
client.login(devadmin) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Generated by Django 3.0.14 on 2021-05-05 22:40 | ||
|
||
from django.conf import settings | ||
import django.contrib.auth.models | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
def migrate_website_users(apps, schema_editor): | ||
User = apps.get_model('core', 'User') | ||
WebsiteUser = apps.get_model('core', 'WebsiteUser') | ||
for website_user in User.objects.filter(type='WEBSITE_USER'): | ||
website_user.__class__ = WebsiteUser # convert to new class | ||
website_user.save() | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0028_auto_20210419_2336'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='WebsiteUser', | ||
fields=[ | ||
('user_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)), | ||
('single_use_match_requests', models.IntegerField(blank=True, default=0)), | ||
], | ||
options={ | ||
'verbose_name': 'WebsiteUser', | ||
}, | ||
bases=('core.user',), | ||
managers=[ | ||
('objects', django.contrib.auth.models.UserManager()), | ||
], | ||
), | ||
migrations.RunPython(migrate_website_users), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import logging | ||
|
||
from constance import config | ||
from django.db import models | ||
from django.utils import timezone | ||
|
||
from .user import User | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class WebsiteUser(User): | ||
"""Represents a website user/bot author""" | ||
single_use_match_requests = models.IntegerField(default=0, blank=True) | ||
"""UNUSED AS OF YET""" | ||
"""Single-use match requests that go on top of any periodic match requests a user might have. | ||
Periodic match requests are used first before these.""" | ||
|
||
@property | ||
def requested_matches_limit(self): | ||
return self.REQUESTED_MATCHES_LIMIT_MAP[self.patreon_level] + self.extra_periodic_match_requests | ||
|
||
@property | ||
def match_request_count_left(self): | ||
from .match import Match | ||
from .result import Result | ||
return self.requested_matches_limit \ | ||
- Match.objects.only('id').filter(requested_by=self, | ||
created__gte=timezone.now() - config.REQUESTED_MATCHES_LIMIT_PERIOD).count() \ | ||
+ Result.objects.only('id').filter(submitted_by=self, type='MatchCancelled', | ||
created__gte=timezone.now() - config.REQUESTED_MATCHES_LIMIT_PERIOD).count() | ||
|
||
|
||
class Meta: | ||
verbose_name = 'WebsiteUser' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
from aiarena.core.api import Matches | ||
from aiarena.core.management.commands import cleanupreplays | ||
from aiarena.core.models import User, Bot, Map, Match, Result, MatchParticipation, Competition, Round, ArenaClient, \ | ||
CompetitionParticipation, MapPool, MatchTag, Tag | ||
CompetitionParticipation, MapPool, WebsiteUser, Tag | ||
from aiarena.core.models.game_mode import GameMode | ||
from aiarena.core.utils import calculate_md5 | ||
|
||
|
@@ -307,11 +307,11 @@ def _generate_extra_bots(self): | |
|
||
|
||
def _generate_extra_users(self): | ||
self.regularUser2 = User.objects.create_user(username='regular_user2', password='x', | ||
self.regularUser2 = WebsiteUser.objects.create_user(username='regular_user2', password='x', | ||
email='[email protected]') | ||
self.regularUser3 = User.objects.create_user(username='regular_user3', password='x', | ||
self.regularUser3 = WebsiteUser.objects.create_user(username='regular_user3', password='x', | ||
email='[email protected]') | ||
self.regularUser4 = User.objects.create_user(username='regular_user4', password='x', | ||
self.regularUser4 = WebsiteUser.objects.create_user(username='regular_user4', password='x', | ||
email='[email protected]') | ||
|
||
|
||
|
@@ -323,7 +323,7 @@ class LoggedInMixin(BaseTestMixin): | |
|
||
def setUp(self): | ||
super().setUp() | ||
self.staffUser1 = User.objects.create_user(username='staff_user', password='x', | ||
self.staffUser1 = WebsiteUser.objects.create_user(username='staff_user', password='x', | ||
email='[email protected]', | ||
is_staff=True, | ||
is_superuser=True, | ||
|
@@ -333,7 +333,7 @@ def setUp(self): | |
type='ARENA_CLIENT', trusted=True, owner=self.staffUser1) | ||
Token.objects.create(user=self.arenaclientUser1) | ||
|
||
self.regularUser1 = User.objects.create_user(username='regular_user1', password='x', | ||
self.regularUser1 = WebsiteUser.objects.create_user(username='regular_user1', password='x', | ||
email='[email protected]') | ||
|
||
|
||
|
@@ -489,7 +489,7 @@ def _send_tags(self, bot1_tags, bot2_tags, results_resp_code=201): | |
def test_results_with_tags(self): | ||
az_symbols = 'abcdefghijklmnopqrstuvwxyz' | ||
num_symbols = '0123456789' | ||
extra_symbols = ' _ _ ' | ||
extra_symbols = ' _ _ ' | ||
game_mode = GameMode.objects.first() | ||
|
||
self.client.force_login(self.arenaclientUser1) | ||
|
@@ -505,14 +505,14 @@ def test_results_with_tags(self): | |
match_tags = Match.objects.get(id=match_response.data['id']).tags.all() | ||
self.assertTrue(match_tags.count()==1) | ||
for mt in match_tags: | ||
self.assertEqual(mt.user, self.staffUser1) | ||
self.assertEqual(mt.user.websiteuser, self.staffUser1) | ||
|
||
Matches.request_match(self.staffUser1, self.staffUser1Bot2, self.regularUser1Bot1, game_mode=game_mode) | ||
match_response, result_response = self._send_tags(None, ['abc']) | ||
match_tags = Match.objects.get(id=match_response.data['id']).tags.all() | ||
self.assertTrue(match_tags.count()==1) | ||
for mt in match_tags: | ||
self.assertEqual(mt.user, self.regularUser1) | ||
self.assertEqual(mt.user.websiteuser, self.regularUser1) | ||
|
||
# Check that tags are correct, stripped and attributed to the correct user | ||
_temp_tag1 = 'tes1t_ test2' | ||
|
@@ -562,7 +562,7 @@ def test_results_with_tags(self): | |
# This is to prevent tags from causing a result to fail submission | ||
Matches.request_match(self.staffUser1, self.staffUser1Bot2, self.regularUser1Bot1, game_mode=game_mode) | ||
match_response, result_response = self._send_tags( | ||
bot1_tags=['!', '2', 'A', '', az_symbols+num_symbols+extra_symbols], | ||
bot1_tags=['!', '2', 'A', '', az_symbols+num_symbols+extra_symbols], | ||
bot2_tags=['123'] | ||
) | ||
match_tags = Match.objects.get(id=match_response.data['id']).tags.all() | ||
|
@@ -572,13 +572,13 @@ def test_results_with_tags(self): | |
# Too many tags | ||
Matches.request_match(self.staffUser1, self.staffUser1Bot2, self.regularUser1Bot1, game_mode=game_mode) | ||
match_response, result_response = self._send_tags( | ||
bot1_tags=[str(i) for i in range(50)], | ||
bot1_tags=[str(i) for i in range(50)], | ||
bot2_tags=[str(i) for i in range(50)] | ||
) | ||
match_tags = Match.objects.get(id=match_response.data['id']).tags.all() | ||
self.assertTrue(match_tags.count()==64) | ||
|
||
|
||
|
||
|
||
class CompetitionsTestCase(FullDataSetMixin, TransactionTestCase): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters