Exemple #1
0
    def setUp(self):
        super(TestApiDataRetrieval, self).setUp()
        ClientFactory(name=CredentialsApiConfig.OAUTH2_CLIENT_NAME, client_type=CONFIDENTIAL)
        ClientFactory(name=ProgramsApiConfig.OAUTH2_CLIENT_NAME, client_type=CONFIDENTIAL)
        self.user = UserFactory()

        cache.clear()
Exemple #2
0
    def setUp(self):
        super(AwardProgramCertificatesTestCase, self).setUp()
        self.create_programs_config()
        self.create_credentials_config()
        self.student = UserFactory.create(username='******')

        ClientFactory.create(name='programs')
        ClientFactory.create(name='credentials')
        UserFactory.create(username=settings.CREDENTIALS_SERVICE_USERNAME)  # pylint: disable=no-member
Exemple #3
0
    def test_get_api_client(self, mock_get_id_token):
        """
        Ensure the function is making the right API calls based on inputs
        """
        student = UserFactory()
        ClientFactory.create(name='programs')
        api_config = self.create_programs_config(
            internal_service_url='http://foo',
            api_version_number=99,
        )
        mock_get_id_token.return_value = 'test-token'

        api_client = tasks.get_api_client(api_config, student)
        self.assertEqual(mock_get_id_token.call_args[0], (student, 'programs'))
        self.assertEqual(api_client._store['base_url'], 'http://foo/api/v99/')  # pylint: disable=protected-access
        self.assertEqual(api_client._store['session'].auth.token, 'test-token')  # pylint: disable=protected-access
Exemple #4
0
 def setUp(self):
     self.client_name = "edx-dummy-client"
     ClientFactory(name=self.client_name)
     super(GetIdTokenTest, self).setUp()
     self.user = UserFactory.create(username="******",
                                    email="*****@*****.**",
                                    password="******")
     self.client.login(username=self.user.username, password="******")
Exemple #5
0
 def setUp(self):
     ClientFactory(name="edx-notes")
     self.course = CourseFactory.create(edxnotes=True)
     self.user = UserFactory.create(username="******",
                                    email="*****@*****.**",
                                    password="******")
     self.client.login(username=self.user.username, password="******")
     self.problem = TestProblem(self.course)
Exemple #6
0
    def setUp(self):
        super(TestIdTokenGeneration, self).setUp()

        self.oauth2_client = ClientFactory(name=self.client_name,
                                           client_type=CONFIDENTIAL)

        self.user = UserFactory.build()
        self.user.save()
 def test_oauth(self):
     """ Verify the endpoint supports authentication via OAuth 2.0. """
     access_token = AccessTokenFactory(user=self.user,
                                       client=ClientFactory()).token
     headers = {'HTTP_AUTHORIZATION': 'Bearer ' + access_token}
     self.client.logout()
     response = self.client.get(self.path, **headers)
     self.assertEqual(response.status_code, 200)
    def setUp(self):
        super(TestIdTokenGeneration, self).setUp()

        self.oauth2_client = ClientFactory(name=self.client_name,
                                           client_type=CONFIDENTIAL)
        self.user = UserFactory()

        # Create a profile for the user
        self.user_profile = UserProfileFactory(user=self.user)
    def setUp(self):
        super(TestProgramListing, self).setUp()

        ClientFactory(name=ProgramsApiConfig.OAUTH2_CLIENT_NAME, client_type=CONFIDENTIAL)

        self.staff = UserFactory(is_staff=True)
        self.client.login(username=self.staff.username, password='******')

        self.studio_home = reverse('home')
Exemple #10
0
    def test_oauth(self):
        """Verify that the endpoint supports OAuth 2.0."""
        access_token = AccessTokenFactory(user=self.user,
                                          client=ClientFactory()).token  # pylint: disable=no-member
        self.headers['HTTP_AUTHORIZATION'] = 'Bearer ' + access_token

        self.client.logout()

        self._verify_response(200)
Exemple #11
0
 def setUp(self):
     """
         Add a student
     """
     super(TestProgramListing, self).setUp()
     ClientFactory(name=ProgramsApiConfig.OAUTH2_CLIENT_NAME,
                   client_type=CONFIDENTIAL)
     self.student = UserFactory()
     self.create_programs_config(xseries_ad_enabled=True)
Exemple #12
0
    def setUp(self):
        """
        Setup a dummy course content.
        """
        super(EdxNotesHelpersTest, self).setUp()

        # There are many tests that are comparing locators as returned from helper methods. When using
        # the split modulestore, some of those locators have version and branch information, but the
        # comparison values do not. This needs further investigation in order to enable these tests
        # with the split modulestore.
        with self.store.default_store(ModuleStoreEnum.Type.mongo):
            ClientFactory(name="edx-notes")
            self.course = CourseFactory.create()
            self.chapter = ItemFactory.create(
                category="chapter", parent_location=self.course.location)
            self.chapter_2 = ItemFactory.create(
                category="chapter", parent_location=self.course.location)
            self.sequential = ItemFactory.create(
                category="sequential", parent_location=self.chapter.location)
            self.vertical = ItemFactory.create(
                category="vertical", parent_location=self.sequential.location)
            self.html_module_1 = ItemFactory.create(
                category="html", parent_location=self.vertical.location)
            self.html_module_2 = ItemFactory.create(
                category="html", parent_location=self.vertical.location)
            self.vertical_with_container = ItemFactory.create(
                category='vertical', parent_location=self.sequential.location)
            self.child_container = ItemFactory.create(
                category='split_test',
                parent_location=self.vertical_with_container.location)
            self.child_vertical = ItemFactory.create(
                category='vertical',
                parent_location=self.child_container.location)
            self.child_html_module = ItemFactory.create(
                category="html", parent_location=self.child_vertical.location)

            # Read again so that children lists are accurate
            self.course = self.store.get_item(self.course.location)
            self.chapter = self.store.get_item(self.chapter.location)
            self.chapter_2 = self.store.get_item(self.chapter_2.location)
            self.sequential = self.store.get_item(self.sequential.location)
            self.vertical = self.store.get_item(self.vertical.location)

            self.vertical_with_container = self.store.get_item(
                self.vertical_with_container.location)
            self.child_container = self.store.get_item(
                self.child_container.location)
            self.child_vertical = self.store.get_item(
                self.child_vertical.location)
            self.child_html_module = self.store.get_item(
                self.child_html_module.location)

            self.user = UserFactory.create(username="******",
                                           email="*****@*****.**",
                                           password="******")
            self.client.login(username=self.user.username, password="******")
Exemple #13
0
 def setUp(self):
     ClientFactory(name="edx-notes")
     super(EdxNotesViewsTest, self).setUp()
     self.course = CourseFactory.create(edxnotes=True)
     self.user = UserFactory.create(username="******", email="*****@*****.**", password="******")
     self.client.login(username=self.user.username, password="******")
     self.notes_page_url = reverse("edxnotes", args=[unicode(self.course.id)])
     self.search_url = reverse("search_notes", args=[unicode(self.course.id)])
     self.get_token_url = reverse("get_token", args=[unicode(self.course.id)])
     self.visibility_url = reverse("edxnotes_visibility", args=[unicode(self.course.id)])
Exemple #14
0
    def setUp(self):
        super(EdxNotesDecoratorTest, self).setUp()

        ClientFactory(name="edx-notes")
        # Using old mongo because of locator comparison issues (see longer
        # note below in EdxNotesHelpersTest setUp.
        self.course = CourseFactory.create(edxnotes=True, default_store=ModuleStoreEnum.Type.mongo)
        self.user = UserFactory.create(username="******", email="*****@*****.**", password="******")
        self.client.login(username=self.user.username, password="******")
        self.problem = TestProblem(self.course)
Exemple #15
0
    def setUp(self):
        self.client_secret = 'some_secret'
        self.auth_client = ClientFactory(client_secret=self.client_secret)

        self.password = '******'
        self.user_factory = UserFactory

        self.user = None
        self.access_token = None
        self.set_user(self.make_user())
Exemple #16
0
    def setUp(self):
        super(AuthenticationTest, self).setUp()
        user = self.user_factory.create(username=USERNAME,
                                        password=PASSWORD,
                                        email=EMAIL)
        self.set_user(user)

        self.auth_client = ClientFactory.create(client_id=CLIENT_ID,
                                                client_secret=CLIENT_SECRET)

        self.url = reverse('oauth2:access_token')
    def setUp(self):
        super(AuthenticationTest, self).setUp()
        user = self.user_factory.create(
            username=USERNAME,
            password=PASSWORD,
            email=EMAIL
        )
        self.set_user(user)

        self.auth_client = ClientFactory.create(
            client_id=CLIENT_ID,
            client_secret=CLIENT_SECRET
        )

        self.url = reverse('oauth2:access_token')
Exemple #18
0
    def setUp(self):
        """
        Setup a dummy course content.
        """
        super(EdxNotesHelpersTest, self).setUp()
        ClientFactory(name="edx-notes")
        self.course = CourseFactory.create()
        self.chapter = ItemFactory.create(category="chapter",
                                          parent_location=self.course.location)
        self.chapter_2 = ItemFactory.create(
            category="chapter", parent_location=self.course.location)
        self.sequential = ItemFactory.create(
            category="sequential", parent_location=self.chapter.location)
        self.vertical = ItemFactory.create(
            category="vertical", parent_location=self.sequential.location)
        self.html_module_1 = ItemFactory.create(
            category="html", parent_location=self.vertical.location)
        self.html_module_2 = ItemFactory.create(
            category="html", parent_location=self.vertical.location)
        self.vertical_with_container = ItemFactory.create(
            category='vertical', parent_location=self.sequential.location)
        self.child_container = ItemFactory.create(
            category='split_test',
            parent_location=self.vertical_with_container.location)
        self.child_vertical = ItemFactory.create(
            category='vertical', parent_location=self.child_container.location)
        self.child_html_module = ItemFactory.create(
            category="html", parent_location=self.child_vertical.location)

        # Read again so that children lists are accurate
        self.course = self.store.get_item(self.course.location)
        self.chapter = self.store.get_item(self.chapter.location)
        self.chapter_2 = self.store.get_item(self.chapter_2.location)
        self.sequential = self.store.get_item(self.sequential.location)
        self.vertical = self.store.get_item(self.vertical.location)

        self.vertical_with_container = self.store.get_item(
            self.vertical_with_container.location)
        self.child_container = self.store.get_item(
            self.child_container.location)
        self.child_vertical = self.store.get_item(self.child_vertical.location)
        self.child_html_module = self.store.get_item(
            self.child_html_module.location)

        self.user = UserFactory.create(username="******",
                                       email="*****@*****.**",
                                       password="******")
        self.client.login(username=self.user.username, password="******")
Exemple #19
0
    def test_oauth(self):
        """ Verify the endpoint supports OAuth, and only allows authorization for staff users. """
        user = UserFactory(is_staff=False)
        oauth_client = ClientFactory.create()
        access_token = AccessTokenFactory.create(user=user, client=oauth_client).token
        headers = {"HTTP_AUTHORIZATION": "Bearer " + access_token}

        # Non-staff users should not have access to the API
        response = self.client.get(self.path, **headers)
        self.assertEqual(response.status_code, 403)

        # Staff users should have access to the API
        user.is_staff = True
        user.save()  # pylint: disable=no-member
        response = self.client.get(self.path, **headers)
        self.assertEqual(response.status_code, 200)
    def test_oauth(self):
        """ Verify the endpoint supports OAuth, and only allows authorization for staff users. """
        user = UserFactory(is_staff=False)
        oauth_client = ClientFactory.create()
        access_token = AccessTokenFactory.create(user=user,
                                                 client=oauth_client).token
        headers = {'HTTP_AUTHORIZATION': 'Bearer ' + access_token}

        # Non-staff users should not have access to the API
        response = self.client.get(self.path, **headers)
        self.assertEqual(response.status_code, 403)

        # Staff users should have access to the API
        user.is_staff = True
        user.save()  # pylint: disable=no-member
        response = self.client.get(self.path, **headers)
        self.assertEqual(response.status_code, 200)
Exemple #21
0
 def create_user_and_access_token(self):
     self.create_user()
     self.oauth_client = ClientFactory.create()
     self.access_token = AccessTokenFactory.create(user=self.user, client=self.oauth_client).token
 def create_user_and_access_token(self):
     self.user = GlobalStaffFactory.create()
     self.oauth_client = ClientFactory.create()
     self.access_token = AccessTokenFactory.create(
         user=self.user, client=self.oauth_client).token