Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Paul Graydon
slapos.core
Commits
6ce7ea07
Commit
6ce7ea07
authored
Aug 08, 2011
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use more of "persistence".
Make test more flexible and controlallbe by exposing groups.
parent
7386bf0c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
13 deletions
+23
-13
slapos/tests/slapformat.py
slapos/tests/slapformat.py
+23
-13
No files found.
slapos/tests/slapformat.py
View file @
6ce7ea07
...
@@ -8,6 +8,7 @@ import os
...
@@ -8,6 +8,7 @@ import os
import
pwd
import
pwd
USER_LIST
=
[]
USER_LIST
=
[]
GROUP_LIST
=
[]
class
FakeConfig
:
class
FakeConfig
:
pass
pass
...
@@ -28,6 +29,9 @@ class FakeCallAndRead:
...
@@ -28,6 +29,9 @@ class FakeCallAndRead:
if
'useradd'
in
argument_list
:
if
'useradd'
in
argument_list
:
global
USER_LIST
global
USER_LIST
USER_LIST
.
append
(
argument_list
[
-
1
])
USER_LIST
.
append
(
argument_list
[
-
1
])
if
'groupadd'
in
argument_list
:
global
GROUP_LIST
GROUP_LIST
.
append
(
argument_list
[
-
1
])
self
.
external_command_list
.
append
(
argument_list
)
self
.
external_command_list
.
append
(
argument_list
)
return
0
,
'UP'
return
0
,
'UP'
...
@@ -44,7 +48,8 @@ class LoggableWrapper:
...
@@ -44,7 +48,8 @@ class LoggableWrapper:
class
GrpMock
:
class
GrpMock
:
@
classmethod
@
classmethod
def
getgrnam
(
self
,
name
):
def
getgrnam
(
self
,
name
):
if
name
==
'testuser'
:
global
GROUP_LIST
if
name
in
GROUP_LIST
:
return
True
return
True
raise
KeyError
raise
KeyError
...
@@ -60,11 +65,6 @@ class PwdMock:
...
@@ -60,11 +65,6 @@ class PwdMock:
raise
KeyError
raise
KeyError
class
SlapformatMixin
(
unittest
.
TestCase
):
class
SlapformatMixin
(
unittest
.
TestCase
):
@
classmethod
def
raisingKeyError
(
self
,
*
args
,
**
kwargs
):
raise
KeyError
def
patchPwd
(
self
):
def
patchPwd
(
self
):
self
.
saved_pwd
=
dict
()
self
.
saved_pwd
=
dict
()
for
fake
in
vars
(
PwdMock
):
for
fake
in
vars
(
PwdMock
):
...
@@ -111,7 +111,9 @@ class SlapformatMixin(unittest.TestCase):
...
@@ -111,7 +111,9 @@ class SlapformatMixin(unittest.TestCase):
self
.
partition
=
slapos
.
format
.
Partition
(
'partition'
,
'/part_path'
,
self
.
partition
=
slapos
.
format
.
Partition
(
'partition'
,
'/part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
None
)
slapos
.
format
.
User
(
'testuser'
),
[],
None
)
global
USER_LIST
global
USER_LIST
USER_LIST
=
[
'testuser'
]
USER_LIST
=
[]
global
GROUP_LIST
GROUP_LIST
=
[]
self
.
real_callAndRead
=
slapos
.
format
.
callAndRead
self
.
real_callAndRead
=
slapos
.
format
.
callAndRead
self
.
fakeCallAndRead
=
FakeCallAndRead
()
self
.
fakeCallAndRead
=
FakeCallAndRead
()
...
@@ -124,8 +126,6 @@ class SlapformatMixin(unittest.TestCase):
...
@@ -124,8 +126,6 @@ class SlapformatMixin(unittest.TestCase):
self
.
restoreOs
()
self
.
restoreOs
()
self
.
restoreGrp
()
self
.
restoreGrp
()
self
.
restorePwd
()
self
.
restorePwd
()
global
USER_LIST
USER_LIST
=
[
'testuser'
]
slapos
.
format
.
callAndRead
=
self
.
real_callAndRead
slapos
.
format
.
callAndRead
=
self
.
real_callAndRead
class
TestComputer
(
SlapformatMixin
):
class
TestComputer
(
SlapformatMixin
):
...
@@ -210,6 +210,8 @@ class TestComputer(SlapformatMixin):
...
@@ -210,6 +210,8 @@ class TestComputer(SlapformatMixin):
class
TestPartition
(
SlapformatMixin
):
class
TestPartition
(
SlapformatMixin
):
def
test_createPath
(
self
):
def
test_createPath
(
self
):
global
USER_LIST
USER_LIST
=
[
'testuser'
]
self
.
partition
.
createPath
()
self
.
partition
.
createPath
()
self
.
assertEqual
(
self
.
assertEqual
(
[
[
...
@@ -260,8 +262,8 @@ class TestUser(SlapformatMixin):
...
@@ -260,8 +262,8 @@ class TestUser(SlapformatMixin):
self
.
fakeCallAndRead
.
external_command_list
)
self
.
fakeCallAndRead
.
external_command_list
)
def
test_create_group_exists
(
self
):
def
test_create_group_exists
(
self
):
pwd
.
getpwnam
=
self
.
raisingKeyError
global
GROUP_LIST
GROUP_LIST
=
[
'testuser'
]
user
=
slapos
.
format
.
User
(
'testuser'
)
user
=
slapos
.
format
.
User
(
'testuser'
)
user
.
setPath
(
'/testuser'
)
user
.
setPath
(
'/testuser'
)
user
.
create
()
user
.
create
()
...
@@ -274,7 +276,8 @@ class TestUser(SlapformatMixin):
...
@@ -274,7 +276,8 @@ class TestUser(SlapformatMixin):
self
.
fakeCallAndRead
.
external_command_list
)
self
.
fakeCallAndRead
.
external_command_list
)
def
test_create_user_exists_additional_groups
(
self
):
def
test_create_user_exists_additional_groups
(
self
):
grp
.
getgrnam
=
self
.
raisingKeyError
global
USER_LIST
USER_LIST
=
[
'testuser'
]
user
=
slapos
.
format
.
User
(
'testuser'
,
[
'additionalgroup1'
,
user
=
slapos
.
format
.
User
(
'testuser'
,
[
'additionalgroup1'
,
'additionalgroup2'
])
'additionalgroup2'
])
user
.
setPath
(
'/testuser'
)
user
.
setPath
(
'/testuser'
)
...
@@ -289,7 +292,8 @@ class TestUser(SlapformatMixin):
...
@@ -289,7 +292,8 @@ class TestUser(SlapformatMixin):
self
.
fakeCallAndRead
.
external_command_list
)
self
.
fakeCallAndRead
.
external_command_list
)
def
test_create_user_exists
(
self
):
def
test_create_user_exists
(
self
):
grp
.
getgrnam
=
self
.
raisingKeyError
global
USER_LIST
USER_LIST
=
[
'testuser'
]
user
=
slapos
.
format
.
User
(
'testuser'
)
user
=
slapos
.
format
.
User
(
'testuser'
)
user
.
setPath
(
'/testuser'
)
user
.
setPath
(
'/testuser'
)
user
.
create
()
user
.
create
()
...
@@ -303,6 +307,10 @@ class TestUser(SlapformatMixin):
...
@@ -303,6 +307,10 @@ class TestUser(SlapformatMixin):
self
.
fakeCallAndRead
.
external_command_list
)
self
.
fakeCallAndRead
.
external_command_list
)
def
test_create_user_group_exists
(
self
):
def
test_create_user_group_exists
(
self
):
global
USER_LIST
USER_LIST
=
[
'testuser'
]
global
GROUP_LIST
GROUP_LIST
=
[
'testuser'
]
user
=
slapos
.
format
.
User
(
'testuser'
)
user
=
slapos
.
format
.
User
(
'testuser'
)
user
.
setPath
(
'/testuser'
)
user
.
setPath
(
'/testuser'
)
user
.
create
()
user
.
create
()
...
@@ -315,6 +323,8 @@ class TestUser(SlapformatMixin):
...
@@ -315,6 +323,8 @@ class TestUser(SlapformatMixin):
self
.
fakeCallAndRead
.
external_command_list
)
self
.
fakeCallAndRead
.
external_command_list
)
def
test_isAvailable
(
self
):
def
test_isAvailable
(
self
):
global
USER_LIST
USER_LIST
=
[
'testuser'
]
user
=
slapos
.
format
.
User
(
'testuser'
)
user
=
slapos
.
format
.
User
(
'testuser'
)
self
.
assertTrue
(
user
.
isAvailable
())
self
.
assertTrue
(
user
.
isAvailable
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment