def test_ad_adsearch_and_ads_notifications_3(self): # ad Ad, then AdSearch corresponding public True => mail to buyer and vendor ad = TestAdFactory.create(brand="myfunkybrand") adsearch = TestAdSearchFactory.create(search="brand=myfunkybrand", content_type=ContentType.objects.get_for_model(TestAd), public=True) self.assertEquals(len(mail.outbox), 2) adsearch.delete() ad.delete()
def test_ad_model_property(self): ad = TestAdFactory.create(brand="myfunkybrand") adsearch = TestAdSearchFactory.create(search="brand=myfunkybrand", content_type=ContentType.objects.get_for_model(TestAd), public=True) self.assertEqual(ad.public_adsearch, [adsearch, ]) adsearch.public = False adsearch.save() self.assertEqual(ad.public_adsearch, [])
def test_ad_search_result_remove(self): ad = TestAdFactory.create(brand="myfunkybrand") adsearch = TestAdSearchFactory.create(search="brand=myfunkybrand", content_type=ContentType.objects.get_for_model(TestAd), public=True) ad.brand = "mytoofunkybrand" ad.save() ad.delete() adsearch.delete()
def test_ad_search_result_remove(self): ad = TestAdFactory.create(brand="myfunkybrand") adsearch = TestAdSearchFactory.create( search="brand=myfunkybrand", content_type=ContentType.objects.get_for_model(TestAd), public=True) ad.brand = "mytoofunkybrand" ad.save() ad.delete() adsearch.delete()
def test_ad_adsearch_and_ads_notifications_4(self): # ad Ad, then AdSearch corresponding public False => mail to buyer ad = TestAdFactory.create(brand="myfunkybrand") adsearch = TestAdSearchFactory.create(search="brand=myfunkybrand", content_type=ContentType.objects.get_for_model(TestAd), public=False) self.assertEquals(len(mail.outbox), 1) # the AdSearch become public, then mail to the vendor adsearch.public = True adsearch.save() self.assertEquals(len(mail.outbox), 2)
def test_view(self): # create ad and an adsearch adsearch = TestAdSearchFactory.create(search="brand=myfunkybrand", content_type=ContentType.objects.get_for_model(TestAd), public=True) ad = TestAdFactory.create(brand="myfunkybrand") request = self.factory.get('/') request.user = ad.user response = views.AdPotentialBuyersView.as_view(model=TestAd)(request, pk=ad.id) self.assertEqual(response.context_data['object'], ad) self.assertEqual(response.context_data['object_list'][0], adsearch.adsearchresult_set.all()[0])
def test_ad_model_property(self): ad = TestAdFactory.create(brand="myfunkybrand") adsearch = TestAdSearchFactory.create( search="brand=myfunkybrand", content_type=ContentType.objects.get_for_model(TestAd), public=True) self.assertEqual(ad.public_adsearch, [ adsearch, ]) adsearch.public = False adsearch.save() self.assertEqual(ad.public_adsearch, [])
def test_view(self): # create ad and an adsearch adsearch = TestAdSearchFactory.create(search="brand=myfunkybrand", content_type=ContentType.objects.get_for_model(TestAd), public=True) ad = TestAdFactory.create(brand="myfunkybrand") request = self.factory.get('/') request.user = ad.user response = views.AdPotentialBuyerContactView.as_view()(request, adsearchresult_id=adsearch.adsearchresult_set.all()[0]) request = self.factory.post('/', data={'message': 'I love your ad'}, files=[]) request.user = ad.user response = views.AdPotentialBuyerContactView.as_view()(request, adsearchresult_id=adsearch.adsearchresult_set.all()[0])
def test_view(self): # create ad and an adsearch adsearch = TestAdSearchFactory.create( search="brand=myfunkybrand", content_type=ContentType.objects.get_for_model(TestAd), public=True) ad = TestAdFactory.create(brand="myfunkybrand") request = self.factory.get('/') request.user = ad.user response = views.AdPotentialBuyersView.as_view(model=TestAd)(request, pk=ad.id) self.assertEqual(response.context_data['object'], ad) self.assertEqual(response.context_data['object_list'][0], adsearch.adsearchresult_set.all()[0])
def test_ad_adsearch_and_ads_signals_3(self): """ Test if signals are well sent to the buyer and the seller in case the search is created after the ad and initially with public set to True """ with mock_signal_receiver(geoad_new_relevant_ad_for_search) as receiver_buyer: with mock_signal_receiver(geoad_new_interested_user) as receiver_vendor: ad = TestAdFactory.create(brand="myfunkybrand") adsearch = TestAdSearchFactory.create(search="brand=myfunkybrand", content_type=ContentType.objects.get_for_model(TestAd), public=True) self.assertEquals(receiver_buyer.call_count, 1) self.assertEquals(receiver_vendor.call_count, 1) adsearch.delete() ad.delete()
def test_adsignal(self): #test_ad = TestAdFactory.create() # here we create an AdSearch that should hold all ads test_adsearch = TestAdSearchFactory.create(content_type=ContentType.objects.get_for_model(TestAd)) # here we create an Ad, and should then get it inside AdSearchResult of test_adsearch test_ad = TestAdFactory.create() self.assertEqual(test_adsearch.adsearchresult_set.all().count(), 1) test_adsearch.search = "brand=myfunkybrand" test_adsearch.save() self.assertEqual(test_adsearch.adsearchresult_set.all().count(), 0) test_adsearch.search = "brand=%s" % (test_ad.brand) test_adsearch.save() self.assertEqual(test_adsearch.adsearchresult_set.all().count(), 1) test_ad.brand = "newbrandnameduetofuckingmarketingservice" test_ad.save() self.assertEqual(test_adsearch.adsearchresult_set.all().count(), 0)
def test_remove_ad_from_ad_search(self): with mock_signal_receiver(geoad_new_relevant_ad_for_search) as receiver_buyer: with mock_signal_receiver(geoad_new_interested_user) as receiver_vendor: adsearch = TestAdSearchFactory.create(search="brand=myfunkybrand", content_type=ContentType.objects.get_for_model(TestAd), public=True) ad = TestAdFactory.create(brand="myfunkybrand") self.assertEquals(receiver_buyer.call_count, 1) self.assertEquals(receiver_vendor.call_count, 1) # modify Ad to correspond => signal to buyer ad.brand = "mytoofunkybrand" ad.save() self.assertEquals(receiver_buyer.call_count, 1) self.assertEquals(receiver_vendor.call_count, 1) adsearch.delete() ad.delete()
def test_view(self): # create ad and an adsearch adsearch = TestAdSearchFactory.create( search="brand=myfunkybrand", content_type=ContentType.objects.get_for_model(TestAd), public=True) ad = TestAdFactory.create(brand="myfunkybrand") request = self.factory.get('/') request.user = ad.user response = views.AdPotentialBuyerContactView.as_view()( request, adsearchresult_id=adsearch.adsearchresult_set.all()[0]) request = self.factory.post('/', data={'message': 'I love your ad'}, files=[]) request.user = ad.user response = views.AdPotentialBuyerContactView.as_view()( request, adsearchresult_id=adsearch.adsearchresult_set.all()[0])
def test_ad_adsearch_and_ads_signals_3(self): """ Test if signals are well sent to the buyer and the seller in case the search is created after the ad and initially with public set to True """ with mock_signal_receiver( geoad_new_relevant_ad_for_search) as receiver_buyer: with mock_signal_receiver( geoad_new_interested_user) as receiver_vendor: ad = TestAdFactory.create(brand="myfunkybrand") adsearch = TestAdSearchFactory.create( search="brand=myfunkybrand", content_type=ContentType.objects.get_for_model(TestAd), public=True) self.assertEquals(receiver_buyer.call_count, 1) self.assertEquals(receiver_vendor.call_count, 1) adsearch.delete() ad.delete()
def test_ad_adsearch_and_ads_signals_5(self): """ Mixed case where we change the different fields of ad and addsearch """ with mock_signal_receiver( geoad_new_relevant_ad_for_search) as receiver_buyer: with mock_signal_receiver( geoad_new_interested_user) as receiver_vendor: ad = TestAdFactory.create(brand="myfunkybrand") adsearch = TestAdSearchFactory.create( search="brand=mytoofunkybrand", content_type=ContentType.objects.get_for_model(TestAd), public=True) self.assertEquals(receiver_buyer.call_count, 0) self.assertEquals(receiver_vendor.call_count, 0) # modify Ad to correspond => signal to buyer ad.brand = "mytoofunkybrand" ad.save() self.assertEquals(receiver_buyer.call_count, 1) self.assertEquals(receiver_vendor.call_count, 1) # resave Ad to be sure, signal isn't send one more time ad.brand = "mytoofunkybrand" ad.save() self.assertEquals(receiver_buyer.call_count, 1) self.assertEquals(receiver_vendor.call_count, 1) # modify AdSearch to not correspond adsearch.search = "brand=myfunkybrand" adsearch.save() self.assertEquals(receiver_buyer.call_count, 1) self.assertEquals(receiver_vendor.call_count, 1) # modify AdSearch to corresond => mail to both ad.brand = "myfunkybrand" ad.save() self.assertEquals(receiver_buyer.call_count, 2) self.assertEquals(receiver_vendor.call_count, 2) # just change the Ad description to be sure signal is not sent another time ad.description = "you must buy it" ad.save() self.assertEquals(receiver_buyer.call_count, 2) self.assertEquals(receiver_vendor.call_count, 2) adsearch.delete() ad.delete()
def test_remove_ad_from_ad_search(self): with mock_signal_receiver( geoad_new_relevant_ad_for_search) as receiver_buyer: with mock_signal_receiver( geoad_new_interested_user) as receiver_vendor: adsearch = TestAdSearchFactory.create( search="brand=myfunkybrand", content_type=ContentType.objects.get_for_model(TestAd), public=True) ad = TestAdFactory.create(brand="myfunkybrand") self.assertEquals(receiver_buyer.call_count, 1) self.assertEquals(receiver_vendor.call_count, 1) # modify Ad to correspond => signal to buyer ad.brand = "mytoofunkybrand" ad.save() self.assertEquals(receiver_buyer.call_count, 1) self.assertEquals(receiver_vendor.call_count, 1) adsearch.delete() ad.delete()
def test_ad_adsearch_and_ads_signals_5(self): """ Mixed case where we change the different fields of ad and addsearch """ with mock_signal_receiver(geoad_new_relevant_ad_for_search) as receiver_buyer: with mock_signal_receiver(geoad_new_interested_user) as receiver_vendor: ad = TestAdFactory.create(brand="myfunkybrand") adsearch = TestAdSearchFactory.create(search="brand=mytoofunkybrand", content_type=ContentType.objects.get_for_model(TestAd), public=True) self.assertEquals(receiver_buyer.call_count, 0) self.assertEquals(receiver_vendor.call_count, 0) # modify Ad to correspond => signal to buyer ad.brand = "mytoofunkybrand" ad.save() self.assertEquals(receiver_buyer.call_count, 1) self.assertEquals(receiver_vendor.call_count, 1) # resave Ad to be sure, signal isn't send one more time ad.brand = "mytoofunkybrand" ad.save() self.assertEquals(receiver_buyer.call_count, 1) self.assertEquals(receiver_vendor.call_count, 1) # modify AdSearch to not correspond adsearch.search = "brand=myfunkybrand" adsearch.save() self.assertEquals(receiver_buyer.call_count, 1) self.assertEquals(receiver_vendor.call_count, 1) # modify AdSearch to corresond => mail to both ad.brand = "myfunkybrand" ad.save() self.assertEquals(receiver_buyer.call_count, 2) self.assertEquals(receiver_vendor.call_count, 2) # just change the Ad description to be sure signal is not sent another time ad.description = "you must buy it" ad.save() self.assertEquals(receiver_buyer.call_count, 2) self.assertEquals(receiver_vendor.call_count, 2) adsearch.delete() ad.delete()
def test_ad_adsearch_and_ads_notifications_5(self): # ad Ad, then AdSearch public, not corresponding => no mail ad = TestAdFactory.create(brand="myfunkybrand") adsearch = TestAdSearchFactory.create(search="brand=mytoofunkybrand", content_type=ContentType.objects.get_for_model(TestAd), public=True) self.assertEquals(len(mail.outbox), 0) # modify Ad to correspond => mail to both ad.brand = "mytoofunkybrand" ad.save() self.assertEquals(len(mail.outbox), 2) # resave Ad to be sure, mail isn't send one more time ad.brand = "mytoofunkybrand" ad.save() self.assertEquals(len(mail.outbox), 2) # modify AdSearch to not correspond adsearch.search = "brand=myfunkybrand" adsearch.save() self.assertEquals(len(mail.outbox), 2) # modify AdSearch to corresond => mail to both ad.brand = "myfunkybrand" ad.save() self.assertEquals(len(mail.outbox), 4)