def setUp(self): super(TestStoreObjectApi, self).setUp() self.useFixture( func_helpers.SqlOrganization( self.engine, uuid=mocks.UUID1, name=helpers.utf8_bytes('my org'), slug=helpers.utf8_bytes('my-org'), parent_organization_uuid=None, root_organization_uuid=mocks.UUID1, created_on=mocks.CREATED_ON, generation=1, left_sequence=1, right_sequence=2, )) self.useFixture( func_helpers.SqlOrganization( self.engine, uuid=mocks.UUID2, name=helpers.utf8_bytes('my other org'), slug=helpers.utf8_bytes('my-other-org'), parent_organization_uuid=None, root_organization_uuid=mocks.UUID2, created_on=mocks.CREATED_ON, generation=1, left_sequence=1, right_sequence=2, ))
def test_many_all(self): search_spec = search.SearchSpec(self.ctx) r = organization.many(self.engine.connect(), search_spec) uuid1_no_dash = mocks.UUID1.replace('-', '') uuid2_no_dash = mocks.UUID2.replace('-', '') expected = [ # Note that mocks.UUID2 is alphabetically first and therefore # without specifying any sort order, the default for organizations # is created_on DESC, uuid ASC { 'uuid': uuid2_no_dash, 'name': helpers.utf8_bytes('my other org'), 'slug': helpers.utf8_bytes('my-other-org'), 'root_organization_uuid': uuid2_no_dash, 'parent_organization_uuid': None, 'created_on': mocks.CREATED_ON_NAIVE, 'generation': 1, 'left_sequence': 1, 'right_sequence': 2, }, { 'uuid': uuid1_no_dash, 'name': helpers.utf8_bytes('my org'), 'slug': helpers.utf8_bytes('my-org'), 'root_organization_uuid': uuid1_no_dash, 'parent_organization_uuid': None, 'created_on': mocks.CREATED_ON_NAIVE, 'generation': 1, 'left_sequence': 1, 'right_sequence': 2, }, ] self.assertEqual(expected, r)
def test_utf8_bytes_success_py3k(self): vals = [ (six.binary_type("The quick brown fox"), six.text_type("The quick brown fox")), (six.text_type("The quick brown fox").encode("utf-8"), six.text_type("The quick brown fox")), (six.text_type("The quick brown fox").encode("ascii"), six.text_type("The quick brown fox")), ] for v, coerced in vals: self.assertEqual(coerced, helpers.utf8_bytes(v))
def to_storage(self, subject): if subject is None: return None res = helpers.utf8_bytes(subject) if not EmailAddress.RE_EMAIL.match(res): msg = "Not a valid email address: {0}" msg = msg.format(subject) raise TypeError(msg) return res.lower()
def test_one_by_name(self): filters = { 'name': helpers.utf8_bytes('my org'), } search_spec = search.SearchSpec(self.ctx, filters=filters) r = organization.one(self.engine.connect(), search_spec) uuid_no_dash = mocks.UUID1.replace('-', '') expected = { 'uuid': uuid_no_dash, 'name': helpers.utf8_bytes('my org'), 'slug': helpers.utf8_bytes('my-org'), 'root_organization_uuid': uuid_no_dash, 'parent_organization_uuid': None, 'created_on': mocks.CREATED_ON_NAIVE, 'generation': 1, 'left_sequence': 1, 'right_sequence': 2, } self.assertEqual(expected, r)