Example #1
0
    def test_get_scope_and_code_with_default_scope(self):
        id_generator = IdGenerator()
        entity, scope, code = id_generator.generate_scope_and_code("portfolio")

        val = next(id_generator.pop_scope_and_codes(), None)

        self.assertEqual(scope, val[1])
        self.assertEqual(scope, id_generator.default_scope)

        val = next(id_generator.pop_scope_and_codes(), None)
        self.assertIsNone(val)
Example #2
0
    def test_get_scope_and_code_with_specified_scope(self):
        test_scope = "test-scope"
        id_generator = IdGenerator(test_scope)
        entity, scope, code = id_generator.generate_scope_and_code("portfolio")

        val = next(id_generator.pop_scope_and_codes(), None)

        self.assertEqual(scope, val[1])
        self.assertEqual(scope, test_scope)

        val = next(id_generator.pop_scope_and_codes(), None)
        self.assertIsNone(val)
Example #3
0
    def test_add_existing_scope_and_code(self):
        id_generator = IdGenerator()
        _, gen_scope, gen_code = id_generator.generate_scope_and_code(
            "portfolio")

        id_generator.add_scope_and_code("portfolio", gen_scope, gen_code)

        gen_vals = set(id_generator.pop_scope_and_codes())
        self.assertEqual(1, len(gen_vals))
Example #4
0
    def test_clear_scope_and_code(self):
        id_generator = IdGenerator()
        id_generator.generate_scope_and_code("portfolio")

        vals = id_generator.pop_scope_and_codes()
        self.assertEqual(1, len(list(vals)))

        id_generator.clear()

        self.assertEqual(0, len(list(vals)))
Example #5
0
    def test_add_scope_and_code_with_specified_scope(self):
        test_scope = "test-scope"
        id_generator = IdGenerator()
        code = str(uuid.uuid4())
        id_generator.add_scope_and_code("portfolio", test_scope, code)

        val = next(id_generator.pop_scope_and_codes(), None)

        self.assertEqual(test_scope, val[1])
        self.assertEqual(code, val[2])
Example #6
0
    def test_add_scope_and_code(self):
        id_generator = IdGenerator()
        code = str(uuid.uuid4())
        id_generator.add_scope_and_code("portfolio", IdGenerator.default_scope,
                                        code)

        val = next(id_generator.pop_scope_and_codes(), None)

        self.assertEqual(IdGenerator.default_scope, val[1])
        self.assertEqual(code, val[2])
Example #7
0
    def test_get_multiple_scope_and_codes(self):
        id_generator = IdGenerator()
        n = 5

        vals = {
            id_generator.generate_scope_and_code("portfolio")
            for _ in range(n)
        }

        gen_vals = set(id_generator.pop_scope_and_codes())
        self.assertEqual(n, len(gen_vals))
        self.assertSetEqual(vals, gen_vals)
Example #8
0
    def test_generate_scope_and_code_with_different_entity(self):
        id_generator = IdGenerator()
        entity1, scope1, code1 = id_generator.generate_scope_and_code(
            "portfolio")

        entity2, scope2, code2 = id_generator.generate_scope_and_code(
            "property")

        vals = set(id_generator.pop_scope_and_codes())

        self.assertEqual(2, len(vals))
        self.assertIn((entity1, scope1, code1), vals)
        self.assertIn((entity2, scope2, code2), vals)