'Scenario: the user should be able to sort the list of teams by open slots or last activity
Given I am enrolled in a course with team configuration and topics
When I visit the Teams page
And I browse teams within a topic
Then I should see a list of teams for that topic
When I choose a sort order
Then I should see the paginated list of teams in that order'

@ddt.data(('open_slots', 'last_activity_at', True), ('last_activity_at', 'open_slots', True))
@ddt.unpack
def test_sort_teams(self, sort_order, secondary_sort_order, reverse):

    teams = self.create_teams(self.topic, (self.TEAMS_PAGE_SIZE + 1))
    for (i, team) in enumerate(random.sample(teams, len(teams))):
        for _ in range(i):
            user_info = AutoAuthPage(self.browser, course_id=self.course_id).visit().user_info
            self.create_membership(user_info['username'], team['id'])
        team['open_slots'] = (self.max_team_size - i)
    AutoAuthPage(self.browser, course_id=self.course_id, staff=True).visit()
    self.browse_teams_page.visit()
    self.browse_teams_page.sort_teams_by(sort_order)
    team_names = self.browse_teams_page.team_names
    self.assertEqual(len(team_names), self.TEAMS_PAGE_SIZE)
    sorted_teams = [team['name'] for team in sorted(sorted(teams, key=(lambda t: t[secondary_sort_order]), reverse=reverse), key=(lambda t: t[sort_order]), reverse=reverse)][:self.TEAMS_PAGE_SIZE]
    self.assertEqual(team_names, sorted_teams)
