diff --git a/syncano/__init__.py b/syncano/__init__.py index 77b9198..4b36939 100644 --- a/syncano/__init__.py +++ b/syncano/__init__.py @@ -2,7 +2,7 @@ import os __title__ = 'Syncano Python' -__version__ = '5.4.4' +__version__ = '5.4.5' __author__ = "Daniel Kopka, Michal Kobus and Sebastian Opalczynski" __credits__ = ["Daniel Kopka", "Michal Kobus", diff --git a/syncano/models/base.py b/syncano/models/base.py index 015217b..2f4eeeb 100644 --- a/syncano/models/base.py +++ b/syncano/models/base.py @@ -11,7 +11,7 @@ from .push_notification import * # NOQA from .geo import * # NOQA from .backups import * # NOQA -from .hosting import * # NOQA +from .hosting import Hosting, HostingFile # NOQA from .data_views import DataEndpoint as EndpointData # NOQA from .custom_sockets import * # NOQA from .custom_sockets_utils import Endpoint, ScriptCall, ScriptDependency, ClassDependency # NOQA diff --git a/syncano/models/hosting.py b/syncano/models/hosting.py index ab80819..48b95e4 100644 --- a/syncano/models/hosting.py +++ b/syncano/models/hosting.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- from . import fields -from .base import Instance, Model, logger +from .base import Model +from .instances import Instance class Hosting(Model): @@ -9,11 +10,12 @@ class Hosting(Model): OO wrapper around hosting. """ - label = fields.StringField(max_length=64, primary_key=True) + name = fields.StringField(max_length=253) + is_default = fields.BooleanField(read_only=True) + is_active = fields.BooleanField(default=True) description = fields.StringField(read_only=False, required=False) domains = fields.ListField(default=[]) - id = fields.IntegerField(read_only=True) links = fields.LinksField() created_at = fields.DateTimeField(read_only=True, required=False) updated_at = fields.DateTimeField(read_only=True, required=False) @@ -45,7 +47,6 @@ def upload_file(self, path, file): response = connection.session.post('{}{}'.format(connection.host, files_path), headers=headers, data=data, files=[('file', file)]) if response.status_code != 201: - logger.error(response.text) return return HostingFile(**response.json()) @@ -74,7 +75,6 @@ def update_file(self, path, file): response = connection.session.patch('{}{}'.format(connection.host, hosting_file.links.self), headers=headers, files=[('file', file)]) if response.status_code != 200: - logger.error(response.text) return return HostingFile(**response.json()) diff --git a/tests/integration_tests_hosting.py b/tests/integration_tests_hosting.py index 1be56a5..b60f942 100644 --- a/tests/integration_tests_hosting.py +++ b/tests/integration_tests_hosting.py @@ -13,35 +13,38 @@ class HostingIntegrationTests(InstanceMixin, IntegrationTest): - def setUp(self): - self.hosting = self.instance.hostings.create( - label='test12', - description='desc', - domains=['test.test{}.io'.format(uuid.uuid4().hex[:5])] - ) - def test_create_file(self): + hosting = self._create_hosting('created-xyz') a_hosting_file = StringIO() a_hosting_file.write('h1 {color: #541231;}') a_hosting_file.seek(0) - hosting_file = self.hosting.upload_file(path='styles/main.css', file=a_hosting_file) + hosting_file = hosting.upload_file(path='styles/main.css', file=a_hosting_file) self.assertEqual(hosting_file.path, 'styles/main.css') def test_set_default(self): - hosting = self.hosting.set_default() - self.assertIn('default', hosting.domains) + hosting = self._create_hosting('default-xyz') + hosting = hosting.set_default() + self.assertTrue('default', hosting.is_default) def test_update_file(self): + hosting = self._create_hosting('update-xyz') a_hosting_file = StringIO() a_hosting_file.write('h1 {color: #541231;}') a_hosting_file.seek(0) - self.hosting.upload_file(path='styles/main.css', file=a_hosting_file) + hosting.upload_file(path='styles/main.css', file=a_hosting_file) a_hosting_file = StringIO() a_hosting_file.write('h2 {color: #541231;}') a_hosting_file.seek(0) - hosting_file = self.hosting.update_file(path='styles/main.css', file=a_hosting_file) + hosting_file = hosting.update_file(path='styles/main.css', file=a_hosting_file) self.assertEqual(hosting_file.path, 'styles/main.css') + + def _create_hosting(self, name): + return self.instance.hostings.create( + name=name, + description='desc', + domains=['test.test{}.io'.format(uuid.uuid4().hex[:5])] + )