#!/usr/bin/env python
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 2; coding: utf-8 -*-
#
# This file is part of Déjà Dup.
# For copyright information, see AUTHORS.
#
# Déjà Dup is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Déjà Dup is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Déjà Dup.  If not, see <http://www.gnu.org/licenses/>.

import os
import sys
sys.path.insert(0, sys.path[0]+'/..')
import base
import ldtp

# First we test how things work when there's no valid ssh info
def no_values():
	base.setup()
	base.set_settings_value('backend', "'ssh'")
	base.start_deja_dup(executable='deja-dup-preferences')
	assert base.get_settings_value('backend') == "'file'", base.get_settings_value('backend')

# Now test bits and pieces missing
def some_values():
	base.setup()
	base.set_settings_value('backend', "'ssh'")
	base.set_settings_value('server', "'localhost'", schema="SSH")
	base.start_deja_dup(executable='deja-dup-preferences')
	assert base.get_settings_value('backend') == "'file'" and \
	       base.get_settings_value('path', schema="File") == "'ssh://localhost/'", \
	       "%s and %s" % (base.get_settings_value('backend'), base.get_settings_value('path', schema="File"))

# Now test everything together
def all_values():
	base.setup()
	base.set_settings_value('backend', "'ssh'")
	base.set_settings_value('server', "'localhost'", schema="SSH")
	base.set_settings_value('port', '42', schema="SSH")
	base.set_settings_value('username', "'goober'", schema="SSH")
	base.set_settings_value('directory', "'/hello'", schema="SSH")
	base.start_deja_dup(executable='deja-dup-preferences')
	assert base.get_settings_value('backend') == "'file'" and \
         base.get_settings_value('path', schema="File") == "'ssh://goober@localhost:42/hello'", \
	       "%s and %s" % (base.get_settings_value('backend'), base.get_settings_value('path', schema="File"))

base.run(no_values)
base.run(some_values)
base.run(all_values)

