예제 #1
0
def test_get_item_from_thousand(benchmark):
    permissions = Const()
    for i in range(1000):
        permissions.add(rand_text(max_length=6))

    @benchmark
    def get_permission():
        permissions[888]
예제 #2
0
def test_add_one_time_big_text(benchmark):
    permissions = Const()
    text = rand_text(max_length=1000)

    @benchmark
    def add_one_with_six_digits():
        permissions.add(text)
예제 #3
0
    def test_set_const_with_tuple_four_values(self):
        const = Const(
            ('Label Test', 'Attr test', 'Value test', 'Ignore Value'),
            ('Label Test2', 'Attr test2', 'Value test2', 'Ignore Value'),
        )

        self.assertEqual(const[0], ('VALUE_TEST', u'Label Test'))
        self.assertEqual(const.attr_test, 'VALUE_TEST')
예제 #4
0
    def test_get_value(self):
        const = Const(
            'Add User',
            'Create User',
            'Delete User',
        )

        self.assertEqual(const.add_user.label, 'Add User')
예제 #5
0
    def test_get_multiple_value_in_order(self):
        const = Const(
            ('Add User', 'add_user'),
            ('Create User', 'create_user'),
            ('Delete User', 'delete_user'),
        )

        self.assertEqual(const[0], ('ADD_USER', u'Add User'))
예제 #6
0
    def test_get_value_in_order(self):
        const = Const(
            'Add User',
            'Create User',
            'Delete User',
        )

        self.assertEqual(const[0], ('ADD_USER', u'Add User'))
예제 #7
0
    def test_set_init_values(self):
        const = Const(
            'add user',
            'create user',
            'delete user',
        )

        self.assertEqual(const.add_user, 'ADD_USER')
        self.assertEqual(len(const), 3)
예제 #8
0
 def add_hundred_with_six_digits():
     permissions = Const()
     for i in range(100):
         permissions.add(texts[i])
예제 #9
0
 def add_thousand_with_six_digits():
     permissions = Const()
     for i in range(1000):
         permissions.add(texts[i])
예제 #10
0
 def test_set_different_attribute_and_value(self):
     const = Const()
     const.add(label='First item', attr="my_item", value=1)
     self.assertEqual(const[0], ('1', u'First item'))
     self.assertEqual(const.my_item, '1')
예제 #11
0
 def test_number_attr(self):
     const = Const()
     const.add('First item', 1)
     self.assertEqual(const[0], ('1', u'First item'))
     self.assertEqual(const._1, '1')
예제 #12
0
 def setUp(self):
     self.const = Const()
예제 #13
0
 def test_get_multiple_kwargs_value_in_order(self):
     const = Const(**{'Add User': '******'})
     self.assertEqual(const[0], ('ADD_USER', u'Add User'))
예제 #14
0
class TestConsts(unittest.TestCase):
    def setUp(self):
        self.const = Const()

    def test_slugify(self):
        self.const.add('caça vovó')
        self.assertEqual(self.const.caca_vovo, 'CACA_VOVO')

    def test_add_item(self):
        self.const.add('update item')
        self.assertEqual(self.const.update_item, 'UPDATE_ITEM')

    def test_inter_pyconst(self):
        self.const.add('update item')
        for value in self.const:
            self.assertEqual(value, ('UPDATE_ITEM', 'update item'))

    def test_set_init_values(self):
        const = Const(
            'add user',
            'create user',
            'delete user',
        )

        self.assertEqual(const.add_user, 'ADD_USER')
        self.assertEqual(len(const), 3)

    def test_get_value(self):
        const = Const(
            'Add User',
            'Create User',
            'Delete User',
        )

        self.assertEqual(const.add_user.label, 'Add User')

    def test_slug_stranger_characteres(self):
        const = Const('Add - User', )
        self.assertEqual(const.add_user, 'ADD_USER')

    def test_add_attribute(self):
        self.const.add('Update item (new)', 'update_item')
        self.assertEqual(self.const.update_item, 'UPDATE_ITEM')
        self.assertEqual(self.const.update_item.label, 'Update item (new)')

    def test_get_value_in_order(self):
        const = Const(
            'Add User',
            'Create User',
            'Delete User',
        )

        self.assertEqual(const[0], ('ADD_USER', u'Add User'))

    def test_get_multiple_value_in_order(self):
        const = Const(
            ('Add User', 'add_user'),
            ('Create User', 'create_user'),
            ('Delete User', 'delete_user'),
        )

        self.assertEqual(const[0], ('ADD_USER', u'Add User'))

    def test_get_multiple_kwargs_value_in_order(self):
        const = Const(**{'Add User': '******'})
        self.assertEqual(const[0], ('ADD_USER', u'Add User'))

    def test_slug_index_error(self):
        const = Const()
        const.add(['Add User'])
        self.assertEqual(const[0], ('ADD_USER', u'Add User'))

    def test_number_attr(self):
        const = Const()
        const.add('First item', 1)
        self.assertEqual(const[0], ('1', u'First item'))
        self.assertEqual(const._1, '1')

    def test_set_different_attribute_and_value(self):
        const = Const()
        const.add(label='First item', attr="my_item", value=1)
        self.assertEqual(const[0], ('1', u'First item'))
        self.assertEqual(const.my_item, '1')

    def test_set_const_with_tuple_three_values(self):
        const = Const(
            ('Label Test', 'Attr test', 'Value test'),
            ('Label Test2', 'Attr test2', 'Value test2'),
        )

        self.assertEqual(const[0], ('VALUE_TEST', u'Label Test'))
        self.assertEqual(const.attr_test, 'VALUE_TEST')

    def test_set_const_with_tuple_four_values(self):
        const = Const(
            ('Label Test', 'Attr test', 'Value test', 'Ignore Value'),
            ('Label Test2', 'Attr test2', 'Value test2', 'Ignore Value'),
        )

        self.assertEqual(const[0], ('VALUE_TEST', u'Label Test'))
        self.assertEqual(const.attr_test, 'VALUE_TEST')
예제 #15
0
 def test_slug_stranger_characteres(self):
     const = Const('Add - User', )
     self.assertEqual(const.add_user, 'ADD_USER')
예제 #16
0
from pyconst import Const

ASSET_TYPES = Const(
    (u'Article', 'ARTICLE', 1),
    (u'Video', 'VIDEO', 2),
    (u'Twitter', 'TWITTER', 3),
    (u'Instagram', 'INSTAGRAM', 4),
    (u'Facebook', 'FACEBOOK', 4),
)

OEMBED_ENDPOINTS = [
    {
        "name":
        "Facebook Post",
        "templates": [
            "(?:www|m|business)\\.facebook\\.com/",
            "(permalink|story)\\.php\\?[^/]+(\\d{10,})",
            "(?:www|m|business)\\.facebook\\.com/"
            "photo\\.php\\?[^/]+(\\d{10,})",
            "(?:www|m|business)\\.facebook\\.com/"
            "([a-zA-Z0-9\\.\\-]+)/(posts|activity)/(\\d{10,})",
            "(?:www|m|business)\\.facebook\\.com/"
            "([a-zA-Z0-9\\.\\-]+)/photos/[^\\/]+/(\\d{10,})",
            "(?:www|m|business)\\.facebook\\.com/notes/"
            "([a-zA-Z0-9\\.\\-]+)/[^/]+/(\\d{10,})",
            "(?:www|m|business)\\.facebook\\.com/media/set/"
            "\\?set=[^/]+(\\d{10,})"
        ],
        "endpoint":
        "https://www.facebook.com/plugins/post/oembed.json/"
    },
예제 #17
0
 def test_slug_index_error(self):
     const = Const()
     const.add(['Add User'])
     self.assertEqual(const[0], ('ADD_USER', u'Add User'))