def test_add_or_activate_function_activates_search(self): """ Test to ensure the add_or_activate_saved_search function adds a search when provided a user and an valid URL of a search that user has and is inactive """ new_ss = SavedSearchFactory(user=self.user, is_active=False) self.assertEqual(new_ss.is_active, False, msg="New search was active. Factory did not set" " it to inactive!") count_user_searches = SavedSearch.objects.filter( user=self.user).count() self.assertEqual( count_user_searches, 1, msg="Expected 1 searches for user, got %s! Factory may" " not have created search" % count_user_searches) saved_search = add_or_activate_saved_search(self.user, new_ss.url) ss_reload = SavedSearch.objects.get() self.assertEqual(new_ss, ss_reload, msg="There was a problem reloading saved search from" "the database. Original and reload do not match!") self.assertEqual(ss_reload.is_active, True, msg="Reloaded search was inactive! Function did not" " activate it!")
def test_add_or_activate_function_adds_search(self): """ Test to ensure the add_or_activate_saved_search function adds a search when provided a user and an valid URL of a search that user does not have """ count_user_searches = SavedSearch.objects.filter(user=self.user).count() self.assertEqual(count_user_searches, 0, msg="Expected 0 searches for user, got %s! Searches" " existed before test" % count_user_searches) add_or_activate_saved_search(self.user, 'http://www.my.jobs/') count_user_searches = SavedSearch.objects.filter( user=self.user).count() self.assertEqual(count_user_searches, 1, msg="Expected 1 search, got %s! Search may not have" "been created." % count_user_searches)
def test_add_or_activate_function_adds_search(self): """ Test to ensure the add_or_activate_saved_search function adds a search when provided a user and an valid URL of a search that user does not have """ count_user_searches = SavedSearch.objects.filter( user=self.user).count() self.assertEqual(count_user_searches, 0, msg="Expected 0 searches for user, got %s! Searches" " existed before test" % count_user_searches) add_or_activate_saved_search(self.user, 'http://www.my.jobs/') count_user_searches = SavedSearch.objects.filter( user=self.user).count() self.assertEqual(count_user_searches, 1, msg="Expected 1 search, got %s! Search may not have" "been created." % count_user_searches)
def test_add_or_activate_function_invalid_url(self): """ Test to ensure the add_or_activate_saved_search function raises the proper exception if an invalid url is provided """ count_user_searches = SavedSearch.objects.filter(user=self.user).count() self.assertEqual(count_user_searches, 0, msg="Expected 0 searches for user, got %s! Searches" " existed before test" % count_user_searches) with self.assertRaises(ValueError, msg="ValueError not raised despite " "invalid url provided!"): saved_search = add_or_activate_saved_search(self.user, 'http://www.google.com/') count_user_searches = SavedSearch.objects.filter(user=self.user).count() self.assertEqual(count_user_searches, 0, msg="Expected 0 searches, got %s! Search may have" " been created." % count_user_searches)
def test_add_or_activate_function_activates_search(self): """ Test to ensure the add_or_activate_saved_search function adds a search when provided a user and an valid URL of a search that user has and is inactive """ new_ss = SavedSearchFactory(user=self.user, is_active=False) self.assertEqual(new_ss.is_active, False, msg="New search was active. Factory did not set" " it to inactive!") count_user_searches = SavedSearch.objects.filter(user=self.user).count() self.assertEqual(count_user_searches, 1, msg="Expected 1 searches for user, got %s! Factory may" " not have created search" % count_user_searches) saved_search = add_or_activate_saved_search(self.user, new_ss.url) ss_reload = SavedSearch.objects.get() self.assertEqual(new_ss, ss_reload, msg="There was a problem reloading saved search from" "the database. Original and reload do not match!") self.assertEqual(ss_reload.is_active, True, msg="Reloaded search was inactive! Function did not" " activate it!")
def test_add_or_activate_function_invalid_url(self): """ Test to ensure the add_or_activate_saved_search function raises the proper exception if an invalid url is provided """ count_user_searches = SavedSearch.objects.filter( user=self.user).count() self.assertEqual(count_user_searches, 0, msg="Expected 0 searches for user, got %s! Searches" " existed before test" % count_user_searches) with self.assertRaises(ValueError, msg="ValueError not raised despite " "invalid url provided!"): saved_search = add_or_activate_saved_search( self.user, 'http://www.google.com/') count_user_searches = SavedSearch.objects.filter( user=self.user).count() self.assertEqual(count_user_searches, 0, msg="Expected 0 searches, got %s! Search may have" " been created." % count_user_searches)