test_studio_library.py 26.6 KB
Newer Older
1 2 3
"""
Acceptance tests for Content Libraries in Studio
"""
4
from ddt import ddt, data
5
from flaky import flaky
6

7
from .base_studio_test import StudioLibraryTest
8
from ...fixtures.course import XBlockFixtureDesc
9
from ...pages.studio.auto_auth import AutoAuthPage
10
from ...pages.studio.utils import add_component
11
from ...pages.studio.library import LibraryEditPage
12
from ...pages.studio.users import LibraryUsersPage
13 14


15
@ddt
16 17 18 19 20 21 22 23
class LibraryEditPageTest(StudioLibraryTest):
    """
    Test the functionality of the library edit page.
    """
    def setUp(self):  # pylint: disable=arguments-differ
        """
        Ensure a library exists and navigate to the library edit page.
        """
24
        super(LibraryEditPageTest, self).setUp()
25
        self.lib_page = LibraryEditPage(self.browser, self.library_key)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
        self.lib_page.visit()
        self.lib_page.wait_until_ready()

    def test_page_header(self):
        """
        Scenario: Ensure that the library's name is displayed in the header and title.
        Given I have a library in Studio
        And I navigate to Library Page in Studio
        Then I can see library name in page header title
        And I can see library name in browser page title
        """
        self.assertIn(self.library_info['display_name'], self.lib_page.get_header_title())
        self.assertIn(self.library_info['display_name'], self.browser.title)

    def test_add_duplicate_delete_actions(self):
        """
        Scenario: Ensure that we can add an HTML block, duplicate it, then delete the original.
        Given I have a library in Studio with no XBlocks
        And I navigate to Library Page in Studio
        Then there are no XBlocks displayed
        When I add Text XBlock
        Then one XBlock is displayed
        When I duplicate first XBlock
        Then two XBlocks are displayed
        And those XBlocks locators' are different
        When I delete first XBlock
        Then one XBlock is displayed
        And displayed XBlock are second one
        """
        self.assertEqual(len(self.lib_page.xblocks), 0)

        # Create a new block:
        add_component(self.lib_page, "html", "Text")
        self.assertEqual(len(self.lib_page.xblocks), 1)
        first_block_id = self.lib_page.xblocks[0].locator

        # Duplicate the block:
        self.lib_page.click_duplicate_button(first_block_id)
        self.assertEqual(len(self.lib_page.xblocks), 2)
        second_block_id = self.lib_page.xblocks[1].locator
        self.assertNotEqual(first_block_id, second_block_id)

        # Delete the first block:
        self.lib_page.click_delete_button(first_block_id, confirm=True)
        self.assertEqual(len(self.lib_page.xblocks), 1)
        self.assertEqual(self.lib_page.xblocks[0].locator, second_block_id)

73 74 75 76 77 78 79 80 81 82 83 84
    def test_no_edit_visibility_button(self):
        """
        Scenario: Ensure that library xblocks do not have 'edit visibility' buttons.
        Given I have a library in Studio with no XBlocks
        And I navigate to Library Page in Studio
        When I add Text XBlock
        Then one XBlock is displayed
        And no 'edit visibility' button is shown
        """
        add_component(self.lib_page, "html", "Text")
        self.assertFalse(self.lib_page.xblocks[0].has_edit_visibility_button)

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
    def test_add_edit_xblock(self):
        """
        Scenario: Ensure that we can add an XBlock, edit it, then see the resulting changes.
        Given I have a library in Studio with no XBlocks
        And I navigate to Library Page in Studio
        Then there are no XBlocks displayed
        When I add Multiple Choice XBlock
        Then one XBlock is displayed
        When I edit first XBlock
        And I go to basic tab
        And set it's text to a fairly trivial question about Battlestar Galactica
        And save XBlock
        Then one XBlock is displayed
        And first XBlock student content contains at least part of text I set
        """
        self.assertEqual(len(self.lib_page.xblocks), 0)
        # Create a new problem block:
        add_component(self.lib_page, "problem", "Multiple Choice")
        self.assertEqual(len(self.lib_page.xblocks), 1)
        problem_block = self.lib_page.xblocks[0]
        # Edit it:
        problem_block.edit()
        problem_block.open_basic_tab()
        problem_block.set_codemirror_text(
            """
            >>Who is "Starbuck"?<<
             (x) Kara Thrace
             ( ) William Adama
             ( ) Laura Roslin
             ( ) Lee Adama
             ( ) Gaius Baltar
            """
        )
        problem_block.save_settings()
        # Check that the save worked:
        self.assertEqual(len(self.lib_page.xblocks), 1)
        problem_block = self.lib_page.xblocks[0]
        self.assertIn("Laura Roslin", problem_block.student_content)
123 124 125 126 127 128

    def test_no_discussion_button(self):
        """
        Ensure the UI is not loaded for adding discussions.
        """
        self.assertFalse(self.browser.find_elements_by_css_selector('span.large-discussion-icon'))
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155

    def test_library_pagination(self):
        """
        Scenario: Ensure that adding several XBlocks to a library results in pagination.
        Given that I have a library in Studio with no XBlocks
        And I create 10 Multiple Choice XBlocks
        Then 10 are displayed.
        When I add one more Multiple Choice XBlock
        Then 1 XBlock will be displayed
        When I delete that XBlock
        Then 10 are displayed.
        """
        self.assertEqual(len(self.lib_page.xblocks), 0)
        for _ in range(0, 10):
            add_component(self.lib_page, "problem", "Multiple Choice")
        self.assertEqual(len(self.lib_page.xblocks), 10)
        add_component(self.lib_page, "problem", "Multiple Choice")
        self.assertEqual(len(self.lib_page.xblocks), 1)
        self.lib_page.click_delete_button(self.lib_page.xblocks[0].locator)
        self.assertEqual(len(self.lib_page.xblocks), 10)

    @data('top', 'bottom')
    def test_nav_present_but_disabled(self, position):
        """
        Scenario: Ensure that the navigation buttons aren't active when there aren't enough XBlocks.
        Given that I have a library in Studio with no XBlocks
        The Navigation buttons should be disabled.
156
        When I add a multiple choice problem
157 158 159 160
        The Navigation buttons should be disabled.
        """
        self.assertEqual(len(self.lib_page.xblocks), 0)
        self.assertTrue(self.lib_page.nav_disabled(position))
161
        add_component(self.lib_page, "problem", "Multiple Choice")
162 163
        self.assertTrue(self.lib_page.nav_disabled(position))

164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
    def test_delete_deletes_only_desired_block(self):
        """
        Scenario: Ensure that when deleting XBlock only desired XBlock is deleted
        Given that I have a library in Studio with no XBlocks
        And I create Blank Common Problem XBlock
        And I create Checkboxes XBlock
        When I delete Blank Problem XBlock
        Then Checkboxes XBlock is not deleted
        And Blank Common Problem XBlock is deleted
        """
        self.assertEqual(len(self.lib_page.xblocks), 0)
        add_component(self.lib_page, "problem", "Blank Common Problem")
        add_component(self.lib_page, "problem", "Checkboxes")
        self.assertEqual(len(self.lib_page.xblocks), 2)
        self.assertIn("Blank Common Problem", self.lib_page.xblocks[0].name)
        self.assertIn("Checkboxes", self.lib_page.xblocks[1].name)
        self.lib_page.click_delete_button(self.lib_page.xblocks[0].locator)
        self.assertEqual(len(self.lib_page.xblocks), 1)
        problem_block = self.lib_page.xblocks[0]
        self.assertIn("Checkboxes", problem_block.name)

185 186 187 188 189 190 191

@ddt
class LibraryNavigationTest(StudioLibraryTest):
    """
    Test common Navigation actions
    """
    def setUp(self):  # pylint: disable=arguments-differ
192
        """
193
        Ensure a library exists and navigate to the library edit page.
194
        """
195
        super(LibraryNavigationTest, self).setUp()
196
        self.lib_page = LibraryEditPage(self.browser, self.library_key)
197 198
        self.lib_page.visit()
        self.lib_page.wait_until_ready()
199

200 201 202 203 204 205 206 207
    def populate_library_fixture(self, library_fixture):
        """
        Create four pages worth of XBlocks, and offset by one so each is named
        after the number they should be in line by the user's perception.
        """
        # pylint: disable=attribute-defined-outside-init
        self.blocks = [XBlockFixtureDesc('html', str(i)) for i in xrange(1, 41)]
        library_fixture.add_children(*self.blocks)
208 209 210 211

    def test_arbitrary_page_selection(self):
        """
        Scenario: I can pick a specific page number of a Library at will.
212
        Given that I have a library in Studio with 40 XBlocks
213
        When I go to the 3rd page
214
        The first XBlock should be the 21st XBlock
215
        When I go to the 4th Page
216
        The first XBlock should be the 31st XBlock
217
        When I go to the 1st page
218
        The first XBlock should be the 1st XBlock
219
        When I go to the 2nd page
220
        The first XBlock should be the 11th XBlock
221 222
        """
        self.lib_page.go_to_page(3)
223
        self.assertEqual(self.lib_page.xblocks[0].name, '21')
224
        self.lib_page.go_to_page(4)
225
        self.assertEqual(self.lib_page.xblocks[0].name, '31')
226
        self.lib_page.go_to_page(1)
227
        self.assertEqual(self.lib_page.xblocks[0].name, '1')
228
        self.lib_page.go_to_page(2)
229
        self.assertEqual(self.lib_page.xblocks[0].name, '11')
230 231 232 233

    def test_bogus_page_selection(self):
        """
        Scenario: I can't pick a nonsense page number of a Library
234
        Given that I have a library in Studio with 40 XBlocks
235 236 237 238 239 240 241 242 243
        When I attempt to go to the 'a'th page
        The input field will be cleared and no change of XBlocks will be made
        When I attempt to visit the 5th page
        The input field will be cleared and no change of XBlocks will be made
        When I attempt to visit the -1st page
        The input field will be cleared and no change of XBlocks will be made
        When I attempt to visit the 0th page
        The input field will be cleared and no change of XBlocks will be made
        """
244
        self.assertEqual(self.lib_page.xblocks[0].name, '1')
245
        self.lib_page.go_to_page('a')
246
        self.assertTrue(self.lib_page.check_page_unchanged('1'))
247
        self.lib_page.go_to_page(-1)
248
        self.assertTrue(self.lib_page.check_page_unchanged('1'))
249
        self.lib_page.go_to_page(5)
250
        self.assertTrue(self.lib_page.check_page_unchanged('1'))
251
        self.lib_page.go_to_page(0)
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
        self.assertTrue(self.lib_page.check_page_unchanged('1'))

    @data('top', 'bottom')
    def test_nav_buttons(self, position):
        """
        Scenario: Ensure that the navigation buttons work.
        Given that I have a library in Studio with 40 XBlocks
        The previous button should be disabled.
        The first XBlock should be the 1st XBlock
        Then if I hit the next button
        The first XBlock should be the 11th XBlock
        Then if I hit the next button
        The first XBlock should be the 21st XBlock
        Then if I hit the next button
        The first XBlock should be the 31st XBlock
        And the next button should be disabled
        Then if I hit the previous button
        The first XBlock should be the 21st XBlock
        Then if I hit the previous button
        The first XBlock should be the 11th XBlock
        Then if I hit the previous button
        The first XBlock should be the 1st XBlock
        And the previous button should be disabled
        """
        # Check forward navigation
        self.assertTrue(self.lib_page.nav_disabled(position, ['previous']))
        self.assertEqual(self.lib_page.xblocks[0].name, '1')
        self.lib_page.move_forward(position)
        self.assertEqual(self.lib_page.xblocks[0].name, '11')
        self.lib_page.move_forward(position)
        self.assertEqual(self.lib_page.xblocks[0].name, '21')
        self.lib_page.move_forward(position)
        self.assertEqual(self.lib_page.xblocks[0].name, '31')
        self.lib_page.nav_disabled(position, ['next'])

        # Check backward navigation
        self.lib_page.move_back(position)
        self.assertEqual(self.lib_page.xblocks[0].name, '21')
        self.lib_page.move_back(position)
        self.assertEqual(self.lib_page.xblocks[0].name, '11')
        self.lib_page.move_back(position)
        self.assertEqual(self.lib_page.xblocks[0].name, '1')
        self.assertTrue(self.lib_page.nav_disabled(position, ['previous']))

    def test_library_pagination(self):
        """
        Scenario: Ensure that adding several XBlocks to a library results in pagination.
        Given that I have a library in Studio with 40 XBlocks
        Then 10 are displayed
        And the first XBlock will be the 1st one
        And I'm on the 1st page
        When I add 1 Multiple Choice XBlock
        Then 1 XBlock will be displayed
        And I'm on the 5th page
        The first XBlock will be the newest one
        When I delete that XBlock
        Then 10 are displayed
        And I'm on the 4th page
        And the first XBlock is the 31st one
        And the last XBlock is the 40th one.
        """
        self.assertEqual(len(self.lib_page.xblocks), 10)
        self.assertEqual(self.lib_page.get_page_number(), '1')
        self.assertEqual(self.lib_page.xblocks[0].name, '1')
        add_component(self.lib_page, "problem", "Multiple Choice")
        self.assertEqual(len(self.lib_page.xblocks), 1)
        self.assertEqual(self.lib_page.get_page_number(), '5')
        self.assertEqual(self.lib_page.xblocks[0].name, "Multiple Choice")
        self.lib_page.click_delete_button(self.lib_page.xblocks[0].locator)
        self.assertEqual(len(self.lib_page.xblocks), 10)
        self.assertEqual(self.lib_page.get_page_number(), '4')
        self.assertEqual(self.lib_page.xblocks[0].name, '31')
        self.assertEqual(self.lib_page.xblocks[-1].name, '40')

    def test_delete_shifts_blocks(self):
        """
        Scenario: Ensure that removing an XBlock shifts other blocks back.
        Given that I have a library in Studio with 40 XBlocks
        Then 10 are displayed
        And I will be on the first page
        When I delete the third XBlock
        There will be 10 displayed
        And the first XBlock will be the first one
        And the last XBlock will be the 11th one
        And I will be on the first page
        """
        self.assertEqual(len(self.lib_page.xblocks), 10)
        self.assertEqual(self.lib_page.get_page_number(), '1')
        self.lib_page.click_delete_button(self.lib_page.xblocks[2].locator, confirm=True)
        self.assertEqual(len(self.lib_page.xblocks), 10)
        self.assertEqual(self.lib_page.xblocks[0].name, '1')
        self.assertEqual(self.lib_page.xblocks[-1].name, '11')
        self.assertEqual(self.lib_page.get_page_number(), '1')
345

346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
    def test_previews(self):
        """
        Scenario: Ensure the user is able to hide previews of XBlocks.
        Given that I have a library in Studio with 40 XBlocks
        Then previews are visible
        And when I click the toggle previews button
        Then the previews will not be visible
        And when I click the toggle previews button
        Then the previews are visible
        """
        self.assertTrue(self.lib_page.are_previews_showing())
        self.lib_page.toggle_previews()
        self.assertFalse(self.lib_page.are_previews_showing())
        self.lib_page.toggle_previews()
        self.assertTrue(self.lib_page.are_previews_showing())

    def test_previews_navigation(self):
        """
        Scenario: Ensure preview settings persist across navigation.
        Given that I have a library in Studio with 40 XBlocks
        Then previews are visible
        And when I click the toggle previews button
        And click the next page button
        Then the previews will not be visible
        And the first XBlock will be the 11th one
        And the last XBlock will be the 20th one
        And when I click the toggle previews button
        And I click the previous page button
        Then the previews will be visible
        And the first XBlock will be the first one
        And the last XBlock will be the 11th one
        """
        self.assertTrue(self.lib_page.are_previews_showing())
        self.lib_page.toggle_previews()
        # Which set of arrows shouldn't matter for this test.
        self.lib_page.move_forward('top')
        self.assertFalse(self.lib_page.are_previews_showing())
        self.assertEqual(self.lib_page.xblocks[0].name, '11')
        self.assertEqual(self.lib_page.xblocks[-1].name, '20')
        self.lib_page.toggle_previews()
        self.lib_page.move_back('top')
        self.assertTrue(self.lib_page.are_previews_showing())
        self.assertEqual(self.lib_page.xblocks[0].name, '1')
        self.assertEqual(self.lib_page.xblocks[-1].name, '10')

    def test_preview_state_persistance(self):
        """
        Scenario: Ensure preview state persists between page loads.
        Given that I have a library in Studio with 40 XBlocks
        Then previews are visible
        And when I click the toggle previews button
        And I revisit the page
        Then the previews will not be visible
        """
        self.assertTrue(self.lib_page.are_previews_showing())
        self.lib_page.toggle_previews()
        self.lib_page.visit()
        self.lib_page.wait_until_ready()
        self.assertFalse(self.lib_page.are_previews_showing())

    def test_preview_add_xblock(self):
        """
        Scenario: Ensure previews are shown when adding new blocks, regardless of preview setting.
        Given that I have a library in Studio with 40 XBlocks
        Then previews are visible
        And when I click the toggle previews button
        Then the previews will not be visible
        And when I add an XBlock
        Then I will be on the 5th page
        And the XBlock will have loaded a preview
        And when I revisit the library
        And I go to the 5th page
        Then the top XBlock will be the one I added
        And it will not have a preview
        And when I add an XBlock
        Then the XBlock I added will have a preview
        And the top XBlock will not have one.
        """
        self.assertTrue(self.lib_page.are_previews_showing())
        self.lib_page.toggle_previews()
        self.assertFalse(self.lib_page.are_previews_showing())
        add_component(self.lib_page, "problem", "Checkboxes")
        self.assertEqual(self.lib_page.get_page_number(), '5')
        first_added = self.lib_page.xblocks[0]
        self.assertIn("Checkboxes", first_added.name)
        self.assertFalse(self.lib_page.xblocks[0].is_placeholder())
        self.lib_page.visit()
        self.lib_page.wait_until_ready()
        self.lib_page.go_to_page(5)
        self.assertTrue(self.lib_page.xblocks[0].is_placeholder())
        add_component(self.lib_page, "problem", "Multiple Choice")
        # DOM has detatched the element since last assignment
        first_added = self.lib_page.xblocks[0]
        second_added = self.lib_page.xblocks[1]
        self.assertIn("Multiple Choice", second_added.name)
        self.assertFalse(second_added.is_placeholder())
        self.assertTrue(first_added.is_placeholder())

    def test_edit_with_preview(self):
        """
        Scenario: Editing an XBlock should show me a preview even if previews are hidden.
        Given that I have a library in Studio with 40 XBlocks
        Then previews are visible
        And when I click the toggle previews button
        Then the previews will not be visible
        And when I edit the first XBlock
        Then the first XBlock will show a preview
        And the other XBlocks will still be placeholders
        """
        self.assertTrue(self.lib_page.are_previews_showing())
        self.lib_page.toggle_previews()
        self.assertFalse(self.lib_page.are_previews_showing())
        target = self.lib_page.xblocks[0]
        target.edit()
        target.save_settings()
        self.assertFalse(target.is_placeholder())
        self.assertTrue(all([xblock.is_placeholder() for xblock in self.lib_page.xblocks[1:]]))

    def test_duplicate_xblock_pagination(self):
        """
        Scenario: Duplicating an XBlock should not shift the page if the XBlock is not at the end.
        Given that I have a library in Studio with 40 XBlocks
        When I duplicate the third XBlock
        Then the page should not change
        And the duplicate XBlock should be there
        And it should show a preview
        And there should not be more than 10 XBlocks visible.
        """
        third_block_id = self.lib_page.xblocks[2].locator
        self.lib_page.click_duplicate_button(third_block_id)
        self.lib_page.wait_until_ready()
        target = self.lib_page.xblocks[3]
        self.assertIn('Duplicate', target.name)
        self.assertFalse(target.is_placeholder())
        self.assertEqual(len(self.lib_page.xblocks), 10)

    def test_duplicate_xblock_pagination_end(self):
        """
        Scenario: Duplicating an XBlock if it's the last one should bring me to the next page with a preview.
        Given that I have a library in Studio with 40 XBlocks
        And when I hide previews
        And I duplicate the last XBlock
        The page should change to page 2
        And the duplicate XBlock should be the first XBlock
        And it should not be a placeholder
        """
        self.lib_page.toggle_previews()
        last_block_id = self.lib_page.xblocks[-1].locator
        self.lib_page.click_duplicate_button(last_block_id)
        self.lib_page.wait_until_ready()
        self.assertEqual(self.lib_page.get_page_number(), '2')
        target_block = self.lib_page.xblocks[0]
        self.assertIn('Duplicate', target_block.name)
        self.assertFalse(target_block.is_placeholder())

501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520

class LibraryUsersPageTest(StudioLibraryTest):
    """
    Test the functionality of the library "Instructor Access" page.
    """
    def setUp(self):
        super(LibraryUsersPageTest, self).setUp()

        # Create a second user for use in these tests:
        AutoAuthPage(self.browser, username="second", email="second@example.com", no_login=True).visit()

        self.page = LibraryUsersPage(self.browser, self.library_key)
        self.page.visit()

    def _expect_refresh(self):
        """
        Wait for the page to reload.
        """
        self.page = LibraryUsersPage(self.browser, self.library_key).wait_for_page()

521
    @flaky  # TODO fix this, see SOL-618
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
    def test_user_management(self):
        """
        Scenario: Ensure that we can edit the permissions of users.
        Given I have a library in Studio where I am the only admin
        assigned (which is the default for a newly-created library)
        And I navigate to Library "Instructor Access" Page in Studio
        Then there should be one user listed (myself), and I must
        not be able to remove myself or my instructor privilege.

        When I click Add Intructor
        Then I see a form to complete
        When I complete the form and submit it
        Then I can see the new user is listed as a "User" of the library

        When I click to Add Staff permissions to the new user
        Then I can see the new user has staff permissions and that I am now
        able to promote them to an Admin or remove their staff permissions.

        When I click to Add Admin permissions to the new user
        Then I can see the new user has admin permissions and that I can now
        remove Admin permissions from either user.
        """
        def check_is_only_admin(user):
            """
            Ensure user is an admin user and cannot be removed.
            (There must always be at least one admin user.)
            """
            self.assertIn("admin", user.role_label.lower())
            self.assertFalse(user.can_promote)
            self.assertFalse(user.can_demote)
            self.assertFalse(user.can_delete)
            self.assertTrue(user.has_no_change_warning)
554
            self.assertIn("Promote another member to Admin to remove your admin rights", user.no_change_warning_text)
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635

        self.assertEqual(len(self.page.users), 1)
        user = self.page.users[0]
        self.assertTrue(user.is_current_user)
        check_is_only_admin(user)

        # Add a new user:

        self.assertTrue(self.page.has_add_button)
        self.assertFalse(self.page.new_user_form_visible)
        self.page.click_add_button()
        self.assertTrue(self.page.new_user_form_visible)
        self.page.set_new_user_email('second@example.com')
        self.page.click_submit_new_user_form()

        # Check the new user's listing:

        def get_two_users():
            """
            Expect two users to be listed, one being me, and another user.
            Returns me, them
            """
            users = self.page.users
            self.assertEqual(len(users), 2)
            self.assertEqual(len([u for u in users if u.is_current_user]), 1)
            if users[0].is_current_user:
                return users[0], users[1]
            else:
                return users[1], users[0]

        self._expect_refresh()
        user_me, them = get_two_users()
        check_is_only_admin(user_me)

        self.assertIn("user", them.role_label.lower())
        self.assertTrue(them.can_promote)
        self.assertIn("Add Staff Access", them.promote_button_text)
        self.assertFalse(them.can_demote)
        self.assertTrue(them.can_delete)
        self.assertFalse(them.has_no_change_warning)

        # Add Staff permissions to the new user:

        them.click_promote()
        self._expect_refresh()
        user_me, them = get_two_users()
        check_is_only_admin(user_me)

        self.assertIn("staff", them.role_label.lower())
        self.assertTrue(them.can_promote)
        self.assertIn("Add Admin Access", them.promote_button_text)
        self.assertTrue(them.can_demote)
        self.assertIn("Remove Staff Access", them.demote_button_text)
        self.assertTrue(them.can_delete)
        self.assertFalse(them.has_no_change_warning)

        # Add Admin permissions to the new user:

        them.click_promote()
        self._expect_refresh()
        user_me, them = get_two_users()
        self.assertIn("admin", user_me.role_label.lower())
        self.assertFalse(user_me.can_promote)
        self.assertTrue(user_me.can_demote)
        self.assertTrue(user_me.can_delete)
        self.assertFalse(user_me.has_no_change_warning)

        self.assertIn("admin", them.role_label.lower())
        self.assertFalse(them.can_promote)
        self.assertTrue(them.can_demote)
        self.assertIn("Remove Admin Access", them.demote_button_text)
        self.assertTrue(them.can_delete)
        self.assertFalse(them.has_no_change_warning)

        # Delete the new user:

        them.click_delete()
        self._expect_refresh()
        self.assertEqual(len(self.page.users), 1)
        user = self.page.users[0]
        self.assertTrue(user.is_current_user)