This repository has been archived by the owner on Aug 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move DNS management methods to the LoadBalancedInstance mixin.
- Loading branch information
Showing
6 changed files
with
132 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# OpenCraft -- tools to aid developing and hosting free software projects | ||
# Copyright (C) 2015-2016 OpenCraft <contact@opencraft.com> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
""" | ||
Load-balanced instance mixin - tests | ||
""" | ||
|
||
# Imports ##################################################################### | ||
|
||
from unittest.mock import patch, call | ||
|
||
from instance.tests.base import TestCase | ||
from instance.tests.models.factories.openedx_instance import OpenEdXInstanceFactory | ||
|
||
|
||
# Tests ####################################################################### | ||
|
||
class LoadBalancedInstanceTestCase(TestCase): | ||
""" | ||
Tests for OpenEdXStorageMixin | ||
""" | ||
|
||
@patch('instance.models.mixins.load_balanced.gandi.set_dns_record') | ||
def test_set_dns_records(self, mock_set_dns_record): | ||
""" | ||
Test set_dns_records() without external domains. | ||
""" | ||
instance = OpenEdXInstanceFactory(internal_lms_domain='test.dns.opencraft.com', | ||
use_ephemeral_databases=True) | ||
instance.set_dns_records() | ||
lb_domain = instance.load_balancing_server.domain + "." # pylint: disable=no-member | ||
self.assertEqual(mock_set_dns_record.mock_calls, [ | ||
call('opencraft.com', name='test.dns', type='CNAME', value=lb_domain), | ||
call('opencraft.com', name='preview-test.dns', type='CNAME', value=lb_domain), | ||
call('opencraft.com', name='studio-test.dns', type='CNAME', value=lb_domain), | ||
]) | ||
|
||
@patch('instance.models.mixins.load_balanced.gandi.set_dns_record') | ||
def test_set_dns_records_external_domain(self, mock_set_dns_record): | ||
""" | ||
Test set_dns_records() with custom external domains. | ||
Ensure that the DNS records are only created for the internal domains. | ||
""" | ||
instance = OpenEdXInstanceFactory(internal_lms_domain='test.dns.opencraft.hosting', | ||
external_lms_domain='courses.myexternal.org', | ||
external_lms_preview_domain='preview.myexternal.org', | ||
external_studio_domain='studio.myexternal.org', | ||
use_ephemeral_databases=True) | ||
instance.set_dns_records() | ||
lb_domain = instance.load_balancing_server.domain + "." # pylint: disable=no-member | ||
self.assertEqual(mock_set_dns_record.mock_calls, [ | ||
call('opencraft.hosting', name='test.dns', type='CNAME', value=lb_domain), | ||
call('opencraft.hosting', name='preview-test.dns', type='CNAME', value=lb_domain), | ||
call('opencraft.hosting', name='studio-test.dns', type='CNAME', value=lb_domain), | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters