Exemple #1
0
class TestAddonGithubUserSettings(OsfTestCase):
    def setUp(self):
        OsfTestCase.setUp(self)
        self.user_settings = AddonGitHubUserSettings()
        self.oauth_settings = AddonGitHubOauthSettings()
        self.oauth_settings.github_user_id = 'testuser'
        self.oauth_settings.save()
        self.user_settings.oauth_settings = self.oauth_settings
        self.user_settings.save()

    def test_repr(self):
        self.user_settings.owner = UserFactory()
        assert_in(self.user_settings.owner._id, repr(self.user_settings))
        oauth_settings = GitHubOauthSettingsFactory()

    def test_public_id_is_none_if_no_oauth_settings_attached(self):
        self.user_settings.oauth_settings = None
        self.user_settings.save()
        # Regression test for:
        #  https://github.com/CenterForOpenScience/openscienceframework.org/issues/1053
        assert_is_none(self.user_settings.public_id)

    def test_github_user_name(self):
        self.oauth_settings.github_user_name = "test user name"
        self.oauth_settings.save()
        assert_equal(self.user_settings.github_user_name, "test user name")

    def test_oauth_access_token(self):
        self.oauth_settings.oauth_access_token = "test access token"
        self.oauth_settings.save()
        assert_equal(self.user_settings.oauth_access_token,
                     "test access token")

    def test_oauth_token_type(self):
        self.oauth_settings.oauth_token_type = "test token type"
        self.oauth_settings.save()
        assert_equal(self.user_settings.oauth_token_type, "test token type")

    @mock.patch('website.addons.github.api.GitHub.revoke_token')
    def test_clear_auth(self, mock_revoke_token):
        mock_revoke_token.return_value = True
        self.user_settings.clear_auth(save=True)
        assert_false(self.user_settings.github_user_name)
        assert_false(self.user_settings.oauth_token_type)
        assert_false(self.user_settings.oauth_access_token)
        assert_false(self.user_settings.oauth_settings)
Exemple #2
0
class TestAddonGithubUserSettings(OsfTestCase):

    def setUp(self):
        OsfTestCase.setUp(self)
        self.user_settings = AddonGitHubUserSettings()
        self.oauth_settings = AddonGitHubOauthSettings()
        self.oauth_settings.github_user_id = 'testuser'
        self.oauth_settings.save()
        self.user_settings.oauth_settings = self.oauth_settings
        self.user_settings.save()

    def test_repr(self):
        self.user_settings.owner = UserFactory()
        assert_in(self.user_settings.owner._id, repr(self.user_settings))
        oauth_settings = GitHubOauthSettingsFactory()

    def test_public_id_is_none_if_no_oauth_settings_attached(self):
        self.user_settings.oauth_settings = None
        self.user_settings.save()
        # Regression test for:
        #  https://github.com/CenterForOpenScience/openscienceframework.org/issues/1053
        assert_is_none(self.user_settings.public_id)

    def test_github_user_name(self):
        self.oauth_settings.github_user_name = "test user name"
        self.oauth_settings.save()
        assert_equal(self.user_settings.github_user_name, "test user name")

    def test_oauth_access_token(self):
        self.oauth_settings.oauth_access_token = "test access token"
        self.oauth_settings.save()
        assert_equal(self.user_settings.oauth_access_token, "test access token")

    def test_oauth_token_type(self):
        self.oauth_settings.oauth_token_type = "test token type"
        self.oauth_settings.save()
        assert_equal(self.user_settings.oauth_token_type, "test token type")

    @mock.patch('website.addons.github.api.GitHub.revoke_token')
    def test_clear_auth(self, mock_revoke_token):
        mock_revoke_token.return_value = True
        self.user_settings.clear_auth(save=True)
        assert_false(self.user_settings.github_user_name)
        assert_false(self.user_settings.oauth_token_type)
        assert_false(self.user_settings.oauth_access_token)
        assert_false(self.user_settings.oauth_settings)