Example #1
0
    def test_first_data_upload(self, cintf):
        """App code for a held service is provided via upload.
        """
        deployment = cintf.create_deployment('foo')
        cintf.set_globals('foo', {'a': 1})
        service = deployment.set_service('bar')
        service.hold(
            'bla',
            service.derive(canonical_definition('bar', {'git': '.'})[1]))

        cintf.provide_data('foo', 'bar', {'app': FileStorage()},
                           {'app': {
                               'version': 42
                           }})

        # docker build was called
        assert len(subprocess.Popen.mock_calls) == 1
        assert 'http://shelf' in subprocess.Popen.mock_calls[0][1][0]
        # Service no longer held
        assert not service.held
        assert not service.held_version  # was cleared
        # A new version was created in the db
        assert len(service.versions) == 1
        assert service.versions[0].definition == canonical_definition(
            'bar', {'git': '.'})[1]
        assert service.versions[0].globals == {'a': 1}
        assert service.versions[0].data['app_version_id'] == 42
        # Also created via the backend.
        assert len(cintf.backend.start.mock_calls) == 1
    def test_new_version_via_config_change(self, cintf):
        """Changing the service definition creates a new version
        """
        deployment = cintf.create_deployment('foo')
        cintf.set_globals('foo', {'a': 1})
        service = deployment.set_service('bar')
        version = service.append_version(
            service.derive(canonical_definition('bar', {'git': '.'})[1]))
        version.data['app_version_id'] = 3

        service = cintf.set_service('foo', 'bar', {'git': '.', 'foo': 1})

        # No slug was built
        assert len(subprocess.Popen.mock_calls) == 0
        # But the new one was deployed as a new version
        assert len(service.versions) == 2
        assert service.versions[1].definition == \
               canonical_definition('bar', {'git': '.', 'foo': 1})[1]
        assert service.versions[1].globals ==service.versions[0].globals
        assert service.versions[1].data['app_version_id'] == service.versions[0].data['app_version_id']
Example #3
0
    def test_new_version_via_config_change(self, cintf):
        """Changing the service definition creates a new version
        """
        deployment = cintf.create_deployment('foo')
        cintf.set_globals('foo', {'a': 1})
        service = deployment.set_service('bar')
        version = service.append_version(
            service.derive(canonical_definition('bar', {'git': '.'})[1]))
        version.data['app_version_id'] = 3

        service = cintf.set_service('foo', 'bar', {'git': '.', 'foo': 1})

        # No slug was built
        assert len(subprocess.Popen.mock_calls) == 0
        # But the new one was deployed as a new version
        assert len(service.versions) == 2
        assert service.versions[1].definition == \
               canonical_definition('bar', {'git': '.', 'foo': 1})[1]
        assert service.versions[1].globals == service.versions[0].globals
        assert service.versions[1].data['app_version_id'] == service.versions[
            0].data['app_version_id']
    def test_first_data_upload(self, cintf):
        """App code for a held service is provided via upload.
        """
        deployment = cintf.create_deployment('foo')
        cintf.set_globals('foo', {'a': 1})
        service = deployment.set_service('bar')
        service.hold('bla', service.derive(canonical_definition('bar', {'git': '.'})[1]))

        cintf.provide_data(
            'foo', 'bar',  {'app': FileStorage()}, {'app': {'version': 42}})

        # docker build was called
        assert len(subprocess.Popen.mock_calls) == 1
        assert 'http://shelf' in subprocess.Popen.mock_calls[0][1][0]
        # Service no longer held
        assert not service.held
        assert not service.held_version   # was cleared
        # A new version was created in the db
        assert len(service.versions) == 1
        assert service.versions[0].definition == canonical_definition('bar', {'git': '.'})[1]
        assert service.versions[0].globals == {'a': 1}
        assert service.versions[0].data['app_version_id'] == 42
        # Also created via the backend.
        assert len(cintf.backend.start.mock_calls) == 1
    def test_subsequent_data_upload(self, cintf):
        """Uploading a new piece of data creates new version.
        """
        deployment = cintf.create_deployment('foo')
        cintf.set_globals('foo', {'a': 1})
        service = deployment.set_service('bar')
        version = service.append_version(
            service.derive(canonical_definition('bar', {'git': '.'})[1]))
        version.data['app_version_id'] = 3

        cintf.provide_data(
            'foo', 'bar',  {'app': FileStorage()}, {'app': {'version': 99}})

        # Another slug was built
        assert len(subprocess.Popen.mock_calls) == 1
        assert 'http://shelf' in subprocess.Popen.mock_calls[0][1][0]
        # And deployed as a new version
        assert len(service.versions) == 2
        assert service.versions[0].definition ==service.versions[1].definition
        assert service.versions[0].globals ==service.versions[1].globals
        assert service.versions[1].data['app_version_id'] == 99
Example #6
0
    def test_subsequent_data_upload(self, cintf):
        """Uploading a new piece of data creates new version.
        """
        deployment = cintf.create_deployment('foo')
        cintf.set_globals('foo', {'a': 1})
        service = deployment.set_service('bar')
        version = service.append_version(
            service.derive(canonical_definition('bar', {'git': '.'})[1]))
        version.data['app_version_id'] = 3

        cintf.provide_data('foo', 'bar', {'app': FileStorage()},
                           {'app': {
                               'version': 99
                           }})

        # Another slug was built
        assert len(subprocess.Popen.mock_calls) == 1
        assert 'http://shelf' in subprocess.Popen.mock_calls[0][1][0]
        # And deployed as a new version
        assert len(service.versions) == 2
        assert service.versions[0].definition == service.versions[1].definition
        assert service.versions[0].globals == service.versions[1].globals
        assert service.versions[1].data['app_version_id'] == 99
Example #7
0
 def test_deep_copy(self):
     """The service definition dict, when copied, is always a deepcopy."""
     _, d = canonical_definition('foo', {'env': {'FOO': 1}})
     d2 = d.copy()
     d['env']['NEW'] = 42
     assert not 'NEW' in d2['env']
Example #8
0
 def test_with_image_key(self):
     # [Regression] image key is accepted as a regular, not an extra key
     _, d = canonical_definition('foo', {'image': 'bar'})
     assert not d['kwargs']
Example #9
0
 def test_deep_copy(self):
     """The service definition dict, when copied, is always a deepcopy."""
     _, d = canonical_definition('foo', {'env': {'FOO': 1}})
     d2 = d.copy()
     d['env']['NEW'] = 42
     assert not 'NEW' in d2['env']
Example #10
0
 def test_with_image_key(self):
     # [Regression] image key is accepted as a regular, not an extra key
     _, d = canonical_definition('foo', {'image': 'bar'})
     assert not d['kwargs']