def test_cannot_creditor_debtor_and_estate_from_different_game(self): creditor = PlayerFactory() debtor = PlayerFactory() estate = RealEstateFactory() my_transaction = Transaction( creditor=creditor, debtor=debtor, real_estate=estate ) with self.assertRaises(ValidationError): my_transaction.full_clean()
def test_unique_player_names_no_conflict(self): player1 = PlayerFactory() player2 = PlayerFactory(name=player1.name) player1.full_clean() player2.full_clean() self.assertTrue(player1 in Player.objects.all()) self.assertTrue(player2 in Player.objects.all())
def test_timestamp(self): estate = RealEstateFactory() creditor = PlayerFactory(game=estate.game) debtor = PlayerFactory(game=estate.game) mocked = datetime.datetime(2021, 3, 3, 0, 2, 3, tzinfo=pytz.utc) with mock.patch("django.utils.timezone.now", mock.Mock(return_value=mocked)): my_transaction = Transaction( real_estate=estate, creditor=creditor, debtor=debtor, amount=Decimal("12.90"), ) my_transaction.save() self.assertEqual(my_transaction.timestamp, mocked)
def test_create_transaction_with_realestate(self): estate = RealEstateFactory() creditor = PlayerFactory(game=estate.game) debtor = PlayerFactory(game=estate.game) my_transaction = Transaction( real_estate=estate, creditor=creditor, debtor=debtor, amount=Decimal("12.90"), ) my_transaction.full_clean() my_transaction.save() self.assertTrue(my_transaction in Transaction.objects.all()) self.assertEqual(my_transaction.real_estate, estate) self.assertEqual(my_transaction.debtor, debtor) self.assertEqual(my_transaction.creditor, creditor) self.assertEqual(my_transaction.amount, Decimal("12.90"))
def test_buy_timestamp(self): estate = RealEstateFactory() player = PlayerFactory(game=estate.game) mocked = datetime.datetime(2021, 3, 3, 0, 2, 3, tzinfo=pytz.utc) with mock.patch("django.utils.timezone.now", mock.Mock(return_value=mocked)): my_ownership = Ownership(real_estate=estate, player=player) my_ownership.save() self.assertEqual(my_ownership.buy_timestamp, mocked)
def test_create_ownership(self): estate = RealEstateFactory() player = PlayerFactory(game=estate.game) my_ownership = Ownership(real_estate=estate, player=player) my_ownership.full_clean() my_ownership.save() self.assertTrue(my_ownership in Ownership.objects.all()) self.assertEqual(my_ownership.real_estate, estate) self.assertEqual(my_ownership.player, player)
def test_cannot_player_and_realestate_from_different_game(self): player = PlayerFactory() estate = RealEstateFactory() my_ownership = Ownership(player=player, real_estate=estate) with self.assertRaises(ValidationError): my_ownership.full_clean()
def test_cannot_create_ownership_without_realestate(self): ownership = Ownership(player=PlayerFactory()) with self.assertRaises(IntegrityError): ownership.save()
def test_delete_game_deletes_player(self): player = PlayerFactory() player.save() game = player.game game.delete() self.assertTrue(player not in Player.objects.all())
def test_delete_player_does_not_delete_game(self): my_player = PlayerFactory() my_game = my_player.game my_player.delete() self.assertTrue(my_player not in Player.objects.all()) self.assertTrue(my_game in Game.objects.all())
def test_unique_player_names_conflict(self): player1 = PlayerFactory() with self.assertRaises(IntegrityError): player2 = PlayerFactory(game=player1.game, name=player1.name)