Пример #1
0
class TestEncryption(unittest.TestCase):
    # pylint: disable=R0904
    def setUp(self):    # pylint: disable=C0103
        self.crypt = Encryption()

    def tearDown(self):    # pylint: disable=C0103
        pass

    def test_make_salt(self):
        salt1 = self.crypt.make_salt()
        salt2 = self.crypt.make_salt()

        self.assertNotEqual(salt1, salt2)

    def test_cookie_hash(self):
        user_id = 1
        user_id_hash = self.crypt.make_user_id_hash(user_id)
        self.assertTrue(self.crypt.is_valid_cookie(user_id, user_id_hash))

    def test_password_hash(self):
        username = '******'
        password = '******'
        hash_and_salt = self.crypt.make_password_hash(username, password)
        self.assertTrue(self.crypt.is_valid_password(username, password,
            hash_and_salt))
Пример #2
0
 def setUp(self):    # pylint: disable=C0103
     self.crypt = Encryption()
     self.data_handler = UserDataHandler()
     # First, create an instance of the Testbed class.
     self.testbed = testbed.Testbed()
     # Then activate the testbed, which prepares the service stubs for use.
     self.testbed.activate()
     # Next, declare which service stubs you want to use.
     self.testbed.init_datastore_v3_stub()
     self.testbed.init_memcache_stub()
Пример #3
0
    def test_page_entry_get_and_put(self):
        data = {}
        data['username'] = '******'
        data['password'] = '******'
        data['email'] = '*****@*****.**'
        page_entry_id = self.data_handler.put(data['username'],
        data['password'], data['email'])

        actual = self.data_handler.get_by_id(page_entry_id)
        expected = data

        self.assertTrue(Encryption.is_valid_password(expected['username'],
            expected['password'], actual.password))
Пример #4
0
    def test_get_all_page_entries(self):
        actual_input = {}
        actual_input['username'] = '******'
        actual_input['password'] = '******'
        actual_input['email'] = '*****@*****.**'

        self.data_handler.put(actual_input['username'],
        actual_input['password'], actual_input['email'])
        self.data_handler.put(actual_input['username'],
        actual_input['password'], actual_input['email'])

        actual = self.data_handler.get_all()

        # Might not be the best way to do this but everything needs to be equal
        # to validate...
        for item in actual:
            self.assertTrue(Encryption.is_valid_password(actual_input['username'],
                    actual_input['password'], item.password))
Пример #5
0
 def setUp(self):    # pylint: disable=C0103
     self.crypt = Encryption()
Пример #6
0
class TestUserDataHandler(unittest.TestCase):
    # pylint: disable=R0904
    def setUp(self):    # pylint: disable=C0103
        self.crypt = Encryption()
        self.data_handler = UserDataHandler()
        # First, create an instance of the Testbed class.
        self.testbed = testbed.Testbed()
        # Then activate the testbed, which prepares the service stubs for use.
        self.testbed.activate()
        # Next, declare which service stubs you want to use.
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()

    def tearDown(self):    # pylint: disable=C0103
        self.testbed.deactivate

    def test_page_entry_get_and_put(self):
        data = {}
        data['username'] = '******'
        data['password'] = '******'
        data['email'] = '*****@*****.**'
        page_entry_id = self.data_handler.put(data['username'],
        data['password'], data['email'])

        actual = self.data_handler.get_by_id(page_entry_id)
        expected = data

        self.assertTrue(Encryption.is_valid_password(expected['username'],
            expected['password'], actual.password))

    def test_get_all_page_entries(self):
        actual_input = {}
        actual_input['username'] = '******'
        actual_input['password'] = '******'
        actual_input['email'] = '*****@*****.**'

        self.data_handler.put(actual_input['username'],
        actual_input['password'], actual_input['email'])
        self.data_handler.put(actual_input['username'],
        actual_input['password'], actual_input['email'])

        actual = self.data_handler.get_all()

        # Might not be the best way to do this but everything needs to be equal
        # to validate...
        for item in actual:
            self.assertTrue(Encryption.is_valid_password(actual_input['username'],
                    actual_input['password'], item.password))

    def test_get_by_username(self):
        actual_input = {}
        actual_input['username'] = '******'
        actual_input['password'] = '******'
        actual_input['email'] = '*****@*****.**'

        self.data_handler.put(actual_input['username'],
        actual_input['password'], actual_input['email'])

        user = self.data_handler.get_by_username(actual_input['username'])
        self.assertTrue(self.crypt.is_valid_password(actual_input['username'],
            actual_input['password'], user.password))
        self.assertEqual(actual_input['email'], user.email)