-
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #24 from LukePeltier/Unit-Testing
Start of unit testing automatically on push to main and pull request to main
- Loading branch information
Showing
9 changed files
with
285 additions
and
176 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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
name: Django CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
max-parallel: 4 | ||
matrix: | ||
python-version: [3.9] | ||
|
||
services: | ||
mysql: | ||
image: mariadb:latest | ||
env: | ||
MYSQL_ROOT_PASSWORD: ${{secrets.MYSQLPW}} | ||
MYSQL_DATABASE: tenmansstatistics | ||
ports: | ||
- 3306:3306/tcp | ||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=10s --health-retries=10 | ||
|
||
env: | ||
DJANGO_SETTINGS_MODULE: LukeWebsite.settings.testing | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Verify MariaDB connection | ||
run: | | ||
docker ps | ||
sudo mysql -h localhost -P 3306 --protocol=tcp -e 'SHOW DATABASES' -uroot --password=${{secrets.MYSQLPW}} | ||
- name: Install Dependencies | ||
working-directory: ./src | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pip-tools | ||
pip-sync | ||
- name: Write DB Conf File | ||
working-directory: ./src/LukeWebsite | ||
env: | ||
DB_CONF: ${{ secrets.DB_CONF }} | ||
run: | | ||
mkdir ./privateSettings | ||
echo "$DB_CONF" >> ./privateSettings/db.cnf | ||
- name: Write API Key File | ||
working-directory: ./src/LukeWebsite/tenMans | ||
env: | ||
API_FILE: ${{ secrets.API_KEY }} | ||
run: | | ||
mkdir ./conf | ||
echo "$API_FILE" >> ./conf/api.ini | ||
- name: Build Objects | ||
working-directory: ./src/LukeWebsite | ||
run: | | ||
python manage.py collectstatic --noinput --settings=LukeWebsite.settings.testing | ||
python manage.py migrate --settings=LukeWebsite.settings.testing | ||
- name: Run Tests | ||
working-directory: ./src/LukeWebsite | ||
run: | | ||
pytest |
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,20 @@ | ||
from LukeWebsite.settings.common import * | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', '++j8rg@ybk83g1ewqof7++roq!v)i5xg=ucd#%0nryja!)%m03') | ||
DEBUG = True | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
|
||
ALLOWED_HOSTS = [] | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.mysql', | ||
'HOST': '127.0.0.1', | ||
'PORT': '3306', | ||
'OPTIONS': { | ||
'read_default_file': os.path.join(BASE_DIR, 'privateSettings', 'db.cnf') | ||
} | ||
} | ||
} |
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,69 @@ | ||
import datetime | ||
import factory | ||
from tenMans.models import Champion, Game, GameBan, GameLaner, Lane, Player | ||
import factory.fuzzy | ||
from dateutil import tz | ||
|
||
|
||
class GameFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Game | ||
|
||
gameNumber = factory.Sequence(lambda n: '%d' % n) | ||
gameDate = factory.fuzzy.FuzzyDateTime(datetime.datetime(2020, 6, 1, tzinfo=tz.gettz('US/Central'))) | ||
gameBlueWins = factory.fuzzy.FuzzyChoice([True, False]) | ||
gameRandomTeams = False | ||
gameMemeStatus = False | ||
gameDuration = factory.fuzzy.FuzzyInteger(1, 3600) | ||
|
||
|
||
class LaneFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Lane | ||
|
||
|
||
class PlayerFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Player | ||
|
||
playerName = factory.Faker('name') | ||
|
||
|
||
class ChampionFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Champion | ||
|
||
championName = factory.fuzzy.FuzzyText() | ||
|
||
|
||
class GameLanerFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = GameLaner | ||
|
||
game = factory.Iterator(Game.objects.all()) | ||
lane = factory.Iterator(Lane.objects.all()) | ||
blueTeam = factory.fuzzy.FuzzyChoice([True, False]) | ||
player = factory.Iterator(Player.objects.all()) | ||
champion = factory.Iterator(Champion.objects.all()) | ||
draftOrder = factory.fuzzy.FuzzyChoice([None, 1, 2, 3, 4, 5, 6, 7, 8]) | ||
championSelectOrder = factory.fuzzy.FuzzyChoice([None, 1, 2, 3, 4, 5, 6, 7]) | ||
|
||
|
||
class GameLanerNoSupport(GameLanerFactory): | ||
lane = factory.Iterator(Lane.objects.exclude(laneName__exact="Support")) | ||
|
||
|
||
class GameLanerRandomGameFactory(GameLanerFactory): | ||
class Meta: | ||
model = GameLaner | ||
|
||
game = factory.Iterator(Game.objects.filter(gameRandomTeams=True)) | ||
draftOrder = None | ||
|
||
|
||
class GameBanFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = GameBan | ||
|
||
game = factory.Iterator(Game.objects.filter(gameRandomTeams=False)) | ||
champion = factory.Iterator(Champion.objects.all()) |
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
Oops, something went wrong.