def test_node_chown(mock_chown, mock_getgrnam, mock_getpwnam, mock_path_exists, atts, expected): # pylint: disable=too-many-arguments """Tests Node's chown method.""" node = Node(atts) if 'owner' not in atts: atts['owner'] = CURRENT_USER if 'group' not in atts: atts['group'] = 'nogroup' if atts['owner'] == 'nobody' else CURRENT_GROUP mock_path_exists.return_value = True # Assume this is working for this test mock_getpwnam(atts['owner']).pw_uid = 123 # Just a number to use for mocking mock_getgrnam(atts['group']).gr_gid = 123 assert expected == node.chown() if atts['path'] is not None: mock_getpwnam.assert_called_with(CURRENT_USER if not atts['owner'] else atts['owner']) mock_getgrnam.assert_called_with(CURRENT_GROUP if not atts['group'] else atts['group']) mock_chown.assert_called_once_with(atts['path'], 123, 123)
def test_node_chown_nonexisting(mock_path_exists): """Tests Node's chown method with a nonexisting node.""" mock_path_exists.return_value = False node = Node(DEFUALT_ATTS) with pytest.raises(IOError): node.chown()