예제 #1
0
class SetLocationTest(TestCase):

    def setUp(self):
        self.client = Client()
        self.url = '/set_location/'
        self.location = any_model(MyCustomLocation)

        self.location_model_patcher = patch.object(settings, 'GEOIP_LOCATION_MODEL', 'test_app.models.MyCustomLocation')
        self.location_model = self.location_model_patcher.start()

    def tearDown(self):
        self.location_model_patcher.stop()

    def test_get(self):
        response = self.client.get(self.url, data={'location_id': self.location.id})
        self.assertFalse(settings.GEOIP_COOKIE_NAME in response.cookies)
        self.assertRedirects(response, 'http://testserver/')

    def test_get_or_post_next_url(self):
        for method in ['get', 'post']:
            method_call = getattr(self.client, method)
            response = method_call(self.url, data={'next': '/hello/',
                                                   'location_id': self.location.id})
            self.assertRedirects(response, 'http://testserver/hello/')

    def test_post_ok(self):
        response = self.client.post(self.url, data={'location_id': self.location.id})
        self.assertEqual(response.cookies[settings.GEOIP_COOKIE_NAME].value, str(self.location.id))
        self.assertRedirects(response, 'http://testserver/')

    def test_post_fake_location(self):
        response = self.client.post(self.url, data={'location_id': self.location.id+1})
        self.assertFalse(settings.GEOIP_COOKIE_NAME in response.cookies)
        self.assertRedirects(response, 'http://testserver/')
예제 #2
0
파일: market.py 프로젝트: nikodimm/bananas
class TestBidActions(TestCase):
    __metaclass__ = WithTestDataSeed

    def setUp(self):
        self.client = Client()
        self.user = self.client.login_as()
        self.avatar = any_model(
            Avatar, owner=self.user,
            today=0, hours_spent=0,
            health=50)
        self.market = any_model(
            Market, buy_item_type=INVENTORY_TYPE.DUBLONS,
            sell_item_type=INVENTORY_TYPE.BANANAS)
        
        self.market_url = reverse('market_index', kwargs={'avatar_pk':self.avatar.pk, 'market_pk':self.market.pk})

    def test_create_bid_succed(self):
        self.client.post(self.market_url, {'action':'create_bid', 'quantity':'10', 'rate':'200', 'direction':'SELL'})

        self.assertEqual(1, Bid.objects.filter(owner=self.avatar).count())

        bid = Bid.objects.get(owner=self.avatar)
        self.assertEqual(10, bid.quantity)
        self.assertEqual(self.market, bid.market)

    def test_delete_bid_succed(self):
        bid = any_model(Bid, owner=self.avatar, market=self.market)
        self.client.post(self.market_url, {'action':'delete_bid', 'bid_pk':'%s' % bid.pk})

        self.assertEqual(0, Bid.objects.filter(owner=self.avatar).count())
예제 #3
0
class TestAvatarActions(TestCase):
    __metaclass__ = WithTestDataSeed

    def setUp(self):
        self.client = Client()
        self.user = self.client.login_as()
        self.avatar = any_model(
            Avatar, owner=self.user,
            today=0, hours_spent=0,
            health=50)
        self.avatar_url = reverse('avatar_index', kwargs={'avatar_pk':self.avatar.pk})

    def test_sleep_action_restore_health_points(self):
        initial_health = self.avatar.health
        self.client.post(self.avatar_url, {'action' : 'sleep'})
        new_health = Avatar.objects.get(pk=self.avatar.pk).health
        self.assertTrue(initial_health < new_health)
                         
    def test_gather_bananas_extend_inventory(self):
        self.client.post(self.avatar_url, {'action' : 'gather_bananas'})
        bananas = self.avatar.get_inventory_item(INVENTORY_TYPE.BANANAS)
        self.assertEqual(1, bananas.quantity)

    def test_eathing_shoes_is_bad_for_heals(self):
        initial_health = self.avatar.health
        self.client.post(self.avatar_url, {'action' : 'eat_bananas'})
        new_health = Avatar.objects.get(pk=self.avatar.pk).health
        self.assertTrue(initial_health > new_health)

    def test_eathing_bananas_is_good_for_heals(self):
        bananas = self.avatar.get_inventory_item(INVENTORY_TYPE.BANANAS)
        bananas.quantity = 1
        bananas.save()
        
        initial_health = self.avatar.health
        self.client.post(self.avatar_url, {'action' : 'eat_bananas'})
        new_health = Avatar.objects.get(pk=self.avatar.pk).health
        self.assertTrue(initial_health < new_health)

    def test_buy_company_with_enough_gold_succeed(self):
        gold = self.avatar.get_inventory_item(INVENTORY_TYPE.GOLD)
        gold.quantity = 10
        gold.save()

        self.client.post(self.avatar_url, {'action':'buy_company', 'name' : 'TheCompany'})

        self.assertEqual(1, Company.objects.filter(owner=self.avatar).count())

        company = Company.objects.get(owner=self.avatar)
        self.assertEqual('TheCompany', company.name)
예제 #4
0
파일: vacancy.py 프로젝트: nikodimm/bananas
class TestVacancyActions(TestCase):
    __metaclass__ = WithTestDataSeed

    def setUp(self):
        self.client = Client()
        self.user = self.client.login_as()
        self.avatar = any_model(Avatar, owner=self.user, today=0, hours_spent=0, health=50)
        self.vacancy_url = reverse("vacancy_index", kwargs={"avatar_pk": self.avatar.pk})

    def test_accept_vacancy_succed(self):
        vacancy = any_model(Vacancy)

        self.client.post(self.vacancy_url, {"action": "accept_vacancy", "vacancy_pk": "%s" % vacancy.pk})

        self.assertEqual(0, Vacancy.objects.count())
예제 #5
0
파일: company.py 프로젝트: nikodimm/bananas
class TestCompanyActions(TestCase):
    __metaclass__ = WithTestDataSeed

    def setUp(self):
        self.client = Client()
        self.user = self.client.login_as()
        self.avatar = any_model(Avatar, owner=self.user, today=0, hours_spent=0, health=50)
        self.company = any_model(Company, owner=self.avatar)

        self.company_url = reverse("company_index", kwargs={"avatar_pk": self.avatar.pk, "company_pk": self.company.pk})

    def test_create_vacancy_succed(self):
        self.client.post(self.company_url, {"action": "create_vacancy", "salary_per_hour": "1"})

        self.assertEqual(1, Vacancy.objects.filter(company=self.company).count())

        vacancy = Vacancy.objects.get(company=self.company)
        self.assertEqual(1, vacancy.salary_per_hour)

    def test_delete_vacancy_succed(self):
        bid = any_model(Vacancy, company=self.company)
        self.client.post(self.company_url, {"action": "delete_vacancy", "vacancy_pk": "%s" % bid.pk})
        self.assertEqual(0, Vacancy.objects.count())

    def test_work_with_enough_company_money_succeed(self):
        CompanyWorker.objects.create(worker=self.avatar, company=self.company, salary_per_hour=1)
        any_model(InventoryItem, owner=self.avatar, quantity=10, item_type=INVENTORY_TYPE.DUBLONS)

        initial_health = self.avatar.health
        self.client.post(self.company_url, {"action": "work"})
        new_health = Avatar.objects.get(pk=self.avatar.pk).health
        self.assertTrue(initial_health > new_health)