Skip to content

Commit

Permalink
Merge branch 'master' into pyup-scheduled-update-2019-09-16
Browse files Browse the repository at this point in the history
  • Loading branch information
djbrown committed Sep 26, 2019
2 parents 1a655c3 + d79fa47 commit 4f042dd
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 111 deletions.
39 changes: 16 additions & 23 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/base/parsing.py
Expand Up @@ -32,7 +32,7 @@ def parse_district_season_start_year(district_season_heading):

def parse_league_name(tree):
heading = tree.xpath('//*[@id="results"]/div/h1/text()[2]')[0]
return heading.split(' - ')[0]
return heading.rsplit(' - ', 1)[0]


def parse_team_links(tree):
Expand Down Expand Up @@ -94,7 +94,7 @@ def parse_sports_hall_bhv_id(link):

def parse_coordinates(tree) -> Tuple[Optional[str], Optional[str]]:
scripts = tree.xpath('//script')
if len(scripts) < 5:
if len(scripts) < 9:
return (None, None)
map_script = scripts[8].text
match = re.search(r"^ new mxn.LatLonPoint\(([.0-9]+),([.0-9]+)\)\),$", map_script, re.MULTILINE)
Expand All @@ -107,7 +107,10 @@ def parse_goals(game_row) -> Tuple[Optional[int], Optional[int]]:
home_goals = game_row[7].text
guest_goals = game_row[9].text
if home_goals and guest_goals:
return int(home_goals), int(guest_goals)
home_goals = home_goals.strip()
guest_goals = guest_goals.strip()
if home_goals and guest_goals:
return int(home_goals), int(guest_goals)

if len(game_row[10]) == 1:
title = game_row[10][0].get("title", "")
Expand Down
11 changes: 3 additions & 8 deletions src/base/templates/contact_form/contact_form_sent.html
Expand Up @@ -5,12 +5,7 @@
{% block content %}
<h1>Nachricht abgeschickt</h1>
<p>
User mit der angegeben E-Mail existiert, wurden die nächsten Schritte zum Rücksetzen Deines Passwort an diese Adresse geschickt.
Die E-Mail sollte in Kürze in Deinem Postfach eintreffen.
Danke für Deine Nachricht.
Du erhälst zeitnah eine Antwort an die angegebene Mail­ad­res­se.
</p>

<p>
Falls Du keine E-Mail erhälst, stelle bitte sicher, dass die eingegebene Adresse die selbe ist, mit der Du Dich registriert hast.
Zusätzlich solltest Du in Deinem Spam-Ordner nachschauen.
</p>
{% endblock %}
{% endblock %}
5 changes: 2 additions & 3 deletions src/base/tests/base.py
Expand Up @@ -3,9 +3,8 @@
import unittest
from contextlib import contextmanager

# import requests
from django.conf import settings
from django.test import LiveServerTestCase
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.urls import ResolverMatch, resolve, reverse
from sauceclient import SauceClient
from selenium.webdriver import Firefox, Remote
Expand All @@ -21,7 +20,7 @@

@unittest.skipUnless(settings.SELENIUM is True or _CI,
'Selenium test cases are only run in CI or if configured explicitly.')
class SeleniumTestCase(LiveServerTestCase):
class SeleniumTestCase(StaticLiveServerTestCase):

def setUp(self):
if _CI:
Expand Down
32 changes: 32 additions & 0 deletions src/base/tests/selenium/test_contact_form.py
@@ -0,0 +1,32 @@
from django.core import mail

from base.tests.base import SeleniumTestCase


class ContactFormTest(SeleniumTestCase):

def test_contact_form(self):
self.assertEqual(mail.outbox, [])

username = 'john'
usermail = 'lennon@thebeatles.com'
message = f'this is a message'
self.navigate('contact_form')

username_textfield = self.driver.find_element_by_name('name')
username_textfield.send_keys(username)
mail_textfield = self.driver.find_element_by_name('email')
mail_textfield.send_keys(usermail)
message_textarea = self.driver.find_element_by_name('body')
message_textarea.send_keys(message)

with self.wait():
message_textarea.submit()

self.assert_view('contact_form_sent')

self.assertEqual(len(mail.outbox), 1)
body: mail.EmailMessage = mail.outbox[0].body
self.assertIn(username, body)
self.assertIn(message, body)
self.assertIn(usermail, body)
35 changes: 0 additions & 35 deletions src/base/tests/selenium/test_selenium.py
@@ -1,7 +1,3 @@
from unittest import skip

from selenium.webdriver.common.keys import Keys

from base.tests.base import SeleniumTestCase


Expand All @@ -23,34 +19,3 @@ def test_w3_org_exists(self):
driver.get('https://www.w3.org/')
body = driver.find_element_by_id('www-w3-org')
self.assertIsNotNone(body)

@skip("Register page not implemented yet")
def test_register(self):
driver = self.driver

# Opening the link we want to test
driver.get('http://127.0.0.1:8000/accounts/register/')

# find the form element
first_name = driver.find_element_by_id('id_first_name')
last_name = driver.find_element_by_id('id_last_name')
username = driver.find_element_by_id('id_username')
email = driver.find_element_by_id('id_email')
password1 = driver.find_element_by_id('id_password1')
password2 = driver.find_element_by_id('id_password2')

submit = driver.find_element_by_name('register')

# Fill the form with data
first_name.send_keys('Homer')
last_name.send_keys('Simpson')
username.send_keys('duffman')
email.send_keys('homer@simpson.com')
password1.send_keys('123456')
password2.send_keys('123456')

# submitting the form
submit.send_keys(Keys.RETURN)

# check the returned result
assert 'Check your email' in driver.page_source
1 change: 0 additions & 1 deletion src/base/urls.py
Expand Up @@ -8,5 +8,4 @@
path('', view_home, name='home'),
path('impressum/', view_notice, name='notice'),
path('datenschutz/', view_privacy, name='privacy'),
# path('kontakt/', view_contact, name='contact'),
]
7 changes: 6 additions & 1 deletion src/games/management/commands/import_games.py
Expand Up @@ -86,11 +86,16 @@ def import_league(self, league: League):
self.import_game(game_row, league)

def import_game(self, game_row, league: League):

if game_row[1].text == 'Nr.':
LOGGER.debug('SKIPPING Row (heading)')
return

# league_abbreviation = game_row[0].text
number = int(game_row[1].text)

if self.options['games'] and number not in self.options['games']:
LOGGER.debug('SKIPPING Game: %s (options)', number)
LOGGER.debug('SKIPPING Game (options): %s', number)
return

opening_whistle = parsing.parse_opening_whistle(game_row[2].text)
Expand Down
7 changes: 7 additions & 0 deletions src/games/tests/test_import_games.py
Expand Up @@ -103,3 +103,10 @@ def test_no_youth(self):
self.assertEqual(return_code, None)

self.assert_objects(Game, count=0)


class BuggedGameRows(ModelTestCase):
def test_additional_heading_row(self):
call_command('setup', '-a', 3, '-d', 8, '-s', 2019, '-l', 46786)
call_command('import_games', '-g', 41013)
self.assert_objects(Game)
2 changes: 2 additions & 0 deletions src/hbscorez/settings.py
Expand Up @@ -156,6 +156,8 @@

EMAIL_FILE_PATH = os.path.join(ROOT_DIR, 'mails')

MANAGERS = [('manager', 'manager@localhost')]


# auth

Expand Down
40 changes: 20 additions & 20 deletions src/leagues/management/commands/setup.py
Expand Up @@ -31,6 +31,8 @@ def add_arguments(self, parser):
help="IDs of Leagues.")
parser.add_argument('--youth', action='store_true',
help="Include youth leagues.")
parser.add_argument('--skip-teams', action='store_true',
help="Skip processing Teams.")

def handle(self, *args, **options):
self.options = options
Expand Down Expand Up @@ -129,56 +131,54 @@ def create_league(self, league_link, district, season):
LOGGER.debug('SKIPPING League (options): %s %s', bhv_id, abbreviation)
return

if abbreviation[:1] in ['m', 'w', 'g', 'u'] and not self.options['youth']:
LOGGER.debug('SKIPPING League (youth league): %s %s', bhv_id, abbreviation)
if abbreviation == 'TEST':
LOGGER.debug('SKIPPING League (test league): %s %s', bhv_id, abbreviation)
return

url = League.build_source_url(bhv_id)
dom = logic.get_html(url)

name = parsing.parse_league_name(dom)

if League.is_youth_league(abbreviation) and not self.options['youth']:
LOGGER.debug('SKIPPING League (youth league): %s %s', bhv_id, name)
if any(n in name for n in ['Platzierungsrunde', 'Meister', 'Freiwurf', 'Maxi', 'turnier', 'wettbewerb']):
LOGGER.debug('SKIPPING League (name): %s %s', bhv_id, name)
return

team_links = parsing.parse_team_links(dom)
if not team_links:
LOGGER.debug('SKIPPING League: %s %s (no team table)', bhv_id, name)
LOGGER.debug('SKIPPING League (no team table): %s %s', bhv_id, name)
return

game_rows = parsing.parse_game_rows(dom)
if not game_rows:
LOGGER.debug('SKIPPING League (no games): %s %s', bhv_id, name)
return

if len(game_rows) < len(team_links) * (len(team_links) - 1):
LOGGER.debug('SKIPPING League (few games): %s %s', bhv_id, abbreviation)
return

if "Platzierungsrunde" in name:
LOGGER.debug('SKIPPING League (Platzierungsrunde): %s %s', bhv_id, name)
return
name = {
5380: "Männer Kreisliga 2-1",
5381: "Männer Kreisliga 2-2",
7424: "Männer Kreisliga C Staffel 3",
50351: "gemischte Jugend D Kreisliga A Staffel 1",
52853: "männliche Jugend C Bezirksliga Staffel 2",
}.get(bhv_id, name)

if "Meister" in name:
LOGGER.debug('SKIPPING League (Meisterschaft): %s %s', bhv_id, name)
if League.is_youth(abbreviation, name) and not self.options['youth']:
LOGGER.debug('SKIPPING League (youth league): %s %s %s', bhv_id, abbreviation, name)
return

if bhv_id == 7424:
name = "Männer Kreisliga C Staffel 3"

if bhv_id == 5380:
name = "Männer Kreisliga 2-1"

if bhv_id == 5381:
name = "Männer Kreisliga 2-2"

league, league_created = League.objects.get_or_create(
name=name, abbreviation=abbreviation, district=district, season=season, bhv_id=bhv_id)
if league_created:
LOGGER.info('CREATED League: %s', league)
else:
LOGGER.info('EXISTING League: %s', league)

if self.options['skip_teams']:
return

for team_link in team_links:
create_team(team_link, league)

Expand Down
31 changes: 31 additions & 0 deletions src/leagues/migrations/0002_update_league_names.py
@@ -0,0 +1,31 @@
import logging

from django.db import migrations

from base import logic, parsing

from ..models import League

LOGGER = logging.getLogger('hbscorez')


def update_league_names(*_):
for league in League.objects.all():
dom = logic.get_html(league.source_url())
name = parsing.parse_league_name(dom)
if name != league.name:
league.name = name
league.save()
LOGGER.info('RENAMED LEAGUE: %s', league)


class Migration(migrations.Migration):
atomic = False

dependencies = [
('leagues', '0001_initial'),
]

operations = [
migrations.RunPython(update_league_names),
]

0 comments on commit 4f042dd

Please sign in to comment.