def test_list_members(self): # Create and log in a user get_user_model().objects.create_user(userid='*****@*****.**') form = self.app.get(reverse('login')).form form['userid'] = 'user0001com' form.submit().follow() t = create_team(name='two members', num_members=2) response = self.app.get(reverse('team-detail', kwargs={"pk": t.pk})) user_items = response.html.find( 'ul', {"class": "member-list"} ).findChildren('li') self.assertEqual( len(user_items), 2 ) self.assertIn( 'Team Member 1', user_items[0].text ) self.assertIn( 'Team Member 2', user_items[1].text )
def test_list_top_tools_ordered(self): # Create and log in a user get_user_model().objects.create_user(userid='*****@*****.**') form = self.app.get(reverse('login')).form form['userid'] = 'user0001com' form.submit().follow() t = create_team(name='Two members top teams', num_members=2) user1 = t.user_set.all()[0] (self.el1, self.el2, self.el3, self.el4, self.el5, self.el6, self.el7, self.el8, self.el9, self.el10) = generate_fake_links(user1, count=10, is_external=True) for i in range(0, 8): self.el4.register_usage(user1, force_new=True) for i in range(0, 6): self.el8.register_usage(user1, force_new=True) for i in range(0, 5): self.el3.register_usage(user1, force_new=True) for i in range(0, 4): self.el1.register_usage(user1, force_new=True) for i in range(0, 2): self.el9.register_usage(user1, force_new=True) for i in range(0, 1): self.el10.register_usage(user1, force_new=True) response = self.app.get(reverse('team-detail', kwargs={"pk": t.pk})) tools_list = response.html.find(id="top_links_list") tools_list_items = tools_list.findChildren('a') self.assertEqual(len(tools_list_items), 5) self.assertIn(self.el4.name, tools_list_items[0].text) self.assertIn(self.el8.name, tools_list_items[1].text) self.assertIn(self.el3.name, tools_list_items[2].text) self.assertIn(self.el1.name, tools_list_items[3].text) self.assertIn(self.el9.name, tools_list_items[4].text) self.assertNotIn(self.el10.name, tools_list.text) self.assertNotIn(self.el2.name, tools_list.text) self.assertNotIn(self.el5.name, tools_list.text) self.assertNotIn(self.el6.name, tools_list.text) self.assertNotIn(self.el7.name, tools_list.text)
def test_show_number_of_members_none(self): # Create and log in a user get_user_model().objects.create_user(userid='*****@*****.**') form = self.app.get(reverse('login')).form form['userid'] = 'user0001com' form.submit().follow() t = create_team(name='no members', num_members=0) response = self.app.get(reverse('team-list')) self.assertIn( t.name, response.html.find('a', {"class": "main-list-item"}).text ) self.assertIn( 'This team has no members', response.html.find('ul', {"class": "team-info"}).text )
def test_list_members(self): # Create and log in a user get_user_model().objects.create_user(userid='*****@*****.**') form = self.app.get(reverse('login')).form form['userid'] = 'user0001com' form.submit().follow() t = create_team(name='two members', num_members=2) response = self.app.get(reverse('team-detail', kwargs={"pk": t.pk})) user_items = response.html.find('ul', { "class": "member-list" }).findChildren('li') self.assertEqual(len(user_items), 2) self.assertIn('Team Member 1', user_items[0].text) self.assertIn('Team Member 2', user_items[1].text)
def test_show_number_of_members_none(self): # Create and log in a user get_user_model().objects.create_user(userid='*****@*****.**') form = self.app.get(reverse('login')).form form['userid'] = 'user0001com' form.submit().follow() t = create_team(name='no members', num_members=0) response = self.app.get(reverse('team-list')) self.assertIn( t.name, response.html.find('a', { "class": "main-list-item" }).text) self.assertIn('This team has no members', response.html.find('ul', { "class": "team-info" }).text)
def create_team(name, num_members=0, usernames={}): return common.create_team(name, num_members, usernames)
def test_list_top_tools_ordered(self): # Create and log in a user get_user_model().objects.create_user(userid='*****@*****.**') form = self.app.get(reverse('login')).form form['userid'] = 'user0001com' form.submit().follow() t = create_team( name='Two members top teams', num_members=2 ) user1 = t.user_set.all()[0] (self.el1, self.el2, self.el3, self.el4, self.el5, self.el6, self.el7, self.el8, self.el9, self.el10) = generate_fake_links( user1, count=10, is_external=True ) for i in range(0, 8): self.el4.register_usage(user1, force_new=True) for i in range(0, 6): self.el8.register_usage(user1, force_new=True) for i in range(0, 5): self.el3.register_usage(user1, force_new=True) for i in range(0, 4): self.el1.register_usage(user1, force_new=True) for i in range(0, 2): self.el9.register_usage(user1, force_new=True) for i in range(0, 1): self.el10.register_usage(user1, force_new=True) response = self.app.get(reverse('team-detail', kwargs={"pk": t.pk})) tools_list = response.html.find(id="top_links_list") tools_list_items = tools_list.findChildren('a') self.assertEqual( len(tools_list_items), 5 ) self.assertIn( self.el4.name, tools_list_items[0].text ) self.assertIn( self.el8.name, tools_list_items[1].text ) self.assertIn( self.el3.name, tools_list_items[2].text ) self.assertIn( self.el1.name, tools_list_items[3].text ) self.assertIn( self.el9.name, tools_list_items[4].text ) self.assertNotIn( self.el10.name, tools_list.text ) self.assertNotIn( self.el2.name, tools_list.text ) self.assertNotIn( self.el5.name, tools_list.text ) self.assertNotIn( self.el6.name, tools_list.text ) self.assertNotIn( self.el7.name, tools_list.text )