Skip to content

Commit

Permalink
Add unit test for create_token()
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Deziel <[email protected]>
  • Loading branch information
simondeziel committed Jun 2, 2022
1 parent a7cee06 commit 81ca43d
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions pylxd/models/tests/test_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# under the License.
import os

import json
from pylxd import models
from pylxd.tests import testing

Expand Down Expand Up @@ -46,6 +47,67 @@ def test_create(self):
an_certificate.fingerprint,
)

def test_create_token(self):
"""A token is returned."""
self.add_rule(
{
"text": json.dumps(
{
"type": "sync",
"status": "Operation created",
"status_code": 100,
"operation": "/1.0/operations/a1d77f1b-7dfb-44e0-a3a3-1dd18bd5c15a",
"error_code": 0,
"error": "",
"metadata": {
"id": "a1d77f1b-7dfb-44e0-a3a3-1dd18bd5c15a",
"class": "token",
"description": "Executing operation",
"created_at": "2022-06-01T19:22:21.778204449Z",
"updated_at": "2022-06-01T19:22:21.778204449Z",
"status": "Running",
"status_code": 103,
"resources": None,
"metadata": {
"addresses": [
"127.0.0.1:8443",
"[::1]:8443",
],
"fingerprint": "eddaa6023f9064f94dd6fadb36c01d9af9de935efff76f4ebada5a2fda4753be",
"request": {
"name": "foo",
"type": "client",
"restricted": True,
"projects": ["default"],
"certificate": "",
"password": "",
"token": True,
},
"secret": "6efac2f5de066103dc9798414e916996a8ffe3b9818608d4fe3ba175fae618ad",
},
"may_cancel": True,
"err": "",
"location": "foo",
},
},
),
"method": "POST",
"url": r"^http://pylxd.test/1.0/certificates$",
"headers": {
"location": "/1.0/operations/a1d77f1b-7dfb-44e0-a3a3-1dd18bd5c15a",
},
},
)

a_token = self.client.certificates.create_token(
name="foo", projects=["default"], restricted=True
)

self.assertEqual(
"eyJuYW1lIjoiZm9vIiwiZmluZ2VycHJpbnQiOiJlZGRhYTYwMjNmOTA2NGY5NGRkNmZhZGIzNmMwMWQ5YWY5ZGU5MzVlZmZmNzZmNGViYWRhNWEyZmRhNDc1M2JlIiwiYWRkcmVzc2VzIjpbIjEyNy4wLjAuMTo4NDQzIiwiWzo6MV06ODQ0MyJdLCJzZWNyZXQiOiI2ZWZhYzJmNWRlMDY2MTAzZGM5Nzk4NDE0ZTkxNjk5NmE4ZmZlM2I5ODE4NjA4ZDRmZTNiYTE3NWZhZTYxOGFkIn0=",
a_token,
)

def test_fetch(self):
"""A partial object is fully fetched."""
an_certificate = models.Certificate(self.client, fingerprint="an-certificate")
Expand Down

0 comments on commit 81ca43d

Please sign in to comment.