intial commit of tests, documentation

This commit is contained in:
2022-11-05 13:53:37 -05:00
parent 9085c184bf
commit 852acafcae
115 changed files with 21599 additions and 1229 deletions

47
tests/base.py Normal file
View File

@@ -0,0 +1,47 @@
#!/usr/bin/env python
"""Tests for `pyteamsnap` package."""
import unittest
from unittest import TestCase
from pyteamsnap import client
from os import getenv
from pyteamsnap.models.base import BaseApiObject
import vcr
TEAMSNAP_TOKEN = getenv('TEAMSNAP_TOKEN')
TEAMSNAP_TEAM = getenv('TEAMSNAP_TEAM')
TEAMSNAP_EVENT = getenv('TEAMSNAP_EVENT')
vcr_options = {
'decode_compressed_response': True,
'cassette_library_dir':'tests/fixtures/cassettes',
'filter_headers':['authorization']
}
class BaseModelTestCase:
"""Tests for `pyteamsnap` package."""
__test__= False
TestClass: BaseApiObject = None
@classmethod
def setUpClass(cls) -> None:
"""Set up test fixtures, if any."""
cls.TEAMSNAP_TOKEN = getenv('TEAMSNAP_TOKEN')
cls.TEAMSNAP_TEAM = int(getenv('TEAMSNAP_TEAM'))
with vcr.use_cassette("client.yml", **vcr_options):
cls.client = client.TeamSnap(token=TEAMSNAP_TOKEN)
cls.cassette = vcr.use_cassette(f"{cls.__name__}.yml", **vcr_options)
super().setUpClass()
def test_data(self):
with self.cassette:
search_results = self.TestClass.search(self.client, team_id=self.TEAMSNAP_TEAM)
instance = search_results[0]
self.assertIsInstance(instance, self.TestClass)
self.assertTrue(len(instance.data))
return instance

0
tests/fixtures/.gitkeep vendored Normal file
View File

0
tests/fixtures/cassettes/.gitkeep vendored Normal file
View File

View File

@@ -0,0 +1,10 @@
from tests.base import BaseModelTestCase
from unittest import TestCase
from pyteamsnap.models import Availability
class TestAvailability(BaseModelTestCase, TestCase):
__test__ = True
TestClass = Availability

View File

@@ -0,0 +1,7 @@
from tests.base import BaseModelTestCase
from unittest import TestCase
from pyteamsnap.models import AvailabilitySummary
class TestAvailabilitySummary(BaseModelTestCase, TestCase):
__test__ = True
TestClass = AvailabilitySummary

8
tests/test_event.py Normal file
View File

@@ -0,0 +1,8 @@
from tests.base import BaseModelTestCase
from unittest import TestCase
from pyteamsnap.models import Event
class TestEvent(BaseModelTestCase, TestCase):
__test__ = True
TestClass = Event

18
tests/test_eventlineup.py Normal file
View File

@@ -0,0 +1,18 @@
from tests.base import BaseModelTestCase
from unittest import TestCase
from pyteamsnap.models import EventLineup, Event
class TestEventLineup(BaseModelTestCase, TestCase):
__test__ = True
TestClass = EventLineup
def test_data(self):
with self.cassette:
event_search_results = Event.search(self.client, team_id=self.TEAMSNAP_TEAM)
event_instance = event_search_results[0]
search_results = self.TestClass.search(self.client, event_id=event_instance.id)
instance = search_results[0]
self.assertIsInstance(instance, self.TestClass)
self.assertTrue(len(instance.data))
return instance

View File

@@ -0,0 +1,20 @@
import unittest
from tests.base import BaseModelTestCase
from unittest import TestCase
from pyteamsnap.models import EventLineupEntry, Event
@unittest.skip("EventLineupEntry Test Known to Fail, need to figure out how to filter events that have a lineup and therefore entries")
class TestEventLineupEntry(BaseModelTestCase, TestCase):
__test__ = True
TestClass = EventLineupEntry
def test_data(self):
with self.cassette:
event_search_results = Event.search(self.client, team_id=self.TEAMSNAP_TEAM)
event_instance = event_search_results[0]
search_results = self.TestClass.search(self.client, event_id=event_instance.id)
instance = search_results[0]
self.assertIsInstance(instance, self.TestClass)
self.assertTrue(len(instance.data))
return instance

8
tests/test_location.py Normal file
View File

@@ -0,0 +1,8 @@
from tests.base import BaseModelTestCase
from unittest import TestCase
from pyteamsnap.models import Location
class TestLocation(BaseModelTestCase, TestCase):
__test__ = True
TestClass = Location

12
tests/test_me.py Normal file
View File

@@ -0,0 +1,12 @@
from tests.base import BaseModelTestCase
from unittest import TestCase
from pyteamsnap.models import Me, User
class TestMe(BaseModelTestCase, TestCase):
def test_data(self):
with self.cassette:
instance = Me(self.client)
self.assertIsInstance(instance, User)
self.assertTrue(len(instance.data))
pass

8
tests/test_member.py Normal file
View File

@@ -0,0 +1,8 @@
from tests.base import BaseModelTestCase
from unittest import TestCase
from pyteamsnap.models import Member
class TestMember(BaseModelTestCase, TestCase):
__test__ = True
TestClass = Member

8
tests/test_opponent.py Normal file
View File

@@ -0,0 +1,8 @@
from tests.base import BaseModelTestCase
from unittest import TestCase
from pyteamsnap.models import Opponent
class TestOpponent(BaseModelTestCase, TestCase):
__test__ = True
TestClass = Opponent

View File

@@ -1,37 +0,0 @@
#!/usr/bin/env python
"""Tests for `pyteamsnap` package."""
import unittest
from pyteamsnap import client
from os import getenv
TEAMSNAP_TOKEN = getenv('TEAMSNAP_TOKEN')
TEAMSNAP_TEAM = getenv('TEAMSNAP_TEAM')
TEAMSNAP_EVENT = getenv('TEAMSNAP_EVENT')
class TestPyteamsnap(unittest.TestCase):
"""Tests for `pyteamsnap` package."""
def setUp(self):
"""Set up test fixtures, if any."""
self.TEAMSNAP_TOKEN = getenv('TEAMSNAP_TOKEN')
self.TEAMSNAP_TEAM = getenv('TEAMSNAP_TEAM')
self.TEAMSNAP_EVENT = getenv('TEAMSNAP_EVENT')
self.client = client.TeamSnap(token=TEAMSNAP_TOKEN)
def tearDown(self):
"""Tear down test fixtures, if any."""
def test_000_me(self):
"""Test something."""
from pyteamsnap.objects import Me
me = Me(self.client)
pass
def test_001_bulk_load(self):
from pyteamsnap.objects import Event
events = self.client.bulk_load(team_id=self.TEAMSNAP_TEAM, types=[objects.Event])
pass

8
tests/test_statistics.py Normal file
View File

@@ -0,0 +1,8 @@
from tests.base import BaseModelTestCase
from unittest import TestCase
from pyteamsnap.models import Statistics
class TestStatistics(BaseModelTestCase, TestCase):
__test__ = True
TestClass = Statistics

15
tests/test_team.py Normal file
View File

@@ -0,0 +1,15 @@
from tests.base import BaseModelTestCase
from unittest import TestCase
from pyteamsnap.models import Team
class TestTeam(BaseModelTestCase, TestCase):
__test__ = True
TestClass = Team
def test_data(self):
instance = super().test_data()
self.assertEqual(instance.id, self.TEAMSNAP_TEAM)
# assertDictContainsSubset is deprecated
# https://stackoverflow.com/a/59777678
self.assertEqual(instance.data["id"], self.TEAMSNAP_TEAM)

15
tests/test_user.py Normal file
View File

@@ -0,0 +1,15 @@
from tests.base import BaseModelTestCase
from unittest import TestCase
from pyteamsnap.models import User, Me
class TestUser(BaseModelTestCase, TestCase):
__test__ = True
TestClass = User
def test_data(self):
with self.cassette:
instance = Me(self.client)
self.assertIsInstance(instance, User)
self.assertTrue(len(instance.data))
pass