| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
import logging |
| 4 |
from unittest.mock import patch |
| 5 |
|
| 6 |
import mozunit |
| 7 |
import pytest |
| 8 |
|
| 9 |
|
| 10 |
@pytest.mark.parametrize("boolean_value", [True, False]) |
| 11 |
def test_set_chown_r_attribute( |
| 12 |
mock_adb_object, redirect_stdout_and_assert, boolean_value |
| 13 |
): |
| 14 |
mock_adb_object._chown_R = boolean_value |
| 15 |
assert mock_adb_object._chown_R == boolean_value |
| 16 |
|
| 17 |
|
| 18 |
def test_chown_path_internal(mock_adb_object, redirect_stdout_and_assert): |
| 19 |
"""Tests whether attempt to chown internal path is ignored""" |
| 20 |
with patch.object(logging, "getLogger") as mock_log: |
| 21 |
mock_adb_object._logger = mock_log |
| 22 |
|
| 23 |
testing_parameters = { |
| 24 |
"owner": "someuser", |
| 25 |
"path": "internal_storage", |
| 26 |
} |
| 27 |
expected = "Ignoring attempt to chown external storage" |
| 28 |
mock_adb_object.chown(**testing_parameters) |
| 29 |
assert "".join(mock_adb_object._logger.method_calls[0][1]) != "" |
| 30 |
assert "".join(mock_adb_object._logger.method_calls[0][1]) == expected |
| 31 |
|
| 32 |
|
| 33 |
def test_chown_one_path(mock_adb_object, redirect_stdout_and_assert): |
| 34 |
"""Tests the path where only one path is provided.""" |
| 35 |
# set up mock logging and self._chown_R attribute. |
| 36 |
with patch.object(logging, "getLogger") as mock_log: |
| 37 |
mock_adb_object._logger = mock_log |
| 38 |
mock_adb_object._chown_R = True |
| 39 |
|
| 40 |
testing_parameters = { |
| 41 |
"owner": "someuser", |
| 42 |
"path": "/system", |
| 43 |
} |
| 44 |
command = "chown {owner} {path}".format(**testing_parameters) |
| 45 |
testing_parameters["text"] = command |
| 46 |
redirect_stdout_and_assert(mock_adb_object.chown, **testing_parameters) |
| 47 |
|
| 48 |
|
| 49 |
def test_chown_one_path_with_group(mock_adb_object, redirect_stdout_and_assert): |
| 50 |
"""Tests the path where group is provided.""" |
| 51 |
# set up mock logging and self._chown_R attribute. |
| 52 |
with patch.object(logging, "getLogger") as mock_log: |
| 53 |
mock_adb_object._logger = mock_log |
| 54 |
mock_adb_object._chown_R = True |
| 55 |
|
| 56 |
testing_parameters = { |
| 57 |
"owner": "someuser", |
| 58 |
"path": "/system", |
| 59 |
"group": "group_2", |
| 60 |
} |
| 61 |
command = "chown {owner}.{group} {path}".format(**testing_parameters) |
| 62 |
testing_parameters["text"] = command |
| 63 |
redirect_stdout_and_assert(mock_adb_object.chown, **testing_parameters) |
| 64 |
|
| 65 |
|
| 66 |
if __name__ == "__main__": |
| 67 |
mozunit.main() |