def test_post_create_homeforsalead_valid_datas(self): user = UserFactory.create(password="******") self.c.login(username=user.username, password='******') ad_home = {'user_profile': user, 'price': 624000, 'habitation_type': "0", 'surface': 63, 'nb_of_rooms': 3, 'user_entered_address': "5 rue de Verneuil, Paris", 'nb_of_bedrooms': 2, 'geoads-adpicture-content_type-object_id-TOTAL_FORMS': 1, 'geoads-adpicture-content_type-object_id-INITIAL_FORMS': 0} resp = self.c.post(reverse('add', 'sites.achetersanscom.urls'), ad_home) self.assertEqual(resp.status_code, 301) self.c.login(username=user.username, password='******') # bad surface ad_home = {'user_profile': user, 'price': 624000, 'habitation_type': "0", 'surface': 'a', 'nb_of_rooms': 3, 'user_entered_address': "5 rue de Verneuil, Paris", 'nb_of_bedrooms': 2, 'geoads-adpicture-content_type-object_id-TOTAL_FORMS': 1, 'geoads-adpicture-content_type-object_id-INITIAL_FORMS': 0} resp = self.c.post(reverse('add', 'sites.achetersanscom.urls'), ad_home) self.assertEqual(resp.status_code, 200) #print resp.context_data['form']['surface'].errors self.assertEquals(resp.context_data['form']['surface'].errors, [u"Entrez une surface en mètres carré."]) #below same test, but doesn't works: seems like form doesn't have a surface field ! why ? #self.assertFormError(resp, 'form', 'surface', u"Entrez une surface en mètres carré.") # test if ad has been created self.assertEquals(HomeForSaleAd.unmoderated_objects.filter(user=user).count(), 1) # test if ad is not available self.assertEquals(HomeForSaleAd.objects.filter(user=user).count(), 0) # approve ModeratedObject.objects.all()[0].approve() # test if ad is now available self.assertEquals(HomeForSaleAd.objects.filter(user=user).count(), 1)
def test_get_update_homeforsale(self): # test for user that doesn't own the ad => throw 404 home = HomeForSaleAdFactory.create() user = UserFactory.create(password="******") self.c.login(username=user.username, password='******') resp = self.c.get(reverse('edit', 'sites.achetersanscom.urls', kwargs={'pk': home.id})) self.assertEqual(resp.status_code, 404)
def test_post_create_homeforsalead_invalid_datas(self): user = UserFactory.create(password="******") self.c.login(username=user.username, password='******') resp = self.c.post(reverse('add', 'sites.achetersanscom.urls')) self.assertEqual(resp.status_code, 200) form = resp.context_data['form'] self.assertFalse(form.is_valid())
def test_get_home_filter_logged_results(self): home = HomeForSaleAdFactory.create() user = UserFactory.create(password="******") self.c.login(username=user.username, password='******') resp = self.c.get(reverse('search', 'sites.achetersanscom.urls'), {'foo': 'bar'}) self.assertEqual(resp.status_code, 200) home.delete()
def test_post_create_homeforsalead_invalid_datas(self): user = UserFactory.create(password="******") self.c.login(username=user.username, password="******") resp = self.c.post(reverse("add", "sites.achetersanscom.urls")) self.assertEqual(resp.status_code, 200) form = resp.context_data["form"] self.assertFalse(form.is_valid())
def test_get_home_filter_logged_results(self): home = HomeForSaleAdFactory.create() user = UserFactory.create(password="******") self.c.login(username=user.username, password="******") resp = self.c.get(reverse("search", "sites.achetersanscom.urls"), {"foo": "bar"}) self.assertEqual(resp.status_code, 200) home.delete()
def test_get_update_homeforsale(self): # test for user that doesn't own the ad => throw 404 home = HomeForSaleAdFactory.create() user = UserFactory.create(password="******") self.c.login(username=user.username, password="******") resp = self.c.get(reverse("edit", "sites.achetersanscom.urls", kwargs={"pk": home.id})) self.assertEqual(resp.status_code, 404)
def test_post_create_homeforsalead_valid_datas(self): user = UserFactory.create(password="******") self.c.login(username=user.username, password="******") ad_home = { "user_profile": user, "price": 624000, "habitation_type": "0", "surface": 63, "nb_of_rooms": 3, "user_entered_address": "5 rue de Verneuil, Paris", "nb_of_bedrooms": 2, "geoads-adpicture-content_type-object_id-TOTAL_FORMS": 1, "geoads-adpicture-content_type-object_id-INITIAL_FORMS": 0, } resp = self.c.post(reverse("add", "sites.achetersanscom.urls"), ad_home) self.assertEqual(resp.status_code, 301) self.c.login(username=user.username, password="******") # bad surface ad_home = { "user_profile": user, "price": 624000, "habitation_type": "0", "surface": "a", "nb_of_rooms": 3, "user_entered_address": "5 rue de Verneuil, Paris", "nb_of_bedrooms": 2, "geoads-adpicture-content_type-object_id-TOTAL_FORMS": 1, "geoads-adpicture-content_type-object_id-INITIAL_FORMS": 0, } resp = self.c.post(reverse("add", "sites.achetersanscom.urls"), ad_home) self.assertEqual(resp.status_code, 200) # print resp.context_data['form']['surface'].errors self.assertEquals(resp.context_data["form"]["surface"].errors, [u"Entrez une surface en mètres carré."]) # below same test, but doesn't works: seems like form doesn't have a surface field ! why ? # self.assertFormError(resp, 'form', 'surface', u"Entrez une surface en mètres carré.") # test if ad has been created self.assertEquals(HomeForSaleAd.unmoderated_objects.filter(user=user).count(), 1) # test if ad is not available self.assertEquals(HomeForSaleAd.objects.filter(user=user).count(), 0) # approve ModeratedObject.objects.all()[0].approve() # test if ad is now available self.assertEquals(HomeForSaleAd.objects.filter(user=user).count(), 1)
def test_get_create_homeforsalead_logged_user(self): user = UserFactory.create(password="******") self.c.login(username=user.username, password='******') resp = self.c.get(reverse('add', 'sites.achetersanscom.urls')) self.assertEqual(resp.status_code, 200)
def test_get_create_homeforsalead_logged_user(self): user = UserFactory.create(password="******") self.c.login(username=user.username, password="******") resp = self.c.get(reverse("add", "sites.achetersanscom.urls")) self.assertEqual(resp.status_code, 200)