def test_new_team_input_visible(self):
        #   Create and log in a user
        get_user_model().objects.create_user(userid='*****@*****.**')
        form = self.app.get(reverse('login')).form
        form['userid'] = '*****@*****.**'
        form.submit().follow()

        o = create_organisation(name='two teams', num_teams=2)
        response = self.app.get(
            reverse(
                'organisation-detail',
                kwargs={'pk': o.pk}
            )
        )

        new_team_input = response.html.find('input', {"id": "id_new_team"})
        team_list = response.html.find("ul", {"class": "team-list"})

        self.assertEqual(len(team_list.findChildren(
            "a",
            {"class": "main-list-item"}
        )), 2)
        self.assertIsNotNone(new_team_input)

        return response, o
示例#2
0
    def setUp(self):
        org = create_organisation("Heavy Users", num_teams=1, num_members=8)
        # user variable names here are ordered by usage
        self.top_user_1 = org.team_set.all()[0].user_set.all()[4]
        self.top_user_2 = org.team_set.all()[0].user_set.all()[2]
        self.top_user_3 = org.team_set.all()[0].user_set.all()[3]
        self.top_user_4 = org.team_set.all()[0].user_set.all()[1]
        self.top_user_5 = org.team_set.all()[0].user_set.all()[0]
        self.top_user_6 = org.team_set.all()[0].user_set.all()[6]

        self.owner_user = org.team_set.all()[0].user_set.all()[5]

        self.used_link, = generate_fake_links(self.owner_user, 2)

        register_link_usage_for_user(self.used_link, self.top_user_1, 13)
        register_link_usage_for_user(self.used_link, self.top_user_2, 12)
        register_link_usage_for_user(self.used_link, self.top_user_3, 10)
        register_link_usage_for_user(self.used_link, self.top_user_4, 9)
        register_link_usage_for_user(self.used_link, self.top_user_5, 7)
        register_link_usage_for_user(self.used_link, self.top_user_6, 5)
        register_link_usage_for_user(self.used_link, self.owner_user, 4)

        login_user(self, self.owner_user)

        # We need this for time mocking.
        self.now = now()
示例#3
0
    def setUp(self):
        org = create_organisation(
            'Heavy Users',
            num_teams=1,
            num_members=8,
        )
        # user variable names here are ordered by usage
        self.top_user_1 = org.team_set.all()[0].user_set.all()[4]
        self.top_user_2 = org.team_set.all()[0].user_set.all()[2]
        self.top_user_3 = org.team_set.all()[0].user_set.all()[3]
        self.top_user_4 = org.team_set.all()[0].user_set.all()[1]
        self.top_user_5 = org.team_set.all()[0].user_set.all()[0]
        self.top_user_6 = org.team_set.all()[0].user_set.all()[6]

        self.owner_user = org.team_set.all()[0].user_set.all()[5]

        self.used_link, = generate_fake_links(self.owner_user, 2)

        register_link_usage_for_user(self.used_link, self.top_user_1, 13)
        register_link_usage_for_user(self.used_link, self.top_user_2, 12)
        register_link_usage_for_user(self.used_link, self.top_user_3, 10)
        register_link_usage_for_user(self.used_link, self.top_user_4, 9)
        register_link_usage_for_user(self.used_link, self.top_user_5, 7)
        register_link_usage_for_user(self.used_link, self.top_user_6, 5)
        register_link_usage_for_user(self.used_link, self.owner_user, 4)

        login_user(self, self.owner_user)

        # We need this for time mocking.
        self.now = now()
示例#4
0
    def test_show_number_of_teams_none(self):
        #   Create and log in a user
        get_user_model().objects.create_user(userid='*****@*****.**')
        form = self.app.get(reverse('login')).form
        form['userid'] = '*****@*****.**'
        form.submit().follow()

        o = create_organisation(name='no teams', num_teams=0)
        response = self.app.get(reverse('organisation-list'))

        self.assertIn(
            o.name,
            response.html.find('a', {"class": "main-list-item"}).text
        )
        self.assertIn(
            'This organisation has no teams',
            response.html.find('ul', {"class": "organisation-info"}).text
        )
示例#5
0
    def test_new_team_input_visible(self):
        #   Create and log in a user
        get_user_model().objects.create_user(userid='*****@*****.**')
        form = self.app.get(reverse('login')).form
        form['userid'] = '*****@*****.**'
        form.submit().follow()

        o = create_organisation(name='two teams', num_teams=2)
        response = self.app.get(
            reverse('organisation-detail', kwargs={'pk': o.pk}))

        new_team_input = response.html.find('input', {"id": "id_new_team"})
        team_list = response.html.find("ul", {"class": "team-list"})

        self.assertEqual(
            len(team_list.findChildren("a", {"class": "main-list-item"})), 2)
        self.assertIsNotNone(new_team_input)

        return response, o
示例#6
0
def create_organisation(name, num_teams=0, num_members=0, usernames={}):
    return common.create_organisation(name, num_teams, 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'] = '*****@*****.**'
        form.submit().follow()

        # Create an organistion with two teams and two members in each team.
        o = create_organisation(
            name='Two members two teams top orgs', num_teams=2, num_members=2
        )

        t1 = o.team_set.all()[0]
        t2 = o.team_set.all()[1]

        user1 = t1.user_set.all()[0]
        user2 = t2.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
        )

        # Register a user from each team as having used various tools to
        # increase the aggregate from values across teams.
        # 16 times for existing link 8
        for i in range(0, 6):
            self.el8.register_usage(user1, force_new=True)
        for i in range(0, 10):
            self.el8.register_usage(user2, force_new=True)

        # 13 times for existing link 4
        for i in range(0, 8):
            self.el4.register_usage(user1, force_new=True)
        for i in range(0, 5):
            self.el4.register_usage(user2, force_new=True)

        # 9 times for existing link 1
        for i in range(0, 4):
            self.el1.register_usage(user1, force_new=True)
        for i in range(0, 5):
            self.el1.register_usage(user2, force_new=True)

        # 8 times for existing link 3
        for i in range(0, 5):
            self.el3.register_usage(user1, force_new=True)
        for i in range(0, 3):
            self.el3.register_usage(user2, force_new=True)

        # 4 times for existing link 9
        for i in range(0, 3):
            self.el9.register_usage(user1, force_new=True)
        for i in range(0, 1):
            self.el9.register_usage(user2, force_new=True)

        # 3 times for existing link 10
        for i in range(0, 2):
            self.el10.register_usage(user1, force_new=True)
        for i in range(0, 1):
            self.el10.register_usage(user2, force_new=True)

        response = self.app.get(reverse(
            'organisation-detail',
            kwargs={"pk": o.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.el8.name,
            tools_list_items[0].text
        )
        self.assertIn(
            self.el4.name,
            tools_list_items[1].text
        )
        self.assertIn(
            self.el1.name,
            tools_list_items[2].text
        )
        self.assertIn(
            self.el3.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
        )
示例#8
0
    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'] = '*****@*****.**'
        form.submit().follow()

        # Create an organistion with two teams and two members in each team.
        o = create_organisation(name='Two members two teams top orgs',
                                num_teams=2,
                                num_members=2)

        t1 = o.team_set.all()[0]
        t2 = o.team_set.all()[1]

        user1 = t1.user_set.all()[0]
        user2 = t2.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)

        # Register a user from each team as having used various tools to
        # increase the aggregate from values across teams.
        # 16 times for existing link 8
        for i in range(0, 6):
            self.el8.register_usage(user1, force_new=True)
        for i in range(0, 10):
            self.el8.register_usage(user2, force_new=True)

        # 13 times for existing link 4
        for i in range(0, 8):
            self.el4.register_usage(user1, force_new=True)
        for i in range(0, 5):
            self.el4.register_usage(user2, force_new=True)

        # 9 times for existing link 1
        for i in range(0, 4):
            self.el1.register_usage(user1, force_new=True)
        for i in range(0, 5):
            self.el1.register_usage(user2, force_new=True)

        # 8 times for existing link 3
        for i in range(0, 5):
            self.el3.register_usage(user1, force_new=True)
        for i in range(0, 3):
            self.el3.register_usage(user2, force_new=True)

        # 4 times for existing link 9
        for i in range(0, 3):
            self.el9.register_usage(user1, force_new=True)
        for i in range(0, 1):
            self.el9.register_usage(user2, force_new=True)

        # 3 times for existing link 10
        for i in range(0, 2):
            self.el10.register_usage(user1, force_new=True)
        for i in range(0, 1):
            self.el10.register_usage(user2, force_new=True)

        response = self.app.get(
            reverse('organisation-detail', kwargs={"pk": o.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.el8.name, tools_list_items[0].text)
        self.assertIn(self.el4.name, tools_list_items[1].text)
        self.assertIn(self.el1.name, tools_list_items[2].text)
        self.assertIn(self.el3.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)