Skip to content
Merged
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
2 changes: 1 addition & 1 deletion syncano/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion syncano/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions syncano/models/hosting.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# -*- coding: utf-8 -*-

from . import fields
from .base import Instance, Model, logger
from .base import Model
from .instances import Instance


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)
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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())

Expand Down
27 changes: 15 additions & 12 deletions tests/integration_tests_hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])]
)