Exemplo n.º 1
0
class TestKey(base.BaseTest):
    def __init__(self, methodName='runTest'):
        super(TestKey, self).__init__(methodName)
        if self.auth:
            self.key = self._g.list_keys()[0]
        else:
            json = {
                    'url': 'https://api.github.com/user/keys/id',
                    'verified': True,
                    'id': 999999,
                    'key': 'ssh-rsa AAAAB4...',
                    'title': 'fake'
                    }
            self.key = Key(json)

    def test_key(self):
        expect(self.key).isinstance(Key)

    def test_pubkey(self):
        expect(self.key.key).isinstance(base.str_test)

    def test_id(self):
        expect(self.key.id) > 0

    def test_title(self):
        expect(self.key.title).isinstance(base.str_test)

    def test_requires_auth(self):
        if not self.auth:
            with expect.raises(github3.GitHubError):
                self.key.update('title', 'ssha-rsa AAAAB2...')
                self.key.delete()
Exemplo n.º 2
0
    def key(self, id_num):
        """Gets the authenticated user's key specified by id_num.

        :param int id_num: (required), unique id of the key
        :returns: :class:`Key <github3.users.Key>`
        """
        json = None
        if int(id_num) > 0:
            url = self._build_url('user', 'keys', str(id_num))
            json = self._json(self._get(url), 200)
        return Key(json, self) if json else None
Exemplo n.º 3
0
class TestKey(base.BaseTest):
    def __init__(self, methodName='runTest'):
        super(TestKey, self).__init__(methodName)
        if self.auth:
            self.key = self._g.list_keys()[0]
        else:
            json = {
                    'url': 'https://api.github.com/user/keys/id',
                    'verified': True,
                    'id': 999999,
                    'key': 'ssh-rsa AAAAB4...',
                    'title': 'fake'
                    }
            self.key = Key(json)

    def test_key(self):
        expect(self.key).isinstance(Key)
        expect(repr(self.key)) != ''
        self.key._update_(self.key.to_json())

    def test_pubkey(self):
        expect(self.key.key).isinstance(base.str_test)

    def test_id(self):
        expect(self.key.id) > 0

    def test_title(self):
        expect(self.key.title).isinstance(base.str_test)

    def test_requires_auth(self):
        if self.auth:
            return
        self.raisesGHE(self.key.update, 'title', 'ssha-rsa AAAAB2...')
        self.raisesGHE(self.key.delete)

    def test_with_auth(self):
        if not self.auth:
            return
        expect(self.key.update(None, None)).is_False()
        expect(self.key.update(self.key.title, self.key.key)).is_True()
Exemplo n.º 4
0
 def __init__(self, methodName='runTest'):
     super(TestKey, self).__init__(methodName)
     if self.auth:
         self.key = self._g.list_keys()[0]
     else:
         json = {
                 'url': 'https://api.github.com/user/keys/id',
                 'verified': True,
                 'id': 999999,
                 'key': 'ssh-rsa AAAAB4...',
                 'title': 'fake'
                 }
         self.key = Key(json)
Exemplo n.º 5
0
    def create_key(self, title, key):
        """Create a new key for the authenticated user.

        :param str title: (required), key title
        :param key: (required), actual key contents, accepts path as a string
            or file-like object
        :returns: :class:`Key <github3.users.Key>`
        """
        created = None

        if title and key:
            url = self._build_url('user', 'keys')
            req = self._post(url, data={'title': title, 'key': key})
            json = self._json(req, 201)
            if json:
                created = Key(json, self)
        return created