#!/usr/bin/env python
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 2; coding: utf-8 -*-
#
# This file is part of Déjà Dup.
# © 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/>.

# Test whether we correctly switch to full backup mode vs incremental

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

def delete():
  base.setup('file', sources=['data/simple'])
  base.set_gconf_value('delete-after', '30', 'int')
  base.backup_simple()
  base.last_date_change('%d days ago' % 100)
  base.start_deja_dup()
  base.backup_simple()
  assert base.num_manifests() == 2 and base.num_manifests('full') == 2
  base.last_date_change('%d days ago' % 80)
  base.start_deja_dup()
  base.backup_simple()
  assert base.num_manifests() == 2 and base.num_manifests('full') == 2
  base.last_date_change('%d days ago' % 60)
  base.start_deja_dup()
  base.backup_simple()
  assert base.num_manifests() == 2 and base.num_manifests('full') == 2
  base.last_date_change('%d days ago' % 30)
  base.start_deja_dup()
  base.backup_simple()
  assert base.num_manifests() == 2 and base.num_manifests('full') == 2
  base.last_date_change('%d days ago' % 10)
  base.start_deja_dup()
  base.backup_simple()
  assert base.num_manifests() == 3 and base.num_manifests('full') == 2
  return True

# Make sure that we don't delete backups when we aren't supposed to!
def forever():
  base.setup('file', sources=['data/simple'])
  base.backup_simple()
  base.last_date_change('%d days ago' % 1000)
  base.start_deja_dup()
  base.backup_simple()
  assert base.num_manifests() == 2 and base.num_manifests('full') == 2
  base.last_date_change('%d days ago' % 900)
  base.start_deja_dup()
  base.backup_simple()
  assert base.num_manifests() == 3 and base.num_manifests('full') == 3
  base.last_date_change('%d days ago' % 800)
  base.start_deja_dup()
  base.backup_simple()
  assert base.num_manifests() == 4 and base.num_manifests('full') == 4
  return True

# make sure to test case of many full backups, but none that are too old.
# make sure to test case of full+incrementals, using the correct date

base.run(delete)
base.run(forever)
