From a27ad89677c25a7858ce191b98a456e6398af870 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Thu, 16 Sep 2021 18:33:17 +1200 Subject: [PATCH] Spec: add user creation test --- Pipfile | 1 + Pipfile.lock | 19 ++++++++++++++++--- spec/vncserver_spec.py | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Pipfile b/Pipfile index 0f6adb8..19668bb 100644 --- a/Pipfile +++ b/Pipfile @@ -7,6 +7,7 @@ name = "pypi" mamba = "*" expects = "*" "path.py" = "*" +pexpect = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index ff20f6c..617ac1a 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "4f05d36196fe84944e2080a837510bfcfc5616a3e82204a4261bd22bbbc6086d" + "sha256": "a73a3b44f03ce3ee5c5b65a466f97ab3630d8f1666852e996afd6f529a1ba889" }, "pipfile-spec": 6, "requires": { @@ -83,7 +83,6 @@ "sha256:f0b278ce10936db1a37e6954e15a3730bea96a0997c26d7fee88e6c396c2086d", "sha256:f11642dddbb0253cc8853254301b51390ba0081750a8ac03f20ea8103f0c56b6" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'", "version": "==5.5" }, "expects": { @@ -105,7 +104,6 @@ "sha256:2de925e8d421f93bcea80d511b81accfb6a7e6b249afa4a5559557b0cf817097", "sha256:340054c5bb459fc9fd40e7eb6768c5989f3e599d18224238465b5333bc8faa7d" ], - "markers": "python_version >= '3.6'", "version": "==16.2.0" }, "path.py": { @@ -115,6 +113,21 @@ ], "index": "pypi", "version": "==12.5.0" + }, + "pexpect": { + "hashes": [ + "sha256:0b48a55dcb3c05f3329815901ea4fc1537514d6ba867a152b581d69ae3710937", + "sha256:fc65a43959d153d0114afe13997d439c22823a27cefceb5ff35c2178c6784c0c" + ], + "index": "pypi", + "version": "==4.8.0" + }, + "ptyprocess": { + "hashes": [ + "sha256:4b41f3967fce3af57cc7e94b888626c18bf37a083e3651ca8feeb66d492fef35", + "sha256:5c5d0a3b48ceee0b48485e0c26037c0acd7d29765ca3fbb5cb3831d347423220" + ], + "version": "==0.7.0" } }, "develop": {} diff --git a/spec/vncserver_spec.py b/spec/vncserver_spec.py index 870b58a..1f913cb 100644 --- a/spec/vncserver_spec.py +++ b/spec/vncserver_spec.py @@ -1,4 +1,5 @@ import os +import pexpect import shutil import subprocess from path import Path @@ -123,3 +124,22 @@ with description('vncserver') as self: expect(completed_process.returncode).to(equal(0)) check_de_was_setup_to_run('cinnamon') + + with context('guided user creation'): + with fit('asks to create a user if none exist'): + child = pexpect.spawn(f'{vncserver_cmd} -select-de cinnamon', + timeout=2) + child.expect('Enter username') + child.sendline() + child.expect('Password:') + child.sendline('password') + child.expect('Verify:') + child.sendline('password') + child.expect(pexpect.EOF) + child.close() + expect(child.exitstatus).to(equal(0)) + + home_dir = os.environ['HOME'] + user = os.environ['USER'] + completed_process = run_cmd(f'grep -q {user} {home_dir}/.kasmpasswd') + expect(completed_process.returncode).to(equal(0))