Ejemplo n.º 1
0
    def test_admin_users(self):
        """
        By default, all users that belong to an organization that owns the
        server and OCIM admins have access to the sandbox.
        """
        admin_org_handle = 'admin-org'
        OrganizationFactory(name=admin_org_handle,
                            github_handle=admin_org_handle)

        users = [
            ('user', 'user', admin_org_handle),
            ('admin2', 'admin2', admin_org_handle),
            ('no_github_handle', '', admin_org_handle),
            ('inactive_user', 'inactive_user', admin_org_handle),
            ('another_org', 'another_org', 'another_org'),
            ('no_org_1', 'no_org_1', ''),
            ('no_org_2', 'no_org_2', None),
        ]
        admin_users = [
            ('admin1', 'admin1', admin_org_handle),
            ('admin3', 'admin3', 'another_org'),
            ('admin4', 'admin4', ''),
            ('admin5', 'admin5', None),
            ('admin_no_org', '', admin_org_handle),
            ('inactive_admin', 'inactive_admin', admin_org_handle),
        ]

        expected_admin_users = [
            'user', 'admin1', 'admin2', 'admin3', 'admin4', 'admin5'
        ]

        for username, github_handle, org_handle in users:
            make_user_and_organization(username,
                                       github_username=github_handle,
                                       org_handle=org_handle)

        for username, github_handle, org_handle in admin_users:
            profile, _ = make_user_and_organization(
                username, github_username=github_handle, org_handle=org_handle)
            profile.user.is_superuser = True
            profile.user.save()

        # Mark the inactive user and admin as inactive; they should not be added to the resulting list
        get_user_model().objects.filter(
            username__in=('inactive_user',
                          'inactive_admin')).update(is_active=False)

        instance = OpenEdXInstanceFactory()
        organization = Organization.objects.get(github_handle=admin_org_handle)
        appserver = make_test_appserver(instance, organization=organization)

        self.assertEqual(len(appserver.admin_users), len(expected_admin_users))
        ansible_settings = yaml.load(appserver.configuration_settings)
        self.assertCountEqual(ansible_settings['COMMON_USER_INFO'],
                              [{
                                  'name': name,
                                  'github': True,
                                  'type': 'admin'
                              } for name in expected_admin_users])
Ejemplo n.º 2
0
    def setUp(self):
        super(ReportViewTestCase, self).setUp()

        self.username = '******'
        self.password = '******'
        self.organization = OrganizationFactory.create(
            name='Organization Name',
            github_handle='organization_github_handle')
Ejemplo n.º 3
0
 def setUp(self):
     with mock.patch(
             'instance.tests.models.factories.openedx_instance.OpenEdXInstance._write_metadata_to_consul',
             return_value=(1, True)):
         self.appserver = make_test_appserver()
     self.organization = OrganizationFactory.create(
         name='Organization Name',
         github_handle='organization_github_handle')
Ejemplo n.º 4
0
    def test_admin_users(self, mock_consul):
        """
        By default, all users that belong to an organization that owns the
        server and OCIM admins have access to the sandbox.
        """
        admin_org_handle = 'admin-org'
        OrganizationFactory(name=admin_org_handle, github_handle=admin_org_handle)

        users = [
            ('user', 'user', admin_org_handle),
            ('admin2', 'admin2', admin_org_handle),
            ('no_github_handle', '', admin_org_handle),
            ('inactive_user', 'inactive_user', admin_org_handle),
            ('another_org', 'another_org', 'another_org'),
            ('no_org_1', 'no_org_1', ''),
            ('no_org_2', 'no_org_2', None),
        ]
        admin_users = [
            ('admin1', 'admin1', admin_org_handle),
            ('admin3', 'admin3', 'another_org'),
            ('admin4', 'admin4', ''),
            ('admin5', 'admin5', None),
            ('admin_no_org', '', admin_org_handle),
            ('admin_no_github', 'invalid_github_user', admin_org_handle),
            ('inactive_admin', 'inactive_admin', admin_org_handle),
        ]

        expected_admin_users = ['user', 'admin1', 'admin2', 'admin3', 'admin4', 'admin5']

        for username, github_handle, org_handle in users:
            make_user_and_organization(username, github_username=github_handle, org_handle=org_handle)

        for username, github_handle, org_handle in admin_users:
            profile, _ = make_user_and_organization(username, github_username=github_handle, org_handle=org_handle)
            profile.user.is_superuser = True
            profile.user.save()

        # Mark the inactive user and admin as inactive; they should not be added to the resulting list
        get_user_model().objects.filter(username__in=('inactive_user', 'inactive_admin')).update(is_active=False)

        def check(_users):
            return [_user for _user in _users if _user != 'invalid_github_user']

        with patch('instance.models.mixins.openedx_config.check_github_users', check):
            appserver = make_test_appserver(
                OpenEdXInstanceFactory(),
                organization=Organization.objects.get(github_handle=admin_org_handle),
            )

            # Check user with non existant Github hande is removed
            self.assertEqual(len(appserver.admin_users) - 1, len(expected_admin_users))

            ansible_settings = yaml.load(appserver.configuration_settings, Loader=yaml.SafeLoader)
            self.assertCountEqual(ansible_settings['COMMON_USER_INFO'], [
                {'name': name, 'github': True, 'type': 'admin'} for name in expected_admin_users
            ])
Ejemplo n.º 5
0
 def setUp(self):
     self.appserver = make_test_appserver()
     self.organization = OrganizationFactory.create(
         name='Organization Name',
         github_handle='organization_github_handle')