def test_calling_refresh_cert_script_with_dead_instance( self, subprocess_mock): with mock.patch('os.path.exists', mock.Mock(return_value=True)): with mock.patch('os.listdir', mock.Mock(return_value=[TEST_DOMAIN])): HostingRefreshSecureCustomDomainCertTask.delay() self.assertEqual(subprocess_mock.call_args[0][0], [REMOVE_SSL_CERT_SCRIPT, TEST_DOMAIN])
def test_calling_refresh_cert_script_with_fresh_domain(self, utime_mock): with ignore_signal(pre_save, post_save): self.instance.domains = [TEST_DOMAIN] self.instance.save() self.hosting.domains = [TEST_DOMAIN] self.hosting.ssl_status = Hosting.SSL_STATUSES.ON self.hosting.save() with mock.patch('os.path.exists', mock.Mock(return_value=True)): with mock.patch('os.listdir', mock.Mock(return_value=[TEST_DOMAIN])): HostingRefreshSecureCustomDomainCertTask.delay() set_current_instance(self.instance) utime_mock.assert_called_once()
def test_calling_refresh_cert_script(self, subprocess_mock): with ignore_signal(pre_save, post_save): self.instance.domains = [TEST_DOMAIN] self.instance.save() self.hosting.domains = [TEST_DOMAIN] self.hosting.ssl_status = Hosting.SSL_STATUSES.ON self.hosting.save() with mock.patch('os.path.exists', mock.Mock(return_value=True)): with mock.patch( 'os.listdir', mock.Mock( return_value=['.last_update', 'pem', TEST_DOMAIN])): HostingRefreshSecureCustomDomainCertTask.delay() self.assertEqual(subprocess_mock.call_args[0][0], [RENEW_SSL_CERT_SCRIPT, TEST_DOMAIN]) set_current_instance(self.instance) self.hosting.refresh_from_db() self.assertEqual(self.hosting.ssl_status, Hosting.SSL_STATUSES.ON)