Skip to content

Commit aea96df

Browse files
authored
Merge pull request #252 from Syncano/LIB-965
[LIB-965] Hosting API update - CORE changes
2 parents 3432726 + 7ba0ffa commit aea96df

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

syncano/models/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .push_notification import * # NOQA
1212
from .geo import * # NOQA
1313
from .backups import * # NOQA
14-
from .hosting import * # NOQA
14+
from .hosting import Hosting, HostingFile # NOQA
1515
from .data_views import DataEndpoint as EndpointData # NOQA
1616
from .custom_sockets import * # NOQA
1717
from .custom_sockets_utils import Endpoint, ScriptCall, ScriptDependency, ClassDependency # NOQA

syncano/models/hosting.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
# -*- coding: utf-8 -*-
22

33
from . import fields
4-
from .base import Instance, Model, logger
4+
from .base import Model
5+
from .instances import Instance
56

67

78
class Hosting(Model):
89
"""
910
OO wrapper around hosting.
1011
"""
1112

12-
label = fields.StringField(max_length=64, primary_key=True)
13+
name = fields.StringField(max_length=253)
14+
is_default = fields.BooleanField(read_only=True)
15+
is_active = fields.BooleanField(default=True)
1316
description = fields.StringField(read_only=False, required=False)
1417
domains = fields.ListField(default=[])
1518

16-
id = fields.IntegerField(read_only=True)
1719
links = fields.LinksField()
1820
created_at = fields.DateTimeField(read_only=True, required=False)
1921
updated_at = fields.DateTimeField(read_only=True, required=False)
@@ -45,7 +47,6 @@ def upload_file(self, path, file):
4547
response = connection.session.post('{}{}'.format(connection.host, files_path), headers=headers,
4648
data=data, files=[('file', file)])
4749
if response.status_code != 201:
48-
logger.error(response.text)
4950
return
5051
return HostingFile(**response.json())
5152

@@ -74,7 +75,6 @@ def update_file(self, path, file):
7475
response = connection.session.patch('{}{}'.format(connection.host, hosting_file.links.self), headers=headers,
7576
files=[('file', file)])
7677
if response.status_code != 200:
77-
logger.error(response.text)
7878
return
7979
return HostingFile(**response.json())
8080

tests/integration_tests_hosting.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,38 @@
1313

1414
class HostingIntegrationTests(InstanceMixin, IntegrationTest):
1515

16-
def setUp(self):
17-
self.hosting = self.instance.hostings.create(
18-
label='test12',
19-
description='desc',
20-
domains=['test.test{}.io'.format(uuid.uuid4().hex[:5])]
21-
)
22-
2316
def test_create_file(self):
17+
hosting = self._create_hosting('created-xyz')
2418
a_hosting_file = StringIO()
2519
a_hosting_file.write('h1 {color: #541231;}')
2620
a_hosting_file.seek(0)
2721

28-
hosting_file = self.hosting.upload_file(path='styles/main.css', file=a_hosting_file)
22+
hosting_file = hosting.upload_file(path='styles/main.css', file=a_hosting_file)
2923
self.assertEqual(hosting_file.path, 'styles/main.css')
3024

3125
def test_set_default(self):
32-
hosting = self.hosting.set_default()
33-
self.assertIn('default', hosting.domains)
26+
hosting = self._create_hosting('default-xyz')
27+
hosting = hosting.set_default()
28+
self.assertTrue('default', hosting.is_default)
3429

3530
def test_update_file(self):
31+
hosting = self._create_hosting('update-xyz')
3632
a_hosting_file = StringIO()
3733
a_hosting_file.write('h1 {color: #541231;}')
3834
a_hosting_file.seek(0)
3935

40-
self.hosting.upload_file(path='styles/main.css', file=a_hosting_file)
36+
hosting.upload_file(path='styles/main.css', file=a_hosting_file)
4137

4238
a_hosting_file = StringIO()
4339
a_hosting_file.write('h2 {color: #541231;}')
4440
a_hosting_file.seek(0)
4541

46-
hosting_file = self.hosting.update_file(path='styles/main.css', file=a_hosting_file)
42+
hosting_file = hosting.update_file(path='styles/main.css', file=a_hosting_file)
4743
self.assertEqual(hosting_file.path, 'styles/main.css')
44+
45+
def _create_hosting(self, name):
46+
return self.instance.hostings.create(
47+
name=name,
48+
description='desc',
49+
domains=['test.test{}.io'.format(uuid.uuid4().hex[:5])]
50+
)

0 commit comments

Comments
 (0)