#!/usr/bin/env python
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 2; coding: utf-8 -*-
#
# This file is part of Déjà Dup.
# © 2008,2009 Michael Terry <mike@mterry.name>
#
# 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 sys
import os
import datetime
sys.path.insert(0, sys.path[0]+'/..')
import base
import ldtp

BASEPATH = '/tmp/deja-dup-test/'
DATE1 = datetime.datetime.strptime('8 1 21:14:21 2009', '%m %d %H:%M:%S %Y').strftime('%c')
DATE2 = datetime.datetime.strptime('8 1 21:14:34 2009', '%m %d %H:%M:%S %Y').strftime('%c')
DATE3 = datetime.datetime.strptime('8 1 21:14:41 2009', '%m %d %H:%M:%S %Y').strftime('%c')

def check_dir(path, oneval):
  root = path+BASEPATH
  assert base.file_equals(root+'one', oneval)
  assert base.file_equals(root+'two', 'two\n')
  assert base.file_equals(root+'three', 'three\n')
  assert base.file_equals(root+'top/one', 'one\n')
  assert os.path.isdir(root+'top/next')

def test():
  restoredir = base.get_temp_name('restore')
  base.setup('file', dest=(sys.path[0]+'/vols/simple'), encrypt=False)
  base.restore_simple(restoredir, DATE1)
  check_dir(restoredir, 'one\n')
  os.system("rm -r %s" % restoredir)
  base.start_deja_dup()
  base.restore_simple(restoredir, DATE2)
  check_dir(restoredir, 'one1\n')
  os.system("rm -r %s" % restoredir)
  base.start_deja_dup()
  base.restore_simple(restoredir, DATE3)
  check_dir(restoredir, 'one1!\n')
  return True

base.run(test)
