def test_validation(self): with self.subTest("with a valid team"): self.assertIsNone(self.team.full_clean()) with self.subTest("with unrecognized team name"): team = Team(name="Bob") with self.assertRaises(ValidationError): team.full_clean() with self.subTest("with duplicate team name"): Team.objects.create(name="Richmond") with self.assertRaises(ValidationError): self.team.full_clean()
def setUp(self): tomorrow = datetime.now() + timedelta(days=1) year = tomorrow.year team_names = TEAM_NAMES[:] # Mock footywire fixture data self.fixture_data = [{ "date": tomorrow, "season": year, "round": 1, "round_label": "Round 1", "crows": 1234, "home_team": team_names.pop(), "away_team": team_names.pop(), "home_score": 50, "away_score": 100, "venue": FAKE.city(), } for idx in range(ROW_COUNT)] footywire = FootywireDataReader() footywire.get_fixture = Mock( return_value=pd.DataFrame(self.fixture_data)) # Mock bulk_create to make assertions on calls pred_bulk_create = copy.copy(Prediction.objects.bulk_create) Prediction.objects.bulk_create = Mock( side_effect=self.__pred_bulk_create(pred_bulk_create)) # Save records in DB for match_data in self.fixture_data: Team(name=match_data["home_team"]).save() Team(name=match_data["away_team"]).save() betting_model = BettingModel(name="betting_data") pickle_filepath = os.path.abspath( os.path.join(BASE_DIR, "server", "tests", "fixtures", "betting_model.pkl")) MLModel( name=betting_model.name, description="Betting data model", filepath=pickle_filepath, data_class_path=BettingModelData.class_path(), ).save() self.tip_command = tip.Command(data_reader=footywire)
def replace_imported_bots(json_text): Game.query.delete() Bot.query.delete() Team.query.delete() data = json.loads(json_text) for team in data['teams']: new_team = Team(team['name']) db.session.add(new_team) for bot in team['bots']: new_bot = Bot(new_team, bot['name'], bot['s3_key']) db.session.add(new_bot) db.session.commit()
def setUp(self): self.maxDiff = None self.client = Client(schema) home_team = Team(name="Richmond") home_team.save() away_team = Team(name="Melbourne") away_team.save() match_datetime = timezone.make_aware(datetime(2018, 5, 5)) new_match = Match(start_date_time=match_datetime, round_number=5) new_match.save() match_datetime = timezone.make_aware(datetime(2014, 5, 5)) old_match = Match(start_date_time=match_datetime, round_number=7) old_match.save() (TeamMatch(team=home_team, match=new_match, at_home=True, score=150).save()) (TeamMatch(team=away_team, match=new_match, at_home=False, score=100).save()) (TeamMatch(team=home_team, match=old_match, at_home=True, score=150).save()) (TeamMatch(team=away_team, match=old_match, at_home=False, score=100).save()) ml_model = MLModel(name="test_model") ml_model.save() new_prediction = Prediction( match=new_match, ml_model=ml_model, predicted_winner=home_team, predicted_margin=50, ) new_prediction.save() old_prediction = Prediction( match=old_match, ml_model=ml_model, predicted_winner=away_team, predicted_margin=50, ) old_prediction.save()
def create_team(): payload = request.json # validate payload assert payload is not None, 'missing json body' ValidationError.raise_assert('team_name' in payload, 'team_name required') team_name = payload['team_name'] # check duplicates duplicates = db.session.query(Team).filter_by(team_name=team_name).first() ValidationError.raise_assert(duplicates is None, 'team "{}" already exists'.format(team_name)) new_team = Team(team_name=team_name, ) db.session.add(new_team) db.session.commit() output = {'team_id': new_team.id, 'team_name': new_team.team_name} return jsonify({'team': output}), 201
def __build_team(team_name: str) -> Team: team = Team(name=team_name) team.full_clean() return team
def setUp(self): self.team = Team(name="Richmond")