~ubuntu-branches/ubuntu/vivid/keystone/vivid

« back to all changes in this revision

Viewing changes to keystone/tests/test_utils.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-10-02 11:46:14 UTC
  • mfrom: (1.1.37)
  • Revision ID: package-import@ubuntu.com-20131002114614-pw4xkjdvowr9u34w
Tags: 1:2013.2~rc1-0ubuntu1
* New upstream version.
* debian/control:
  - Add versioned dependencies to python-pbr, python-dogpile.cache,
    python-oslo.config, python-webob, python-pam, python-sqlalchemy,
    python-testtools, and python-requests.
  - Added python-greenlet, python-requests, python-netifaces,
    and python-setuptools as a build dependency.
  - Dropped python-swift, python-unittest, python-d2to1,
    as a build dependency.
  - Bumped versioned depends for python-keystoneclient.
* debian/patches/disable-oauth2.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
2
 
3
 
# Copyright 2012 OpenStack LLC
 
3
# Copyright 2012 OpenStack Foundation
4
4
#
5
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
6
# not use this file except in compliance with the License. You may obtain
29
29
#    License for the specific language governing permissions and limitations
30
30
#    under the License.
31
31
 
32
 
from keystone.tests import core as test
 
32
import datetime
 
33
import functools
 
34
import os
 
35
import time
33
36
 
34
37
from keystone.common import utils
35
 
 
36
 
 
37
 
class UtilsTestCase(test.TestCase):
 
38
from keystone import tests
 
39
 
 
40
 
 
41
TZ = None
 
42
 
 
43
 
 
44
def timezone(func):
 
45
    @functools.wraps(func)
 
46
    def wrapper(*args, **kwargs):
 
47
        tz_original = os.environ.get('TZ')
 
48
        try:
 
49
            if TZ:
 
50
                os.environ['TZ'] = TZ
 
51
                time.tzset()
 
52
            return func(*args, **kwargs)
 
53
        finally:
 
54
            if TZ:
 
55
                if tz_original:
 
56
                    os.environ['TZ'] = tz_original
 
57
                else:
 
58
                    if 'TZ' in os.environ:
 
59
                        del os.environ['TZ']
 
60
                time.tzset()
 
61
    return wrapper
 
62
 
 
63
 
 
64
class UtilsTestCase(tests.TestCase):
38
65
    def test_hash(self):
39
66
        password = 'right'
40
67
        wrong = 'wrongwrong'  # Two wrongs don't make a right
64
91
        self.assertFalse(utils.auth_str_equal('a', 'aaaaa'))
65
92
        self.assertFalse(utils.auth_str_equal('aaaaa', 'a'))
66
93
        self.assertFalse(utils.auth_str_equal('ABC123', 'abc123'))
 
94
 
 
95
    def test_unixtime(self):
 
96
        global TZ
 
97
 
 
98
        @timezone
 
99
        def _test_unixtime():
 
100
            epoch = utils.unixtime(dt)
 
101
            self.assertEquals(epoch, epoch_ans, "TZ=%s" % TZ)
 
102
 
 
103
        dt = datetime.datetime(1970, 1, 2, 3, 4, 56, 0)
 
104
        epoch_ans = 56 + 4 * 60 + 3 * 3600 + 86400
 
105
        for d in ['+0', '-11', '-8', '-5', '+5', '+8', '+14']:
 
106
            TZ = 'UTC' + d
 
107
            _test_unixtime()