Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure project name from the config file #463

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions fig/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,19 @@ def from_dicts(cls, name, service_dicts, client):

@classmethod
def from_config(cls, name, config, client):
dicts = []
services = []
project_config = config.pop('project-config', {})
name = project_config.get('name', name)

for service_name, service in list(config.items()):
if not isinstance(service, dict):
raise ConfigurationError('Service "%s" doesn\'t have any configuration options. All top level keys in your fig.yml must map to a dictionary of configuration options.')
raise ConfigurationError(
'Service "%s" doesn\'t have any configuration options. '
'All top level keys in your fig.yml must map to a '
'dictionary of configuration options.')
service['name'] = service_name
dicts.append(service)
return cls.from_dicts(name, dicts, client)
services.append(service)
return cls.from_dicts(name, services, client)

def get_service(self, name):
"""
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/project_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from fig.service import Service
from fig.project import Project, ConfigurationError


class ProjectTest(unittest.TestCase):
def test_from_dict(self):
project = Project.from_dicts('figtest', [
Expand Down Expand Up @@ -65,6 +66,15 @@ def test_from_config_throws_error_when_not_dict(self):
'web': 'busybox:latest',
}, None)

def test_from_config_with_project_config(self):
project_name = 'theprojectnamefromconfig'
project = Project.from_config('default_name_not_used', {
'project-config': {'name': project_name},
'web': {'image': 'busybox:latest'}
}, None)

self.assertEqual(project.name, project_name)

def test_get_service(self):
web = Service(
project='figtest',
Expand Down