Mercurial > mozilla > hg > ProfileManager
annotate profilemanager/tests/test.py @ 78:553f5783999f
give a version
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 07 May 2010 17:50:10 -0700 |
parents | e76a122d8622 |
children | 145e111903d2 |
rev | line source |
---|---|
12 | 1 #!/usr/bin/env python |
2 | |
32
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
3 import os |
73
1cfd259f74cf
finish dated backups, untested
Jeff Hammel <jhammel@mozilla.com>
parents:
72
diff
changeset
|
4 import time |
32
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
5 from profilemanager import ProfileManager |
12 | 6 |
32
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
7 # Get the path to the test profiles.ini file: |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
8 from pkg_resources import resource_filename |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
9 profiles_dir = os.path.join('tests', 'profiles') |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
10 path = os.path.join(profiles_dir, 'profiles.ini') |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
11 profiles = resource_filename('profilemanager', path) |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
12 profiles_dir = resource_filename('profilemanager', profiles_dir) |
34 | 13 assert os.path.exists(profiles), '%s does not exist' % profiles |
14 assert os.path.exists(profiles_dir), '%s does not exist' % profiles_dir | |
12 | 15 |
32
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
16 # Instatiate a ProfileManager: |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
17 manager = ProfileManager(profiles) |
12 | 18 |
32
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
19 # Remove any profiles that didn't get cleaned up: |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
20 profiles_dict = manager.profiles_dict() |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
21 for profile in profiles_dict: |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
22 manager.remove(profile) |
34 | 23 assert os.listdir(profiles_dir) == ['profiles.ini'], 'profiles_dir isnt empty except profiles.ini' |
24 assert file(profiles).read().strip() == '[General]', 'profiles.ini isnt nearly empty' | |
32
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
25 |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
26 # Create a new profile: |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
27 profiledir = manager.new('testprofile') |
35 | 28 assert profiledir.endswith('.testprofile'), 'profiledir should end with testprofile, instead it is %s' % profiledir |
39 | 29 assert manager.list() == ['testprofile'] |
12 | 30 |
43 | 31 # Clone the profile: |
32 manager.clone('testprofile', 'cloneprofile') | |
33 assert sorted(manager.list()) == ['cloneprofile', 'testprofile'] | |
44 | 34 manager.remove('cloneprofile') |
43 | 35 |
50 | 36 # Backup the profile |
37 manager.backup('testprofile') | |
68
6cb674db8f51
more backup+restore testing
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
38 backups = manager.backups('testprofile') |
6cb674db8f51
more backup+restore testing
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
39 assert len(backups) == 1, "Expected one backup, instead got %d" % len(backups) |
6cb674db8f51
more backup+restore testing
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
40 assert backups[0][0].startswith('testprofile') |
6cb674db8f51
more backup+restore testing
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
41 manager.restore('testprofile') |
6cb674db8f51
more backup+restore testing
Jeff Hammel <jhammel@mozilla.com>
parents:
51
diff
changeset
|
42 manager.restore('testprofile', delete=True) |
72
619f5918b998
add a test to ensure the backup is gone
Jeff Hammel <jhammel@mozilla.com>
parents:
68
diff
changeset
|
43 backups = manager.backups('testprofile') |
619f5918b998
add a test to ensure the backup is gone
Jeff Hammel <jhammel@mozilla.com>
parents:
68
diff
changeset
|
44 assert not backups |
619f5918b998
add a test to ensure the backup is gone
Jeff Hammel <jhammel@mozilla.com>
parents:
68
diff
changeset
|
45 # TODO: test the backup with a populated profile |
619f5918b998
add a test to ensure the backup is gone
Jeff Hammel <jhammel@mozilla.com>
parents:
68
diff
changeset
|
46 |
73
1cfd259f74cf
finish dated backups, untested
Jeff Hammel <jhammel@mozilla.com>
parents:
72
diff
changeset
|
47 # Test dated backups |
1cfd259f74cf
finish dated backups, untested
Jeff Hammel <jhammel@mozilla.com>
parents:
72
diff
changeset
|
48 manager.backup('testprofile') |
74
b6bb59b79525
* return the backed-up profile
Jeff Hammel <jhammel@mozilla.com>
parents:
73
diff
changeset
|
49 old_backups = manager.backups('testprofile') |
b6bb59b79525
* return the backed-up profile
Jeff Hammel <jhammel@mozilla.com>
parents:
73
diff
changeset
|
50 assert len(old_backups) == 1, "Expected one backup, instead got %d" % len(old_backups) |
73
1cfd259f74cf
finish dated backups, untested
Jeff Hammel <jhammel@mozilla.com>
parents:
72
diff
changeset
|
51 old_time = int(time.time()) |
1cfd259f74cf
finish dated backups, untested
Jeff Hammel <jhammel@mozilla.com>
parents:
72
diff
changeset
|
52 time.sleep(3) |
1cfd259f74cf
finish dated backups, untested
Jeff Hammel <jhammel@mozilla.com>
parents:
72
diff
changeset
|
53 manager.backup('testprofile') |
74
b6bb59b79525
* return the backed-up profile
Jeff Hammel <jhammel@mozilla.com>
parents:
73
diff
changeset
|
54 new_backups = manager.backups('testprofile') |
b6bb59b79525
* return the backed-up profile
Jeff Hammel <jhammel@mozilla.com>
parents:
73
diff
changeset
|
55 assert len(new_backups) == 2, "Expected two backups, instead got %d" % len(new_backups) |
b6bb59b79525
* return the backed-up profile
Jeff Hammel <jhammel@mozilla.com>
parents:
73
diff
changeset
|
56 restore_time = old_time + 1 |
b6bb59b79525
* return the backed-up profile
Jeff Hammel <jhammel@mozilla.com>
parents:
73
diff
changeset
|
57 restored = manager.restore('testprofile', date=restore_time) |
b6bb59b79525
* return the backed-up profile
Jeff Hammel <jhammel@mozilla.com>
parents:
73
diff
changeset
|
58 assert restored == old_backups[0], "Tried to restore from %d [%s], but got [%s]" % (restore_time, old_backups[0], restored) |
73
1cfd259f74cf
finish dated backups, untested
Jeff Hammel <jhammel@mozilla.com>
parents:
72
diff
changeset
|
59 # TODO: test with alternate forms of date |
50 | 60 |
74
b6bb59b79525
* return the backed-up profile
Jeff Hammel <jhammel@mozilla.com>
parents:
73
diff
changeset
|
61 # Restore the newest profile |
b6bb59b79525
* return the backed-up profile
Jeff Hammel <jhammel@mozilla.com>
parents:
73
diff
changeset
|
62 restored = manager.restore('testprofile') |
76 | 63 assert restored != old_backups[0], "Tried to restore the newest but got the old one [%s]" % old_backups[0] |
74
b6bb59b79525
* return the backed-up profile
Jeff Hammel <jhammel@mozilla.com>
parents:
73
diff
changeset
|
64 manager.restore('testprofile', delete=True) |
b6bb59b79525
* return the backed-up profile
Jeff Hammel <jhammel@mozilla.com>
parents:
73
diff
changeset
|
65 manager.restore('testprofile', delete=True) |
b6bb59b79525
* return the backed-up profile
Jeff Hammel <jhammel@mozilla.com>
parents:
73
diff
changeset
|
66 assert not manager.backups() |
b6bb59b79525
* return the backed-up profile
Jeff Hammel <jhammel@mozilla.com>
parents:
73
diff
changeset
|
67 assert manager.list() == ['testprofile'] |
b6bb59b79525
* return the backed-up profile
Jeff Hammel <jhammel@mozilla.com>
parents:
73
diff
changeset
|
68 |
32
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
69 # Cleanup: |
6f2ad307fdda
dont use any testing framework because they make testing hard
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
70 manager.remove('testprofile') |
39 | 71 assert manager.list() == [] |
49
cbd471e0146f
the variable profiles, not the string
Jeff Hammel <jhammel@mozilla.com>
parents:
48
diff
changeset
|
72 f = file(profiles, 'w') |
48
09a2666999fa
* restore profiles.ini to base in tests
Jeff Hammel <jhammel@mozilla.com>
parents:
44
diff
changeset
|
73 print >> f, '[General]' |