Esempio n. 1
0
 def test_unique_realestate_names_no_conflict(self):
     estate1 = RealEstateFactory()
     estate2 = RealEstateFactory(name=estate1.name)
     estate1.full_clean()
     estate2.full_clean()
     self.assertTrue(estate1 in RealEstate.objects.all())
     self.assertTrue(estate2 in RealEstate.objects.all())
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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()
Esempio n. 5
0
 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)
Esempio n. 6
0
 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"))
Esempio n. 7
0
 def test_delete_game_deletes_realestate(self):
     estate = RealEstateFactory()
     estate.save()
     game = estate.game
     game.delete()
     self.assertTrue(estate not in RealEstate.objects.all())
Esempio n. 8
0
 def test_delete_realestate_does_not_delete_game(self):
     estate = RealEstateFactory()
     my_game = estate.game
     estate.delete()
     self.assertTrue(estate not in RealEstate.objects.all())
     self.assertTrue(my_game in Game.objects.all())
Esempio n. 9
0
 def test_unique_realestate_names_conflict(self):
     estate1 = RealEstateFactory()
     with self.assertRaises(IntegrityError):
         estate2 = RealEstateFactory(game=estate1.game, name=estate1.name)
Esempio n. 10
0
 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()
Esempio n. 11
0
 def test_cannot_create_ownership_without_player(self):
     ownership = Ownership(real_estate=RealEstateFactory())
     with self.assertRaises(IntegrityError):
         ownership.save()