fix runs_for runs_against bug in instagen
add instagen tests
This commit is contained in:
@@ -1 +1,75 @@
|
||||
# Create your tests here.
|
||||
import vcr
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import (
|
||||
BACKEND_SESSION_KEY,
|
||||
HASH_SESSION_KEY,
|
||||
SESSION_KEY,
|
||||
get_user_model,
|
||||
)
|
||||
from django.contrib.sessions.backends.db import SessionStore
|
||||
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
|
||||
from django.urls import reverse
|
||||
from selenium import webdriver
|
||||
|
||||
USER = get_user_model().objects.get(pk=2)
|
||||
vcr_options = {
|
||||
"path": "teamsnap/fixtures/tests.json",
|
||||
"ignore_localhost": True,
|
||||
"filter_headers": ["authorization"],
|
||||
"filter_query_parameters": ["email", "password"],
|
||||
# 'record_mode':"new_episodes",
|
||||
"decode_compressed_response": True,
|
||||
"allow_playback_repeats": True,
|
||||
}
|
||||
|
||||
|
||||
def create_session_cookie():
|
||||
|
||||
# Then create the authenticated session using the new user credentials
|
||||
session = SessionStore()
|
||||
session[SESSION_KEY] = USER.pk
|
||||
session[BACKEND_SESSION_KEY] = settings.AUTHENTICATION_BACKENDS[0]
|
||||
session[HASH_SESSION_KEY] = USER.get_session_auth_hash()
|
||||
session.save()
|
||||
|
||||
# Finally, create the cookie dictionary
|
||||
cookie = {
|
||||
"name": settings.SESSION_COOKIE_NAME,
|
||||
"value": session.session_key,
|
||||
"secure": False,
|
||||
"path": "/",
|
||||
}
|
||||
return cookie
|
||||
|
||||
|
||||
class InstagenTests(StaticLiveServerTestCase):
|
||||
fixtures = ["benchcoach/fixtures/dump.json"]
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.port = 8000
|
||||
super().setUpClass()
|
||||
cls.selenium = webdriver.Chrome("/opt/homebrew/bin/chromedriver")
|
||||
cls.selenium.implicitly_wait(10)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.selenium.quit()
|
||||
super().tearDownClass()
|
||||
|
||||
def setUp(self):
|
||||
session_cookie = create_session_cookie()
|
||||
self.selenium.get("{}{}".format(self.live_server_url, "/"))
|
||||
self.selenium.add_cookie(session_cookie)
|
||||
self.selenium.refresh()
|
||||
pass
|
||||
|
||||
@vcr.use_cassette(**vcr_options)
|
||||
def test_instagen(self):
|
||||
managed_team_id = USER.teamsnap_preferences.managed_team_id
|
||||
# event_id = 266446202
|
||||
url = reverse(
|
||||
"instagen", kwargs=dict(team_id=managed_team_id, event_id=266446216)
|
||||
)
|
||||
self.selenium.get(url=self.live_server_url + url)
|
||||
breakpoint()
|
||||
|
||||
@@ -63,8 +63,8 @@ def get_matchup_image(request, team_id, event_id, dimensions=None, background=No
|
||||
formatted_results = ts_event["formatted_results"]
|
||||
if formatted_results:
|
||||
# L 4-3
|
||||
runs_for = formatted_results.split(" ")[1].split("-")[0]
|
||||
runs_against = formatted_results.split(" ")[1].split("-")[1]
|
||||
runs_for = int(formatted_results.split(" ")[1].split("-")[0])
|
||||
runs_against = int(formatted_results.split(" ")[1].split("-")[1])
|
||||
else:
|
||||
runs_for, runs_against = None, None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user