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
Jérome Perrin
slapos.core
Commits
9be006b0
Commit
9be006b0
authored
Jun 24, 2013
by
Thomas Larrieu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changing 2 tests, making assertion on method call and not on side effects
parent
d4b9c175
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
23 deletions
+27
-23
slapos/tests/slapgrid.py
slapos/tests/slapgrid.py
+27
-23
No files found.
slapos/tests/slapgrid.py
View file @
9be006b0
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
#
#
##############################################################################
##############################################################################
from
__future__
import
absolute_import
import
httplib
import
httplib
import
logging
import
logging
import
os
import
os
...
@@ -40,6 +41,7 @@ import unittest
...
@@ -40,6 +41,7 @@ import unittest
import
urlparse
import
urlparse
import
xml_marshaller
import
xml_marshaller
from
mock
import
patch
import
slapos.slap.slap
import
slapos.slap.slap
import
slapos.grid.utils
import
slapos.grid.utils
...
@@ -49,6 +51,7 @@ from slapos.grid.utils import md5digest
...
@@ -49,6 +51,7 @@ from slapos.grid.utils import md5digest
from
slapos.grid.watchdog
import
Watchdog
,
getWatchdogID
from
slapos.grid.watchdog
import
Watchdog
,
getWatchdogID
from
slapos.grid
import
SlapObject
from
slapos.grid
import
SlapObject
dummylogger
=
logging
.
getLogger
()
dummylogger
=
logging
.
getLogger
()
...
@@ -238,13 +241,13 @@ class MasterMixin(BasicMixin):
...
@@ -238,13 +241,13 @@ class MasterMixin(BasicMixin):
def
_patchHttplib
(
self
):
def
_patchHttplib
(
self
):
"""Overrides httplib"""
"""Overrides httplib"""
import
mock.httplib
import
slapos.tests.
mock.httplib
self
.
saved_httplib
=
{}
self
.
saved_httplib
=
{}
for
fake
in
vars
(
mock
.
httplib
):
for
fake
in
vars
(
slapos
.
tests
.
mock
.
httplib
):
self
.
saved_httplib
[
fake
]
=
getattr
(
httplib
,
fake
,
None
)
self
.
saved_httplib
[
fake
]
=
getattr
(
httplib
,
fake
,
None
)
setattr
(
httplib
,
fake
,
getattr
(
mock
.
httplib
,
fake
))
setattr
(
httplib
,
fake
,
getattr
(
slapos
.
tests
.
mock
.
httplib
,
fake
))
def
_unpatchHttplib
(
self
):
def
_unpatchHttplib
(
self
):
"""Restores httplib overriding"""
"""Restores httplib overriding"""
...
@@ -1172,43 +1175,44 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1172,43 +1175,44 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
"""
"""
Checks that a partition is not processed when
Checks that a partition is not processed when
its periodicity is negative
its periodicity is negative
1. We setup one instance and set periodicity at -1
2. We mock the install method from slapos.grid.slapgrid.Partition
3. We launch slapgrid once so that .timestamp file is created and check that install method is
indeed called (through mocked_method.called
4. We launch slapgrid anew and check that install as not been called again
"""
"""
def
get_runtime
(
instance
):
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
instance
.
partition_path
,
'.timestamp'
)))
return
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance
.
partition_path
,
'.timestamp'
))
periodicity
=
-
1
timestamp
=
str
(
int
(
time
.
time
()))
timestamp
=
str
(
int
(
time
.
time
()))
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
1
,
1
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
1
,
1
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
instance
.
software
.
setPeriodicity
(
periodicity
)
instance
.
software
.
setPeriodicity
(
-
1
)
instance
.
timestamp
=
timestamp
instance
.
timestamp
=
timestamp
self
.
launchSlapgrid
()
with
patch
.
object
(
slapos
.
grid
.
slapgrid
.
Partition
,
'install'
,
return_value
=
None
)
as
mock_method
:
first_runtime
=
get_runtime
(
instance
)
self
.
launchSlapgrid
(
)
self
.
launchSlapgrid
(
)
self
.
assertTrue
(
mock_method
.
called
)
second_runtime
=
get_runtime
(
instance
)
self
.
launchSlapgrid
(
)
self
.
assertEqual
(
first_runtime
,
second_runtime
)
self
.
assertEqual
(
mock_method
.
call_count
,
1
)
def
test_one_partition_is_always_processed_when_periodicity_is_zero
(
self
):
def
test_one_partition_is_always_processed_when_periodicity_is_zero
(
self
):
"""
"""
Checks that a partition is always processed when
Checks that a partition is always processed when
its periodicity is 0
its periodicity is 0
1. We setup one instance and set periodicity at 0
2. We mock the install method from slapos.grid.slapgrid.Partition
3. We launch slapgrid once so that .timestamp file is created
4. We launch slapgrid anew and check that install has been called twice (one time because of the
new setup and one time because of periodicity = 0)
"""
"""
def
get_runtime
(
instance
):
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
instance
.
partition_path
,
'.timestamp'
)))
return
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance
.
partition_path
,
'.timestamp'
))
periodicity
=
0
timestamp
=
str
(
int
(
time
.
time
()))
timestamp
=
str
(
int
(
time
.
time
()))
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
1
,
1
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
1
,
1
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
instance
.
software
.
setPeriodicity
(
periodicity
)
instance
.
software
.
setPeriodicity
(
0
)
instance
.
timestamp
=
timestamp
instance
.
timestamp
=
timestamp
self
.
launchSlapgrid
()
with
patch
.
object
(
slapos
.
grid
.
slapgrid
.
Partition
,
'install'
,
return_value
=
None
)
as
mock_method
:
first_runtime
=
get_runtime
(
instance
)
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
second_runtime
=
get_runtime
(
instance
)
self
.
assertEqual
(
mock_method
.
call_count
,
2
)
self
.
assertNotEqual
(
first_runtime
,
second_runtime
)
def
test_one_partition_buildout_fail_does_not_disturb_others
(
self
):
def
test_one_partition_buildout_fail_does_not_disturb_others
(
self
):
"""
"""
...
...
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