Ejemplo n.º 1
0
 def test_creating_whisky(self):
     User.create_user('username', 'password')
     self.login_user('username', 'password')
     self.wait_until(EC.url_changes, self.deployment_url + "homepage")
     time.sleep(2)
     add = self.driver.find_element_by_id("id_add_button")
     add.click()
     self.fill_whisky_form('create')
     create = self.driver.find_element_by_id("id_button_create")
     create.click()
     time.sleep(3)
     whisk = self.get_whisky_card_attr()
     self.compare_whisk(whisk)
     self.driver.get(self.deployment_url)
     self.login_user('username', 'password')
     self.wait_until(EC.url_changes, self.deployment_url + "homepage")
     time.sleep(3)
     try:
         list_item = self.driver.find_element_by_id("id_item_0")
         self.assertIsNotNone(list_item)
         self.assertEqual(list_item.text, 'name')
     except:
         self.fail('Whisky not in list')
     try:
         whis = self.get_whisky_card_attr()
         self.assertIsNotNone(whis)
     except:
         self.fail("Card not showing")
     self.compare_whisk(whis)
 def test_get_user_exists(self):
     user_to_add = User(username='******', hashed_password='******')
     db.session.add(user_to_add)
     db.session.commit()
     user = User.get_user('username')
     self.assertIsNotNone(user)
     self.assertEqual(user.username, 'username')
     self.assertEqual(user.hashed_password, 'password')
Ejemplo n.º 3
0
 def test_build_dict_user(self):
     username = '******'
     password = '******'
     user = User(username=username, hashed_password=password)
     db.session.add(user)
     db.session.commit()
     user_dict = user.build_dict()
     self.assertEqual(user_dict['uid'], 2)
     self.assertEqual(user_dict['username'], username)
     self.assertEqual(len(user_dict), 2)
Ejemplo n.º 4
0
 def test_editing_whisky(self):
     user = User.create_user('username', 'password')
     self.load_whiskies(user)
     self.login_user('username', 'password')
     time.sleep(5)
     whis = self.get_whisky_card_attr()
     edit = self.driver.find_element_by_name('edit')
     edit.click()
     self.fill_whisky_form('edit')
     self.driver.find_element_by_id('id_button_submit').click()
     time.sleep(5)
     list_item = self.driver.find_element_by_id("id_item_4")
     list_item.click()
     time.sleep(5)
     new_whis = self.get_whisky_card_attr()
     for key, value in whis.items():
         self.assertNotEqual(whis[key], new_whis[key])
     self.driver.get(self.deployment_url)
     self.login_user('username', 'password')
     time.sleep(5)
     next_button = self.driver.find_element_by_id("id_next_button")
     found_updated = False
     for i in range(5):
         time.sleep(1)
         whisk = self.get_whisky_card_attr()
         if whisk['name'] == "name0name":
             found_updated = True
             break
         next_button.click()
     self.assertTrue(found_updated)
Ejemplo n.º 5
0
 def create_test_user(self, username='******', database=db):
     password = '******'
     hashed_password = bcrypt.hashpw(password.encode('utf-8'),
                                     bcrypt.gensalt()).decode('utf-8')
     user = User(username=username, hashed_password=hashed_password)
     database.session.add(user)
     database.session.commit()
     return user
Ejemplo n.º 6
0
 def test_create_whisk_fail(self):
     User.create_user('username', 'password')
     self.login_user('username', 'password')
     time.sleep(1)
     add = self.driver.find_element_by_id("id_add_button")
     add.click()
     self.fill_whisky_form('create', age_value='as')
     age = self.driver.find_element_by_id('id_age_create')
     age.send_keys('as')
     create = self.driver.find_element_by_id("id_button_create")
     create.click()
     time.sleep(2)
     error = self.driver.find_element_by_id("id_error")
     self.assertIsNotNone(error)
     add = self.driver.find_element_by_id("id_add_button")
     add.click()
     self.fill_whisky_form('create')
     create = self.driver.find_element_by_id("id_button_create")
     create.click()
     try:
         self.driver.find_element_by_id('id_error')
         self.fail("error message should not appear")
     except:
         pass
Ejemplo n.º 7
0
 def test_visible_whiskies(self):
     print("Testing visible whiskies")
     user = User.create_user('username', 'password')
     self.load_whiskies(user)
     self.login_user('username', 'password')
     self.wait_until(EC.url_changes, self.deployment_url + "homepage")
     time.sleep(2)
     try:
         self.driver.find_element_by_id("id_empty_list")
         self.fail("List shouldn't be empty")
     except:
         pass
     time.sleep(1)
     next = self.driver.find_element_by_id("id_next_button")
     back = self.driver.find_element_by_id("id_back_button")
     self.click_whisk(next, 5)
     self.click_whisk(back, 5)
Ejemplo n.º 8
0
 def test_search_whisky(self):
     user = User.create_user('username', 'password')
     Whisky.create_whisky('unique', 'unique', 'unique', 12, 'unique',
                          'unique', 'unique', 5, user.uid)
     self.load_whiskies(user)
     self.login_user('username', 'password')
     time.sleep(5)
     items = []
     for i in range(5):
         items.append(self.driver.find_element_by_id("id_item_%s" % i))
     search_field = self.driver.find_element_by_id("id_search_input")
     search_field.send_keys("unique")
     time.sleep(5)
     new_items = []
     for i in range(5):
         if i == 0:
             new_items.append(
                 self.driver.find_element_by_id("id_item_%s" % i))
         else:
             try:
                 self.driver.find_element_by_id("id_item_%s" % i)
                 self.fail()
             except:
                 pass
     self.assertEqual(len(new_items), 1)
     self.assertNotEqual(len(new_items), len(items))
     whisk = self.get_whisky_card_attr()
     self.assertEqual(whisk['name'], 'unique')
     search_field.clear()
     search_field.send_keys('545')
     time.sleep(5)
     try:
         self.driver.find_element_by_id("id_name_0")
         self.fail()
     except:
         pass
Ejemplo n.º 9
0
 def test_create_user(self):
     user = User.create_user('username2', 'password')
     self.assertIsInstance(user, User)
     created_user = User.query.filter_by(username='******').first()
     self.assertEqual(created_user.username, user.username)
     self.assertEqual(created_user.hashed_password, user.hashed_password)
Ejemplo n.º 10
0
 def test_get_user_exists(self):
     user = User.get_user('username')
     self.assertIsNotNone(user)
     self.assertEqual(user.username, 'username')
     self.assertIsNotNone(user.hashed_password)
Ejemplo n.º 11
0
 def test_get_user_empty(self):
     username = '******'
     user = User.get_user(username)
     self.assertEqual(None, user)
Ejemplo n.º 12
0
 def create_test_user(self):
     password = '******'
     hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
     user = User(username='******', hashed_password=hashed_password)
     db.session.add(user)
     db.session.commit()