class DjangoAnyClient(TestCase): urls = 'django_any.tests.test_client' def setUp(self): self.client = Client() def test_login_as_super_user(self): # TODO make test page which will not require is_staff like /admin self.assertTrue(self.client.login_as(is_superuser=True, is_staff=True)) response = self.client.get('/admin/') self.assertEquals(200, response.status_code) def test_login_as_custom_user(self): user = User.objects.create_user('john', '*****@*****.**', 'johnpassword') self.assertTrue(self.client.login_as(user=user)) def test_login_as_failed(self): user = None self.assertRaises(AssertionError, self.client.login_as, user=user) def test_post_any_data(self): response = self.client.post_any_data('/view/') self.assertRedirects(response, '/view/')
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())
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)
class DjangoAnyClient(TestCase): def setUp(self): self.client = Client() def test_login_as_super_user(self): # TODO make test page which will not require is_staff like /admin self.assertTrue(self.client.login_as(is_superuser=True, is_staff=True)) response = self.client.get('/admin/') self.assertEqual(200, response.status_code) def test_login_as_custom_user(self): user = User.objects.create_user('john', '*****@*****.**', 'johnpassword') self.assertTrue(self.client.login_as(user=user)) def test_login_as_failed(self): user = None self.assertRaises(AssertionError, self.client.login_as, user=user) def test_post_any_data(self): response = self.client.post_any_data('/view/') self.assertRedirects(response, '/view/')
class DjangoAnyClient(TestCase): urls = 'django_any.tests.test_client' def setUp(self): self.client = Client() def test_login_as_super_user(self): self.assertTrue(self.client.login_as(is_superuser=True)) response = self.client.get('/admin/') self.assertEquals(200, response.status_code) def test_login_as_custom_user(self): user = User.objects.create_user('john', '*****@*****.**', 'johnpassword') self.assertTrue(self.client.login_as(user=user)) def test_login_as_failed(self): user = None self.assertRaises(AssertionError, self.client.login_as, user=user) def test_post_any_data(self): response = self.client.post_any_data('/view/') self.assertRedirects(response, '/view/')
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)
class DjangoAnyClient(TestCase): urls = 'django_any.tests.test_client' def setUp(self): self.client = Client() def test_login_as_super_user(self): self.assertTrue(self.client.login_as(is_superuser=True)) response = self.client.get('/admin/') self.assertEquals(200, response.status_code) def test_post_any_data(self): response = self.client.post_any_data('/view/') self.assertRedirects(response, '/view/')
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())