Explorar o código

Do not allow underscores in names

Ben Firshman %!s(int64=12) %!d(string=hai) anos
pai
achega
6c551a200b
Modificáronse 2 ficheiros con 6 adicións e 6 borrados
  1. 1 1
      plum/service.py
  2. 5 5
      tests/service_test.py

+ 1 - 1
plum/service.py

@@ -13,7 +13,7 @@ class BuildError(Exception):
 
 class Service(object):
     def __init__(self, name, client=None, links=[], **options):
-        if not re.match('^[a-zA-Z0-9_]+$', name):
+        if not re.match('^[a-zA-Z0-9]+$', name):
             raise ValueError('Invalid name: %s' % name)
         if 'image' in options and 'build' in options:
             raise ValueError('Service %s has both an image and build path specified. A service can either be built to image or use an existing image, not both.' % name)

+ 5 - 5
tests/service_test.py

@@ -10,13 +10,13 @@ class ServiceTest(DockerClientTestCase):
         self.assertRaises(ValueError, lambda: Service(name='/'))
         self.assertRaises(ValueError, lambda: Service(name='!'))
         self.assertRaises(ValueError, lambda: Service(name='\xe2'))
+        self.assertRaises(ValueError, lambda: Service(name='_'))
+        self.assertRaises(ValueError, lambda: Service(name='____'))
+        self.assertRaises(ValueError, lambda: Service(name='foo_bar'))
+        self.assertRaises(ValueError, lambda: Service(name='__foo_bar__'))
 
         Service('a')
         Service('foo')
-        Service('foo_bar')
-        Service('__foo_bar__')
-        Service('_')
-        Service('_____')
 
     def test_containers(self):
         foo = self.create_service('foo')
@@ -38,7 +38,7 @@ class ServiceTest(DockerClientTestCase):
         self.assertIn('/bar_2', names)
 
     def test_up_scale_down(self):
-        service = self.create_service('scaling_test')
+        service = self.create_service('scalingtest')
         self.assertEqual(len(service.containers()), 0)
 
         service.start()