def test_get_profiles_single(self): """A profiles.ini with a single profile works as expected.""" with open(self.p(b'profiles.ini'), 'wb') as fh: fh.write(b'\n'.join([ b'[General]', b'StartWithLastProfile=0', b'', b'[Profile0]', b'Name=default', b'IsRelative=1', b'Path=Profiles.jmt0dxx7.default', ])) profiles = auth.get_profiles(self.tmpdir) self.assertEqual(len(profiles), 1) self.assertEqual( profiles[0], { b'name': b'default', b'path': self.p(b'Profiles.jmt0dxx7.default'), b'default': False, b'mtime': -1, }) with open(self.p(b'profiles.ini'), 'ab') as fh: fh.write(b'\nDefault=1\n') profiles = auth.get_profiles(self.tmpdir) self.assertEqual(len(profiles), 1) self.assertTrue(profiles[0][b'default'])
def test_get_profiles_single(self): """A profiles.ini with a single profile works as expected.""" with open(self.p('profiles.ini'), 'wb') as fh: fh.write('\n'.join([ '[General]', 'StartWithLastProfile=0', '', '[Profile0]', 'Name=default', 'IsRelative=1', 'Path=Profiles.jmt0dxx7.default', ])) profiles = auth.get_profiles(self.tmpdir) self.assertEqual(len(profiles), 1) self.assertEqual(profiles[0], { 'name': 'default', 'path': self.p('Profiles.jmt0dxx7.default'), 'default': False, 'mtime': -1, }) with open(self.p('profiles.ini'), 'ab') as fh: fh.write('\nDefault=1\n') profiles = auth.get_profiles(self.tmpdir) self.assertEqual(len(profiles), 1) self.assertTrue(profiles[0]['default'])
def test_multiple_profiles_default_first(self): """Test that the default profile always comes first.""" with open(self.p(b'profiles.ini'), 'wb') as fh: fh.write(b'\n'.join([ b'[Profile0]', b'Name=notdefault', b'IsRelative=1', b'Path=notdefault', b'', b'[Profile1]', b'Name=default', b'IsRelative=1', b'Path=default', b'Default=1', ])) profiles = auth.get_profiles(self.tmpdir) self.assertEqual(profiles, [{ b'name': b'default', b'path': self.p(b'default'), b'default': True, b'mtime': -1, }, { b'name': b'notdefault', b'path': self.p(b'notdefault'), b'default': False, b'mtime': -1, }])
def test_multiple_profiles_default_first(self): """Test that the default profile always comes first.""" with open(self.p('profiles.ini'), 'wb') as fh: fh.write('\n'.join([ '[Profile0]', 'Name=notdefault', 'IsRelative=1', 'Path=notdefault', '', '[Profile1]', 'Name=default', 'IsRelative=1', 'Path=default', 'Default=1', ])) profiles = auth.get_profiles(self.tmpdir) self.assertEqual(profiles, [ { 'name': 'default', 'path': self.p('default'), 'default': True, 'mtime': -1, }, { 'name': 'notdefault', 'path': self.p('notdefault'), 'default': False, 'mtime': -1, } ])
def test_multiple_profiles_age_ordering(self): """Profile with newest file content comes first.""" with open(self.p(b'profiles.ini'), 'wb') as fh: fh.write(b'\n'.join([ b'[Profile0]', b'Name=foo', b'IsRelative=1', b'Path=foo', b'', b'[Profile1]', b'Name=bar', b'IsRelative=1', b'Path=bar', b'', b'[Profile2]', b'Name=baz', b'IsRelative=1', b'Path=baz', b'Default=1', ])) for p in [b'foo', b'bar', b'baz']: os.mkdir(self.p(p)) os.mkdir(self.p(p, b'dummydir')) with open(self.p(p, b'dummy1'), 'a'): pass now = int(time.time()) t_foo = now - 10 t_bar = now - 5 t_baz = now - 7 os.utime(self.p(b'foo', b'dummy1'), (t_foo, t_foo)) os.utime(self.p(b'bar', b'dummy1'), (t_bar, t_bar)) os.utime(self.p(b'baz', b'dummy1'), (t_baz, t_baz)) profiles = auth.get_profiles(self.tmpdir) names = [p[b'name'] for p in profiles] self.assertEqual(names, [b'baz', b'bar', b'foo'])
def test_multiple_profiles_age_ordering(self): """Profile with newest file content comes first.""" with open(self.p('profiles.ini'), 'wb') as fh: fh.write('\n'.join([ '[Profile0]', 'Name=foo', 'IsRelative=1', 'Path=foo', '', '[Profile1]', 'Name=bar', 'IsRelative=1', 'Path=bar', '', '[Profile2]', 'Name=baz', 'IsRelative=1', 'Path=baz', 'Default=1', ])) for p in ['foo', 'bar', 'baz']: os.mkdir(self.p(p)) os.mkdir(self.p(p, 'dummydir')) with open(self.p(p, 'dummy1'), 'a'): pass now = int(time.time()) t_foo = now - 10 t_bar = now - 5 t_baz = now - 7 os.utime(self.p('foo', 'dummy1'), (t_foo, t_foo)) os.utime(self.p('bar', 'dummy1'), (t_bar, t_bar)) os.utime(self.p('baz', 'dummy1'), (t_baz, t_baz)) profiles = auth.get_profiles(self.tmpdir) names = [p['name'] for p in profiles] self.assertEqual(names, ['baz', 'bar', 'foo'])
def test_get_profiles_empty(self): """If we point at a directory without a profiles.ini, we get nothing.""" profiles = auth.get_profiles(self.tmpdir) self.assertEqual(profiles, [])