def test_league_answers(self):
        data = DataSetup('api_league_answers')
        data.create_users(3)
        data.create_leagues(1)
        data.create_member(data.user[0].get_object(), data.league[0], True)
        data.create_member(data.user[1].get_object(), data.league[0], False)
        data.create_prop_bet(data.league[0], False)
        data.create_prop_bet(data.league[0], False)
        data.create_prop_bet(data.league[0], False)

        url = '/api/league/answers'
        request = {
            'league_name': data.league[0].name,
            'answers': {
                data.prop_bet[0].title: True,
                data.prop_bet[1].title: True,
                data.prop_bet[2].title: True
            }
        }
        username = data.user[0].name
        self.auth_test(url, request)
        self.parameter_checks(url, request, username)

        # invalid league
        request = {
            'league_name': 'invalid_league',
            'answers': {
                data.prop_bet[0].title: True,
                data.prop_bet[1].title: True,
                data.prop_bet[2].title: True
            }
        }
        response = {
            'success': False,
            'errors': ['League and user do not match (user must be admin).']
        }
        self.custom_test(url, request, response, username)
        # not in league
        request = {
            'league_name': data.league[0].name,
            'answers': {
                data.prop_bet[0].title: True,
                data.prop_bet[1].title: True,
                data.prop_bet[2].title: True
            }
        }
        username = data.user[2].name
        self.custom_test(url, request, response, username)
        # not admin
        username = data.user[1].name
        self.custom_test(url, request, response, username)
        # valid
        response = {'success': True}
        username = data.user[0].name
        self.custom_test(url, request, response, username)
        # check data is created
        for x in range(0, 3):
            db_models.PropBet.objects.get(title=data.prop_bet[x].title,
                                          league=data.league[0],
                                          answer=True)
    def test_member_update_picks(self):
        data = DataSetup('api_member_update_picks')
        data.create_users(2)
        data.create_leagues(1)
        data.create_member(data.user[0].get_object(), data.league[0], False)
        data.create_prop_bet(data.league[0], True)
        data.create_prop_bet(data.league[0], True)
        data.create_prop_bet(data.league[0], True)

        url = '/api/member/picks/update'
        request = {
            'league_name': data.league[0].name,
            'picks': {
                data.prop_bet[0].title: False,
                data.prop_bet[1].title: False,
                data.prop_bet[2].title: False
            }
        }
        username = data.user[0].name
        self.auth_test(url, request)
        self.parameter_checks(url, request, username)

        # invalid league
        request = {
            'league_name': 'invalid_league',
            'picks': {
                data.prop_bet[0].title: False,
                data.prop_bet[1].title: False,
                data.prop_bet[2].title: False
            }
        }
        response = {
            'success': False,
            'errors': ['League and user do not match.']
        }
        username = data.user[0].name
        self.custom_test(url, request, response, username)
        # not in league
        request = {
            'league_name': data.league[0].name,
            'picks': {
                data.prop_bet[0].title: False,
                data.prop_bet[1].title: False,
                data.prop_bet[2].title: False
            }
        }
        username = data.user[1].name
        self.custom_test(url, request, response, username)
        # valid
        response = {'success': True}
        username = data.user[0].name
        self.custom_test(url, request, response, username)
        # check data is updated
        for x in range(0, 3):
            db_models.Pick.objects.get(member=data.member[0],
                                       prop_bet=data.prop_bet[x],
                                       response=False)
示例#3
0
  def test_league_answers_submit(self):
    data = DataSetup('ui_league_answers_submit')
    data.create_users(3)
    data.create_leagues(1)
    data.create_member(data.user[0].get_object(), data.league[0], True)
    data.create_member(data.user[1].get_object(), data.league[0], False)
    data.create_prop_bet(data.league[0], True)
    data.create_prop_bet(data.league[0], True)
    data.create_prop_bet(data.league[0], True)
    url = '/ui/league/answers/submit'

    self.auth_test(url)

    response_template = 'ui/landing.html'
    response_context = {'message': 
      'Error: League is invalid or you are not a member.'}
    payload = {'league_name': data.league[0].name, data.prop_bet[0].title: False, 
      data.prop_bet[1].title: False, data.prop_bet[2].title: False}
    # not member
    username = data.user[2].name
    self.custom_test(url, 'POST', response_template, response_context, 
      payload=payload, username=username)
    # invalid league
    payload = {'league_name': 'invalid_league', data.prop_bet[0].title: False, 
      data.prop_bet[1].title: False, data.prop_bet[2].title: False}
    username = data.user[0].name
    self.custom_test(url, 'POST', response_template, response_context, 
      payload=payload, username=username)
    response_template = 'ui/league_home.html'
    # missing answers
    response_context = {'message': 'Error: Answers block is invalid or missing.'}
    payload = {'league_name': data.league[0].name}
    username = data.user[0].name
    self.custom_test(url, 'POST', response_template, response_context, 
      payload=payload, username=username)
    # not admin
    response_context = {'message': 'Error: You must be an admin to update league answers.'}
    payload = {'league_name': data.league[0].name, data.prop_bet[0].title: False, 
      data.prop_bet[1].title: False, data.prop_bet[2].title: False}
    username = data.user[1].name
    self.custom_test(url, 'POST', response_template, response_context, 
      payload=payload, username=username)
    # valid
    response_context = {'message': 'Successfully updated league answers.'}
    username = data.user[0].name
    self.custom_test(url, 'POST', response_template, response_context, 
      payload=payload, username=username)
    # check data is updated
    for x in range(0, 3):
      db_models.PropBet.objects.get(title=data.prop_bet[x].title, 
        league=data.league[0], answer=False)
示例#4
0
  def test_league_picks(self):
    data = DataSetup('ui_league_picks')
    data.create_users(3)
    data.create_leagues(1)
    data.create_member(data.user[0].get_object(), data.league[0], True)
    data.create_member(data.user[1].get_object(), data.league[0], True)
    data.create_prop_bet(data.league[0], True)
    data.create_prop_bet(data.league[0], True)
    data.create_prop_bet(data.league[0], True)
    data.create_pick(data.member[0], data.prop_bet[0], False)
    data.create_pick(data.member[0], data.prop_bet[1], False)
    data.create_pick(data.member[0], data.prop_bet[2], False)
    url = '/ui/league/picks/%s' % data.league[0].name

    self.auth_test(url)

    response_template = 'ui/landing.html'
    response_context = {'message': 
      'Error: League is invalid or you are not a member.'}
    # not member
    username = data.user[2].name
    self.custom_test(url, 'GET', response_template, response_context, 
      username=username)
    # invalid league
    username = data.user[0].name
    url = '/ui/league/picks/invalid_league'
    self.custom_test(url, 'GET', response_template, response_context, 
      username=username)
    url = '/ui/league/picks/%s' % data.league[0].name
    # valid without picks
    username = data.user[1].name
    response_template = 'ui/league_entry.html'
    response_context = {'user': data.user[1].get_object(), 'league_name': 
      data.league[0].name, 'answers': False, 'prop_bets': 
      {data.prop_bet[0].title: None, data.prop_bet[1].title: None, 
      data.prop_bet[2].title: None}}
    self.custom_test(url, 'GET', response_template, response_context, 
      username=username)
    # valid with picks
    username = data.user[0].name
    response_context = {'user': data.user[0].get_object(), 'league_name': 
      data.league[0].name, 'answers': False, 'prop_bets': 
      {data.prop_bet[0].title: False, data.prop_bet[1].title: False, 
      data.prop_bet[2].title: False}} 
    self.custom_test(url, 'GET', response_template, response_context, 
      username=username)
示例#5
0
  def test_league_answers(self):
    data = DataSetup('ui_league_answers')
    data.create_users(3)
    data.create_leagues(1)
    data.create_member(data.user[0].get_object(), data.league[0], True)
    data.create_member(data.user[1].get_object(), data.league[0], False)
    data.create_prop_bet(data.league[0], True)
    data.create_prop_bet(data.league[0], True)
    data.create_prop_bet(data.league[0], True)
    url = '/ui/league/answers/%s' % data.league[0].name

    self.auth_test(url)

    response_template = 'ui/landing.html'
    response_context = {'message': 
      'Error: League is invalid or you are not a member.'}
    # not member
    username = data.user[2].name
    self.custom_test(url, 'GET', response_template, response_context, 
      username=username)
    # invalid league
    url = '/ui/league/answers/invalid_league'
    username = data.user[0].name
    self.custom_test(url, 'GET', response_template, response_context, 
      username=username)
    url = '/ui/league/answers/%s' % data.league[0].name
    # not admin
    username = data.user[1].name 
    response_template = 'ui/league_home.html'
    response_context = {'message': 
      'Error: You must be an admin to update league answers.'}
    self.custom_test(url, 'GET', response_template, response_context, 
      username=username)
    # valid
    username = data.user[0].name 
    response_template = 'ui/league_entry.html'
    response_context = {'user': data.user[0].get_object(), 'league_name': 
      data.league[0].name, 'answers': True, 'prop_bets': {data.prop_bet[0].title: 
      True, data.prop_bet[1].title: True, data.prop_bet[2].title: True}}
    self.custom_test(url, 'GET', response_template, response_context, 
      username=username)
    def test_member_get_picks(self):
        data = DataSetup('api_member_get_picks')
        data.create_users(3)
        data.create_leagues(2)
        data.create_member(data.user[0].get_object(), data.league[0], False)
        data.create_member(data.user[1].get_object(), data.league[0], False)
        data.create_member(data.user[0].get_object(), data.league[1], False)
        data.create_prop_bet(data.league[0], True)
        data.create_prop_bet(data.league[0], False)
        data.create_prop_bet(data.league[0], True)
        data.create_pick(data.member[0], data.prop_bet[0], True)
        data.create_pick(data.member[0], data.prop_bet[1], False)
        data.create_pick(data.member[0], data.prop_bet[2], True)

        url = '/api/member/picks/get'
        request = {'league_name': data.league[0].name}
        username = data.user[0].name
        self.auth_test(url, request)
        self.parameter_checks(url, request, username)

        # invalid league
        request = {'league_name': 'invalid_league'}
        response = {
            'success': False,
            'errors': ['League and user do not match.']
        }
        self.custom_test(url, request, response, username)
        # not in league
        request = {'league_name': data.league[0].name}
        username = data.user[2].name
        self.custom_test(url, request, response, username)
        # valid, no picks & no prop bets
        request = {'league_name': data.league[1].name}
        response = {'success': True, 'picks': {}}
        username = data.user[0].name
        self.custom_test(url, request, response, username)
        # valid, no picks (returns default False for each prop bet)
        request = {'league_name': data.league[0].name}
        response = {
            'success': True,
            'picks': {
                data.prop_bet[0].title: False,
                data.prop_bet[1].title: False,
                data.prop_bet[2].title: False
            }
        }
        username = data.user[1].name
        self.custom_test(url, request, response, username)
        # valid, picks
        response = {
            'success': True,
            'picks': {
                data.prop_bet[0].title: True,
                data.prop_bet[1].title: False,
                data.prop_bet[2].title: True
            }
        }
        username = data.user[0].name
        self.custom_test(url, request, response, username)
    def test_league_prop_bets(self):
        data = DataSetup('api_league_prop_bets')
        data.create_users(2)
        data.create_leagues(1)
        data.create_member(data.user[0].get_object(), data.league[0], False)
        data.create_prop_bet(data.league[0], False)
        data.create_prop_bet(data.league[0], False)

        url = '/api/league/prop-bets'
        request = {'league_name': data.league[0].name}
        username = data.user[0].name
        self.auth_test(url, request)
        self.parameter_checks(url, request, username)

        # invalid league
        request = {'league_name': 'invalid_league'}
        response = {
            'success': False,
            'errors': ['League and user do not match.']
        }
        self.custom_test(url, request, response, username)
        # not in league
        request = {'league_name': data.league[0].name}
        username = data.user[1].name
        self.custom_test(url, request, response, username)
        # valid
        request = {'league_name': data.league[0].name}
        response = {
            'success': True,
            'prop_bets': {
                data.prop_bet[0].title: False,
                data.prop_bet[1].title: False
            }
        }
        username = data.user[0].name
        self.custom_test(url, request, response, username)
    def test_league_scoreboard(self):
        data = DataSetup('api_league_scoreboard')
        data.create_users(4)
        data.create_leagues(1)
        data.create_member(data.user[0].get_object(), data.league[0], False)
        data.create_member(data.user[1].get_object(), data.league[0], False)
        data.create_member(data.user[2].get_object(), data.league[0], False)
        data.create_prop_bet(data.league[0], True)
        data.create_prop_bet(data.league[0], False)
        data.create_prop_bet(data.league[0], True)
        data.create_pick(data.member[0], data.prop_bet[0], True)
        data.create_pick(data.member[0], data.prop_bet[1], False)
        data.create_pick(data.member[0], data.prop_bet[2], True)
        data.create_pick(data.member[1], data.prop_bet[0], False)
        data.create_pick(data.member[1], data.prop_bet[1], False)
        data.create_pick(data.member[1], data.prop_bet[2], False)
        data.create_pick(data.member[2], data.prop_bet[0], False)
        data.create_pick(data.member[2], data.prop_bet[1], True)
        data.create_pick(data.member[2], data.prop_bet[2], False)

        url = '/api/league/scoreboard'
        request = {'league_name': data.league[0].name}
        username = data.user[0].name
        self.auth_test(url, request)
        self.parameter_checks(url, request, username)

        # invalid league
        request = {'league_name': 'invalid_league'}
        response = {
            'success': False,
            'errors': ['League and user do not match.']
        }
        self.custom_test(url, request, response, username)
        # not in league
        request = {'league_name': data.league[0].name}
        username = data.user[3].name
        self.custom_test(url, request, response, username)
        # valid
        response = {
            'scoreboard': [{
                'username': data.user[0].name,
                'score': 3
            }, {
                'username': data.user[1].name,
                'score': 1
            }, {
                'username': data.user[2].name,
                'score': 0
            }],
            'success':
            True
        }
        username = data.user[0].name
        self.custom_test(url, request, response, username)
示例#9
0
  def test_scoreboard(self):
    data = DataSetup('ui_scoreboard')
    data.create_users(4)
    data.create_leagues(1)
    data.create_member(data.user[0].get_object(), data.league[0], False)
    data.create_member(data.user[1].get_object(), data.league[0], False)
    data.create_member(data.user[2].get_object(), data.league[0], False)
    data.create_prop_bet(data.league[0], True)
    data.create_prop_bet(data.league[0], False)
    data.create_prop_bet(data.league[0], True)
    data.create_pick(data.member[0], data.prop_bet[0], True)
    data.create_pick(data.member[0], data.prop_bet[1], False)
    data.create_pick(data.member[0], data.prop_bet[2], True)
    data.create_pick(data.member[1], data.prop_bet[0], False)
    data.create_pick(data.member[1], data.prop_bet[1], False)
    data.create_pick(data.member[1], data.prop_bet[2], False)
    data.create_pick(data.member[2], data.prop_bet[0], False)
    data.create_pick(data.member[2], data.prop_bet[1], True)
    data.create_pick(data.member[2], data.prop_bet[2], False)
    url = '/ui/league/scoreboard/%s' % data.league[0].name

    self.auth_test(url)

    response_template = 'ui/landing.html'
    response_context = {'message': 
      'Error: League is invalid or you are not a member.'}
    # invalid league
    username = data.user[0].name 
    url = '/ui/league/scoreboard/invalid_league'
    self.custom_test(url, 'GET', response_template, response_context, 
      username=username)
    # not member
    username = data.user[3].name 
    url = '/ui/league/scoreboard/%s' % data.league[0].name
    self.custom_test(url, 'GET', response_template, response_context, 
      username=username)
    # valid
    response_template = 'ui/league_scoreboard.html'
    response_context = {'scores': [{'username': data.user[0].name, 'score': 3}, 
      {'username': data.user[1].name, 'score': 1}, 
      {'username': data.user[2].name, 'score': 0}]}
    username = data.user[1].name
    self.custom_test(url, 'GET', response_template, response_context, 
      username=username)