Beispiel #1
0
    def test_hash_is_calculated_from_components(self):
        random_key = generate_random_string()
        random_context = generate_random_string()
        random_string = "hello world"
        random_hash = hash((random_key, random_context, random_string))

        open_string = OpenString(random_key, '')
        open_string.context = random_context
        open_string._strings[5] = random_string

        self.assertEqual(hash(open_string), random_hash)
Beispiel #2
0
    def test_hash_is_calculated_from_components(self):
        random_key = generate_random_string()
        random_context = generate_random_string()
        random_string = "hello world"
        random_hash = hash((random_key, random_context, random_string))

        open_string = OpenString(random_key, '')
        open_string.context = random_context
        open_string._strings[5] = random_string

        self.assertEqual(hash(open_string), random_hash)
Beispiel #3
0
    def test_context_is_hashed_when_present(self):
        random_context = generate_random_string()
        random_key = generate_random_string()
        random_hash = md5(':'.join([random_key, random_context
                                    ]).encode('utf-8')).hexdigest()

        open_string = OpenString(random_key, 'test')
        open_string.context = random_context

        replacement = open_string.template_replacement
        hash_string = replacement.split('_')[0]

        self.assertEqual(hash_string, random_hash)
Beispiel #4
0
    def test_context_is_hashed_when_present(self):
        random_context = generate_random_string()
        random_key = generate_random_string()
        random_hash = md5(
            ':'.join([random_key, random_context]).encode('utf-8')
        ).hexdigest()

        open_string = OpenString(random_key, 'test')
        open_string.context = random_context

        replacement = open_string.template_replacement
        hash_string = replacement.split('_')[0]

        self.assertEqual(hash_string, random_hash)