Advertisement
Guest User

Untitled

a guest
May 30th, 2016
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.68 KB | None | 0 0
  1. class SearchSystemTests(TestCase):
  2.  
  3.     def test_search_with_epmty_field(self):
  4.         """
  5.         search with empty field should output
  6.         querry without any changes
  7.         """
  8.         #add user who "added" this data
  9.         user = User.objects.create_user(id = 1,username = 'test', email = 'test@test.com', password = '123')
  10.         # add new data
  11.         data_set_1 = giveaways(login = 'first', passw = 'password', rating_lim = 0, poster_id = 1, domain = 'www.google.com')
  12.         data_set_2 = giveaways(login = 'first', passw = 'password', rating_lim = 0, poster_id = 1, domain = 'www.yahoo.com')
  13.         data_set_3 = giveaways(login = 'first', passw = 'password', rating_lim = 0, poster_id = 1, domain = 'www.yandex.ru')
  14.         #save
  15.         data_set_1.save()
  16.         data_set_2.save()
  17.         data_set_3.save()
  18.  
  19.         response = self.client.post('/', {'search': '', 'data_count': 1,'order_con': 0,'hide': False})
  20.  
  21.         self.assertQuerysetEqual(response.context['data_set'], ['<giveaways: www.google.com>','<giveaways: www.yahoo.com>',
  22.             '<giveaways: www.yandex.ru>'])
  23.  
  24.     def test_search_with_no_match(self):
  25.         """
  26.         search with no mathes found  should output
  27.         empty querry
  28.         """
  29.         #add user who "added" this data
  30.         user = User.objects.create_user(id = 1,username = 'test', email = 'test@test.com', password = '123')
  31.         # add new data
  32.         data_set_1 = giveaways(login = 'first', passw = 'password', rating_lim = 0, poster_id = 1, domain = 'www.google.com')
  33.         data_set_2 = giveaways(login = 'first', passw = 'password', rating_lim = 0, poster_id = 1, domain = 'www.yahoo.com')
  34.         data_set_3 = giveaways(login = 'first', passw = 'password', rating_lim = 0, poster_id = 1, domain = 'www.yandex.ru')
  35.         #save
  36.         data_set_1.save()
  37.         data_set_2.save()
  38.         data_set_3.save()
  39.  
  40.         response = self.client.post('/', {'search': 'asdwaads', 'data_count': 1,'order_con': 0,'hide': False})
  41.  
  42.         self.assertQuerysetEqual(response.context['data_set'], [])
  43.  
  44.     def test_search_with_one_match(self):
  45.         """
  46.         search with one match found  should output
  47.         querry with one elements
  48.         """
  49.         #add user who "added" this data
  50.         user = User.objects.create_user(id = 1,username = 'test', email = 'test@test.com', password = '123')
  51.         # add new data
  52.         data_set_1 = giveaways(login = 'first', passw = 'password', rating_lim = 0, poster_id = 1, domain = 'www.google.com')
  53.         data_set_2 = giveaways(login = 'first', passw = 'password', rating_lim = 0, poster_id = 1, domain = 'www.yahoo.com')
  54.         data_set_3 = giveaways(login = 'first', passw = 'password', rating_lim = 0, poster_id = 1, domain = 'www.yandex.ru')
  55.         #save
  56.         data_set_1.save()
  57.         data_set_2.save()
  58.         data_set_3.save()
  59.  
  60.         response = self.client.post('/', {'search': 'dex', 'data_count': 1,'order_con': 0,'hide': False})
  61.  
  62.         self.assertQuerysetEqual(response.context['data_set'], ['<giveaways: www.yandex.ru>'])
  63.  
  64.     def test_search_with_multiple_matches(self):
  65.         """
  66.         search with multipl matches found  should output
  67.         querry with multiple elements
  68.         """
  69.         #add user who "added" this data
  70.         user = User.objects.create_user(id = 1,username = 'test', email = 'test@test.com', password = '123')
  71.         # add new data
  72.         data_set_1 = giveaways(login = 'first', passw = 'password', rating_lim = 0, poster_id = 1, domain = 'www.google.com')
  73.         data_set_2 = giveaways(login = 'first', passw = 'password', rating_lim = 0, poster_id = 1, domain = 'www.yahoo.com')
  74.         data_set_3 = giveaways(login = 'first', passw = 'password', rating_lim = 0, poster_id = 1, domain = 'www.yandex.ru')
  75.         #save
  76.         data_set_1.save()
  77.         data_set_2.save()
  78.         data_set_3.save()
  79.  
  80.         response = self.client.post('/', {'search': 'oo', 'data_count': 1,'order_con': 0,'hide': False})
  81.  
  82.         self.assertQuerysetEqual(response.context['data_set'], ['<giveaways: www.google.com>','<giveaways: www.yahoo.com>'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement