Esempio n. 1
0
  def test_territory_exchange_with_resources_canceled(self):
    arthur = User.objects.get(username='******')
    brian = User.objects.get(username='******')

    aglax = Territory.objects.get(name='Aglax')
    efea = Territory.objects.get(name='Efea')

    offeror_r = Resources(currency=499)
    offeror_r.save()

    exchange = Exchange(offeror=arthur, offeror_territory=aglax,
                                        offeror_resources=offeror_r,
                        offeree=brian,  offeree_territory=efea)

    self.assertEqual(aglax.owner, arthur)
    self.assertEqual(efea.owner, brian)
    self.assertEqual(arthur.player.resources.currency, 1000)
    self.assertEqual(brian.player.resources.currency, 0)
    exchange.offer(user=arthur)
    self.assertEqual(arthur.player.resources.currency, 501)
    self.assertEqual(brian.player.resources.currency, 0)
    exchange.reject(user=brian)
    self.assertEqual(exchange.state, exchange.REJECTED)
    self.assertEqual(aglax.owner, arthur)
    self.assertEqual(efea.owner, brian)
    self.assertEqual(arthur.player.resources.currency, 1000)
    self.assertEqual(brian.player.resources.currency, 0)
Esempio n. 2
0
  def test_exchange_invalid_user(self):
    arthur = User.objects.get(username='******')
    brian = User.objects.get(username='******')
    dickens = User.objects.get(username='******')

    offeror_r = Resources(currency=100)
    offeror_r.save()

    offeree_r = Resources(agricultural=10)
    offeree_r.save()

    exchange = Exchange(offeror=arthur, offeror_resources=offeror_r,
                        offeree=brian,  offeree_resources=offeree_r)

    with self.assertRaisesRegexp(ValidationError,
      "“brian” is not the offeror of this exchange."):
      exchange.offer(user=brian)

    exchange.offer(user=arthur)

    with self.assertRaisesRegexp(ValidationError,
      "“arthur” is not the offeree of this exchange."):
      exchange.accept(user=arthur)

    with self.assertRaisesRegexp(ValidationError,
      "“arthur” is not the offeree of this exchange."):
      exchange.reject(user=arthur)

    with self.assertRaisesRegexp(ValidationError,
      "“brian” is not the offeror of this exchange."):
      exchange.cancel(user=brian)

    self.assertEqual(exchange.state, exchange.WAITING)
Esempio n. 3
0
  def test_territory_ask_donation_reject(self):
    arthur = User.objects.get(username='******')
    brian = User.objects.get(username='******')

    aglax = Territory.objects.get(name='Aglax')
    efea = Territory.objects.get(name='Efea')

    exchange = Exchange(offeror=arthur,
                        offeree=brian, offeree_territory=efea)

    self.assertEqual(efea.owner, brian)
    exchange.offer(user=arthur)
    exchange.reject(user=brian)
    self.assertEqual(efea.owner, brian)
Esempio n. 4
0
  def test_simple_exchange_cancel(self):
    arthur = User.objects.get(username='******')
    brian = User.objects.get(username='******')
    dickens = User.objects.get(username='******')

    offeror_r = Resources(currency=100)
    offeror_r.save()

    offeree_r = Resources(agricultural=10)
    offeree_r.save()

    exchange = Exchange(offeror=arthur, offeror_resources=offeror_r,
                        offeree=brian,  offeree_resources=offeree_r)

    self.assertEqual(brian.player.resources.currency, 0)
    self.assertEqual(brian.player.resources.agricultural, 11)

    self.assertEqual(arthur.player.resources.currency, 1000)
    self.assertEqual(arthur.player.resources.agricultural, 0)

    exchange.offer(user=arthur)
    self.assertEqual(exchange.state, exchange.WAITING)

    self.assertEqual(brian.player.resources.currency, 0)
    self.assertEqual(brian.player.resources.agricultural, 11)

    self.assertEqual(arthur.player.resources.currency, 900)
    self.assertEqual(arthur.player.resources.agricultural, 0)

    self.assertTrue(exchange.cancel(user=arthur))

    self.assertEqual(exchange.state, exchange.CANCELED)

    self.assertEqual(brian.player.resources.currency, 0)
    self.assertEqual(brian.player.resources.agricultural, 11)

    self.assertEqual(arthur.player.resources.currency, 1000)
    self.assertEqual(arthur.player.resources.agricultural, 0)

    with self.assertRaisesRegexp(ValidationError,
      "This exchange is not waiting for response."):
      exchange.accept(user=brian)

    with self.assertRaisesRegexp(ValidationError,
      "This exchange is not waiting for response."):
      exchange.reject(user=brian)

    with self.assertRaisesRegexp(ValidationError,
      "This exchange is not waiting for response."):
      exchange.cancel(user=arthur)
Esempio n. 5
0
  def test_territory_donation_reject(self):
    arthur = User.objects.get(username='******')
    brian = User.objects.get(username='******')

    aglax = Territory.objects.get(name='Aglax')
    efea = Territory.objects.get(name='Efea')

    exchange = Exchange(offeror=arthur, offeror_territory=aglax,
                        offeree=brian)

    self.assertEqual(aglax.owner, arthur)
    exchange.offer(user=arthur)
    exchange.reject(user=brian)
    self.assertEqual(exchange.state, exchange.REJECTED)
    self.assertEqual(aglax.owner, arthur)
Esempio n. 6
0
  def test_simple_ask_for_donation_reject(self):
    arthur = User.objects.get(username='******')
    brian = User.objects.get(username='******')

    offeree_r = Resources(agricultural=1)
    offeree_r.save()

    exchange = Exchange(offeror=arthur,
                        offeree=brian, offeree_resources=offeree_r)

    self.assertEqual(arthur.player.resources.agricultural, 0)
    self.assertEqual(brian.player.resources.agricultural, 11)
    exchange.offer(user=arthur)
    self.assertEqual(arthur.player.resources.agricultural, 0)
    self.assertEqual(brian.player.resources.agricultural, 11)
    exchange.reject(user=brian)
    self.assertEqual(exchange.state, exchange.REJECTED)
    self.assertEqual(arthur.player.resources.agricultural, 0)
    self.assertEqual(brian.player.resources.agricultural, 11)
Esempio n. 7
0
  def test_simple_donation_reject(self):
    arthur = User.objects.get(username='******')
    brian = User.objects.get(username='******')

    offeror_r = Resources(currency=1)
    offeror_r.save()

    exchange = Exchange(offeror=arthur, offeror_resources=offeror_r,
                        offeree=brian)

    self.assertEqual(arthur.player.resources.currency, 1000)
    self.assertEqual(brian.player.resources.currency, 0)
    exchange.offer(user=arthur)
    self.assertEqual(arthur.player.resources.currency, 999)
    self.assertEqual(brian.player.resources.currency, 0)
    exchange.reject(user=brian)
    self.assertEqual(exchange.state, exchange.REJECTED)
    self.assertEqual(arthur.player.resources.currency, 1000)
    self.assertEqual(brian.player.resources.currency, 0)
Esempio n. 8
0
  def test_territory_buy_reject(self):
    arthur = User.objects.get(username='******')
    brian = User.objects.get(username='******')

    aglax = Territory.objects.get(name='Aglax')
    efea = Territory.objects.get(name='Efea')

    offeree_r = Resources(agricultural=10)
    offeree_r.save()

    exchange = Exchange(offeror=arthur, offeror_territory=aglax,
                        offeree=brian,  offeree_resources=offeree_r)

    self.assertEqual(aglax.owner, arthur)
    self.assertEqual(arthur.player.resources.agricultural, 0)
    self.assertEqual(brian.player.resources.agricultural, 11)
    exchange.offer(user=arthur)
    self.assertEqual(arthur.player.resources.agricultural, 0)
    self.assertEqual(brian.player.resources.agricultural, 11)
    exchange.reject(user=brian)
    self.assertEqual(exchange.state, exchange.REJECTED)
    self.assertEqual(aglax.owner, arthur)
    self.assertEqual(arthur.player.resources.agricultural, 0)
    self.assertEqual(brian.player.resources.agricultural, 11)