Example #1
0
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('client', sa.Column('namespace', sa.Unicode(length=250), nullable=True))
    op.create_unique_constraint('client_namespace_key', 'client', ['namespace'])
    ### end Alembic commands ###

    connection = op.get_bind()
    client = table('client',
        column('id', sa.Integer),
        column('website', sa.Unicode(250)),
        column('namespace', sa.Unicode(250)))
    results = connection.execute(select([client.c.id, client.c.website]))
    namespaces = []
    namespace_list = []
    for r in results:
        new_namespace = namespace = namespace_from_url(r[1])
        append_count = 0
        while new_namespace in namespace_list:
            append_count = append_count + 1
            new_namespace = "%s%s" % (namespace, append_count)
        namespaces.append({'clientid': r[0], 'namespace': new_namespace})
        namespace_list.append(new_namespace)

    if len(namespaces) > 0:
        updt_stmt = client.update().where(client.c.id == bindparam('clientid')).values(namespace=bindparam('namespace'))
        connection.execute(updt_stmt, namespaces)
Example #2
0
 def test_namespace_from_url(self):
     self.assertEqual(namespace_from_url(u'https://github.com/hasgeek/coaster'), u'com.github')
     self.assertEqual(namespace_from_url(u'https://funnel.hasgeek.com/metarefresh2014/938-making-design-decisions'),
         u'com.hasgeek.funnel')
     self.assertEqual(namespace_from_url(u'http://www.hasgeek.com'), u'com.hasgeek')
     self.assertEqual(namespace_from_url(u'www.hasgeek.com'), None)
     self.assertEqual(namespace_from_url(u'This is an invalid url'), None)
     # IP addresses are rejected
     self.assertEqual(namespace_from_url('127.0.0.1'), None)
     # Return string type is the input type
     self.assertTrue(isinstance(namespace_from_url(u'https://github.com/hasgeek/coaster'), six.text_type))
     self.assertTrue(isinstance(namespace_from_url('https://github.com/hasgeek/coaster'), str))
Example #3
0
 def test_namespace_from_url(self):
     self.assertEqual(namespace_from_url(u'https://github.com/hasgeek/coaster'), u'com.github')
     self.assertEqual(namespace_from_url(u'https://funnel.hasgeek.com/metarefresh2014/938-making-design-decisions'),
         u'com.hasgeek.funnel')
     self.assertEqual(namespace_from_url(u'http://www.hasgeek.com'), u'com.hasgeek')
     self.assertEqual(namespace_from_url(u'www.hasgeek.com'), None)
     self.assertEqual(namespace_from_url(u'This is an invalid url'), None)
     # IP addresses are rejected
     self.assertEqual(namespace_from_url('127.0.0.1'), None)
     # Return string type is the input type
     self.assertTrue(isinstance(namespace_from_url(u'https://github.com/hasgeek/coaster'), unicode))
     self.assertTrue(isinstance(namespace_from_url('https://github.com/hasgeek/coaster'), str))
Example #4
0
 def test_namespace_from_url(self):
     assert (namespace_from_url(u'https://github.com/hasgeek/coaster') ==
             u'com.github')
     assert (namespace_from_url(
         u'https://funnel.hasgeek.com/metarefresh2014/938-making-design-decisions'
     ) == u'com.hasgeek.funnel')
     assert namespace_from_url(u'http://www.hasgeek.com') == u'com.hasgeek'
     assert namespace_from_url(u'www.hasgeek.com') is None
     assert namespace_from_url(u'This is an invalid url') is None
     # IP addresses are rejected
     assert namespace_from_url('127.0.0.1') is None
     # Return string type is the input type
     assert isinstance(
         namespace_from_url(u'https://github.com/hasgeek/coaster'),
         six.text_type)
     assert isinstance(
         namespace_from_url('https://github.com/hasgeek/coaster'), str)