from unittest import TestCase, mock
from players.utils import update_players_db
from players.models import Player
from .tests_utils import create_mock_players_data

class UpdatePlayersDBTest(TestCase):
    @mock.patch('players.utils.get_players_data')
    def test_update_players_db(self, mock_get_players_data):
        player_data = create_mock_players_data()

        # Call the update_players_db function
        update_players_db(player_data)

        # Verify that the players were added to the database with correct data
        player_1 = Player.objects.get(player_id='1')
        self.assertEqual(player_1.first_name, 'Patrick')
        self.assertEqual(player_1.last_name, 'Mahomes')
        self.assertEqual(player_1.position, 'QB')
        self.assertEqual(player_1.team, 'KC')

        player_2 = Player.objects.get(player_id='2')
        self.assertEqual(player_2.first_name, 'Tom')
        self.assertEqual(player_2.last_name, 'Brady')
        self.assertEqual(player_2.position, 'QB')
        self.assertEqual(player_2.team, 'NE')
