chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using QuantConnect.Notifications;
|
||||
|
||||
namespace QuantConnect.Tests.Common.Notifications
|
||||
{
|
||||
[TestFixture, Parallelizable(ParallelScope.All)]
|
||||
public class NotificationEmailTests
|
||||
{
|
||||
[Test]
|
||||
public void Constructor_SetsNullData_ToEmptyString()
|
||||
{
|
||||
// empty string used as default following NotificationManager.Email's default value for data
|
||||
var email = new NotificationEmail("e@d.com", "subject", "message", null);
|
||||
Assert.AreEqual(string.Empty, email.Data);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Constructor_SetsNullSubject_ToEmptyString()
|
||||
{
|
||||
// empty string used if subject is null
|
||||
var email = new NotificationEmail("e@d.com", null, "message", "data");
|
||||
Assert.AreEqual(string.Empty, email.Subject);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Constructor_SetsNullMessage_ToEmptyString()
|
||||
{
|
||||
// empty string used if message is null
|
||||
var email = new NotificationEmail("e@d.com", "subject", null, "data");
|
||||
Assert.AreEqual(string.Empty, email.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase("js@contoso.中国", true)]
|
||||
[TestCase("j@proseware.com9", true)]
|
||||
[TestCase("js@proseware.com9", true)]
|
||||
[TestCase("j_9@[129.126.118.1]", true)]
|
||||
[TestCase("jones@ms1.proseware.com", true)]
|
||||
[TestCase("david.jones@proseware.com", true)]
|
||||
[TestCase("d.j@server1.proseware.com", true)]
|
||||
[TestCase("js#internal@proseware.com", true)]
|
||||
[TestCase("j.s@server1.proseware.com", true)]
|
||||
[TestCase("\"j\\\"s\\\"\"@proseware.com", true)]
|
||||
|
||||
[TestCase("js*@proseware.com", false)]
|
||||
[TestCase("js@proseware..com", false)]
|
||||
[TestCase("j..s@proseware.com", false)]
|
||||
[TestCase("j.@server1.proseware.com", false)]
|
||||
public void Constructor_ThrowsArgumentException_WhenEmailAddressIsInvalid(string address, bool isValid)
|
||||
{
|
||||
// Test cases sourced via msdn:
|
||||
// https://docs.microsoft.com/en-us/dotnet/standard/base-types/how-to-verify-that-strings-are-in-valid-email-format
|
||||
|
||||
TestDelegate ctor = () => new NotificationEmail(
|
||||
address,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty
|
||||
);
|
||||
|
||||
if (isValid)
|
||||
{
|
||||
Assert.DoesNotThrow(ctor);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Throws<ArgumentException>(ctor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using NUnit.Framework;
|
||||
using QuantConnect.Notifications;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace QuantConnect.Tests.Common.Notifications
|
||||
{
|
||||
[TestFixture, Parallelizable(ParallelScope.All)]
|
||||
public class NotificationFtpTests
|
||||
{
|
||||
private byte[] _testContent = Encoding.ASCII.GetBytes("{}");
|
||||
|
||||
[Test]
|
||||
public void PortDefaultsTo21()
|
||||
{
|
||||
var notification = new NotificationFtp("qc.com", "username", "password", "path/to/file.json", _testContent);
|
||||
Assert.AreEqual(21, notification.Port);
|
||||
}
|
||||
|
||||
[TestCase(null)]
|
||||
[TestCase("")]
|
||||
public void ThrowsOnMissingPassword(string password)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => new NotificationFtp("qc.com", "username", password, "path/to/file.json", _testContent));
|
||||
}
|
||||
|
||||
[TestCase(null)]
|
||||
[TestCase("")]
|
||||
public void ThrowsOnMissingSSHKeys(string privateKey)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => new NotificationFtp("qc.com", "username", privateKey, "", "path/to/file.json", _testContent));
|
||||
}
|
||||
|
||||
// Protocol as in a URI
|
||||
[TestCase(@"ftp://qc.com")]
|
||||
[TestCase(@"sftp://qc.com")]
|
||||
// Trailing slashes
|
||||
[TestCase(@"qc.com/")]
|
||||
[TestCase(@"qc.com//")]
|
||||
// Both
|
||||
[TestCase(@"ftp://qc.com//")]
|
||||
[TestCase(@"sftp://qc.com//")]
|
||||
[TestCase(@"qc.com")]
|
||||
public void NormalizesHostname(string hostname)
|
||||
{
|
||||
var notification = new NotificationFtp(hostname, "username", "password", "path/to/file.json", _testContent);
|
||||
Assert.AreEqual("qc.com", notification.Hostname);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EncodesBytesFileContent()
|
||||
{
|
||||
var contentStr = @"{""someKey"": ""this is a sample json file"", ""anotherKey"": 123456}";
|
||||
var contentBytes = Encoding.ASCII.GetBytes(contentStr);
|
||||
var notification = new NotificationFtp("qc.com", "username", "password", "path/to/file.json", contentBytes);
|
||||
AssertEncoding(contentStr, notification);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EncodesStringFileContent()
|
||||
{
|
||||
var contentStr = @"{""someKey"": ""this is a sample json file"", ""anotherKey"": 123456}";
|
||||
var notification = new NotificationFtp("qc.com", "username", "password", "path/to/file.json", contentStr);
|
||||
AssertEncoding(contentStr, notification);
|
||||
}
|
||||
|
||||
private static void AssertEncoding(string expectedContentStr, NotificationFtp notification)
|
||||
{
|
||||
var decodedBytes = Convert.FromBase64String(notification.FileContent);
|
||||
var decodedStr = Encoding.ASCII.GetString(decodedBytes);
|
||||
|
||||
Assert.AreEqual(expectedContentStr, decodedStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using QuantConnect.Notifications;
|
||||
|
||||
namespace QuantConnect.Tests.Common.Notifications
|
||||
{
|
||||
[TestFixture]
|
||||
public class NotificationJsonConverterTests
|
||||
{
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public void EmailRoundTrip(bool nullFields)
|
||||
{
|
||||
var expected = new NotificationEmail("p@p.com", "subjectP", null, null);
|
||||
if (!nullFields)
|
||||
{
|
||||
expected.Headers = new Dictionary<string, string> { { "key", "value" } };
|
||||
expected.Data = "dataContent";
|
||||
}
|
||||
|
||||
var serialized = JsonConvert.SerializeObject(expected);
|
||||
|
||||
var result = (NotificationEmail)JsonConvert.DeserializeObject<Notification>(serialized);
|
||||
|
||||
Assert.AreEqual(expected.Subject, result.Subject);
|
||||
Assert.AreEqual(expected.Address, result.Address);
|
||||
Assert.AreEqual(expected.Data, result.Data);
|
||||
Assert.AreEqual(expected.Message, result.Message);
|
||||
Assert.AreEqual(expected.Headers, result.Headers);
|
||||
}
|
||||
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public void SmsRoundTrip(bool nullFields)
|
||||
{
|
||||
var expected = new NotificationSms("123", nullFields ? null : "ImATextMessage");
|
||||
|
||||
var serialized = JsonConvert.SerializeObject(expected);
|
||||
|
||||
var result = (NotificationSms)JsonConvert.DeserializeObject<Notification>(serialized);
|
||||
|
||||
Assert.AreEqual(expected.PhoneNumber, result.PhoneNumber);
|
||||
Assert.AreEqual(expected.Message, result.Message);
|
||||
}
|
||||
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public void WebRoundTrip(bool nullFields)
|
||||
{
|
||||
var expected = new NotificationWeb("qc.com",
|
||||
nullFields ? null : "JijiData",
|
||||
nullFields ? null : new Dictionary<string, string> { { "key", "value" } });
|
||||
|
||||
var serialized = JsonConvert.SerializeObject(expected);
|
||||
|
||||
var result = (NotificationWeb)JsonConvert.DeserializeObject<Notification>(serialized);
|
||||
|
||||
Assert.AreEqual(expected.Address, result.Address);
|
||||
Assert.AreEqual(expected.Data, result.Data);
|
||||
Assert.AreEqual(expected.Headers, result.Headers);
|
||||
}
|
||||
|
||||
[TestCase(true, true)]
|
||||
[TestCase(true, false)]
|
||||
[TestCase(false, true)]
|
||||
[TestCase(false, false)]
|
||||
public void TelegramRoundTrip(bool nullMessage, bool nullToken)
|
||||
{
|
||||
var expected = new NotificationTelegram("pepe", nullMessage ? null : "ImAMessage", nullToken ? null : "botToken");
|
||||
|
||||
var serialized = JsonConvert.SerializeObject(expected);
|
||||
|
||||
var result = (NotificationTelegram)JsonConvert.DeserializeObject<Notification>(serialized);
|
||||
|
||||
Assert.AreEqual(expected.Id, result.Id);
|
||||
Assert.AreEqual(expected.Message, result.Message);
|
||||
Assert.AreEqual(expected.Token, result.Token);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FtpWithPasswordRoundTrip([Values] bool secure, [Values] bool withPort)
|
||||
{
|
||||
var expected = new NotificationFtp(
|
||||
"qc.com",
|
||||
"username",
|
||||
"password",
|
||||
"path/to/file.json",
|
||||
Encoding.ASCII.GetBytes("{}"),
|
||||
secure,
|
||||
withPort ? 2121: null);
|
||||
|
||||
var serialized = JsonConvert.SerializeObject(expected);
|
||||
var result = (NotificationFtp)JsonConvert.DeserializeObject<Notification>(serialized);
|
||||
|
||||
Assert.AreEqual(expected.Hostname, result.Hostname);
|
||||
Assert.AreEqual(expected.Username, result.Username);
|
||||
Assert.AreEqual(expected.Password, result.Password);
|
||||
Assert.AreEqual(expected.FilePath, result.FilePath);
|
||||
Assert.AreEqual(expected.FileContent, result.FileContent);
|
||||
Assert.AreEqual(expected.Port, result.Port);
|
||||
Assert.AreEqual(expected.Secure, result.Secure);
|
||||
Assert.IsNull(result.PrivateKey);
|
||||
Assert.IsNull(result.PrivateKeyPassphrase);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FtpWithKeyRoundTrip([Values] bool withPort, [Values] bool withPassphrase)
|
||||
{
|
||||
var expected = new NotificationFtp(
|
||||
"qc.com",
|
||||
"username",
|
||||
"privatekey",
|
||||
withPassphrase ? "passphrase" : null,
|
||||
"path/to/file.json",
|
||||
Encoding.ASCII.GetBytes("{}"),
|
||||
withPort ? 2121 : null);
|
||||
|
||||
var serialized = JsonConvert.SerializeObject(expected);
|
||||
var result = (NotificationFtp)JsonConvert.DeserializeObject<Notification>(serialized);
|
||||
|
||||
Assert.AreEqual(expected.Hostname, result.Hostname);
|
||||
Assert.AreEqual(expected.Username, result.Username);
|
||||
Assert.AreEqual(expected.PrivateKey, result.PrivateKey);
|
||||
Assert.AreEqual(expected.FilePath, result.FilePath);
|
||||
Assert.AreEqual(expected.FileContent, result.FileContent);
|
||||
Assert.AreEqual(expected.Port, result.Port);
|
||||
Assert.IsNull(result.Password);
|
||||
Assert.IsTrue(result.Secure);
|
||||
|
||||
if (withPassphrase)
|
||||
{
|
||||
Assert.AreEqual(expected.PrivateKeyPassphrase, result.PrivateKeyPassphrase);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsNull(result.PrivateKeyPassphrase);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CaseInsensitive()
|
||||
{
|
||||
var serialized = @"[{
|
||||
""address"": ""p@p.com"",
|
||||
""subject"": ""sdads""
|
||||
}, {
|
||||
""phoneNumber"": ""11111111111""
|
||||
}, {
|
||||
""headers"": {
|
||||
""1"": ""2""
|
||||
},
|
||||
""address"": ""qc.com""
|
||||
}, {
|
||||
""address"": ""qc.com/1234""
|
||||
},{
|
||||
""host"": ""qc.com"",
|
||||
""username"": ""username"",
|
||||
""password"": ""password"",
|
||||
""fileDestinationPath"": ""path/to/file.csv"",
|
||||
""fileContent"": ""abcde"",
|
||||
""secure"": ""true"",
|
||||
""port"": 2222
|
||||
},{
|
||||
""host"": ""qc.com"",
|
||||
""username"": ""username"",
|
||||
""password"": ""password"",
|
||||
""fileDestinationPath"": ""path/to/file.csv"",
|
||||
""filecontent"": ""abcde"",
|
||||
""secure"": ""false"",
|
||||
""port"": 2222
|
||||
},{
|
||||
""host"": ""qc.com"",
|
||||
""username"": ""username"",
|
||||
""privatekey"": ""privatekey"",
|
||||
""passphrase"": ""privatekeyPassphrase"",
|
||||
""fileDestinationPath"": ""path/to/file.csv"",
|
||||
""filecontent"": ""abcde"",
|
||||
""secure"": ""false"",
|
||||
""port"": 2222
|
||||
}]";
|
||||
var result = JsonConvert.DeserializeObject<List<Notification>>(serialized);
|
||||
|
||||
Assert.AreEqual(7, result.Count);
|
||||
|
||||
var email = result[0] as NotificationEmail;
|
||||
Assert.AreEqual("sdads", email.Subject);
|
||||
Assert.AreEqual("p@p.com", email.Address);
|
||||
|
||||
var sms = result[1] as NotificationSms;
|
||||
Assert.AreEqual("11111111111", sms.PhoneNumber);
|
||||
|
||||
var web = result[2] as NotificationWeb;
|
||||
Assert.AreEqual(1, web.Headers.Count);
|
||||
Assert.AreEqual("2", web.Headers["1"]);
|
||||
Assert.AreEqual("qc.com", web.Address);
|
||||
|
||||
var web2 = result[3] as NotificationWeb;
|
||||
Assert.AreEqual("qc.com/1234", web2.Address);
|
||||
|
||||
var ftp = result[4] as NotificationFtp;
|
||||
Assert.AreEqual("qc.com", ftp.Hostname);
|
||||
Assert.AreEqual("username", ftp.Username);
|
||||
Assert.AreEqual("password", ftp.Password);
|
||||
Assert.AreEqual("path/to/file.csv", ftp.FilePath);
|
||||
Assert.AreEqual("abcde", ftp.FileContent);
|
||||
Assert.IsTrue(ftp.Secure);
|
||||
Assert.AreEqual(2222, ftp.Port);
|
||||
Assert.IsNull(ftp.PrivateKey);
|
||||
Assert.IsNull(ftp.PrivateKeyPassphrase);
|
||||
|
||||
var ftp2 = result[5] as NotificationFtp;
|
||||
Assert.AreEqual("qc.com", ftp2.Hostname);
|
||||
Assert.AreEqual("username", ftp2.Username);
|
||||
Assert.AreEqual("password", ftp2.Password);
|
||||
Assert.AreEqual("path/to/file.csv", ftp2.FilePath);
|
||||
Assert.AreEqual("abcde", ftp2.FileContent);
|
||||
Assert.IsFalse(ftp2.Secure);
|
||||
Assert.AreEqual(2222, ftp2.Port);
|
||||
Assert.IsNull(ftp.PrivateKey);
|
||||
Assert.IsNull(ftp.PrivateKeyPassphrase);
|
||||
|
||||
var ftp3 = result[6] as NotificationFtp;
|
||||
Assert.AreEqual("qc.com", ftp3.Hostname);
|
||||
Assert.AreEqual("username", ftp3.Username);
|
||||
Assert.AreEqual("privatekey", ftp3.PrivateKey);
|
||||
Assert.AreEqual("privatekeyPassphrase", ftp3.PrivateKeyPassphrase);
|
||||
Assert.AreEqual("path/to/file.csv", ftp3.FilePath);
|
||||
Assert.AreEqual("abcde", ftp3.FileContent);
|
||||
Assert.IsTrue(ftp3.Secure);
|
||||
Assert.AreEqual(2222, ftp3.Port);
|
||||
Assert.IsNull(ftp3.Password);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using Python.Runtime;
|
||||
using QuantConnect.Notifications;
|
||||
|
||||
namespace QuantConnect.Tests.Common.Notifications
|
||||
{
|
||||
[TestFixture(true)]
|
||||
[TestFixture(false)]
|
||||
public class NotificationManagerTests
|
||||
{
|
||||
private readonly bool _liveMode;
|
||||
private NotificationManager _notify;
|
||||
|
||||
public NotificationManagerTests(bool liveMode)
|
||||
{
|
||||
_liveMode = liveMode;
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_notify = new NotificationManager(_liveMode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Email_AddsNotificationEmail_ToMessages_WhenLiveModeIsTrue()
|
||||
{
|
||||
Assert.AreEqual(_liveMode, _notify.Email("address@domain.com", "subject", "message", "data"));
|
||||
Assert.AreEqual(_liveMode ? 1 : 0, _notify.Messages.Count);
|
||||
if (_liveMode)
|
||||
{
|
||||
Assert.IsInstanceOf<NotificationEmail>(_notify.Messages.Single());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Sms_AddsNotificationSms_ToMessages_WhenLiveModeIsTrue()
|
||||
{
|
||||
Assert.AreEqual(_liveMode, _notify.Sms("phone-number", "message"));
|
||||
Assert.AreEqual(_liveMode ? 1 : 0, _notify.Messages.Count);
|
||||
if (_liveMode)
|
||||
{
|
||||
Assert.IsInstanceOf<NotificationSms>(_notify.Messages.Single());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Web_AddsNotificationWeb_ToMessages_WhenLiveModeIsTrue()
|
||||
{
|
||||
Assert.AreEqual(_liveMode, _notify.Web("address", "data"));
|
||||
Assert.AreEqual(_liveMode ? 1 : 0, _notify.Messages.Count);
|
||||
if (_liveMode)
|
||||
{
|
||||
Assert.IsInstanceOf<NotificationWeb>(_notify.Messages.Single());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TelegramAddsNotificationToMessagesWhenLiveModeIsTrue()
|
||||
{
|
||||
Assert.AreEqual(_liveMode, _notify.Telegram("pepe", "ImAMessage", "botToken"));
|
||||
Assert.AreEqual(_liveMode ? 1 : 0, _notify.Messages.Count);
|
||||
if (_liveMode)
|
||||
{
|
||||
Assert.IsInstanceOf<NotificationTelegram>(_notify.Messages.Single());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FtpAddsNotificationToMessagesWhenLiveModeIsTrue()
|
||||
{
|
||||
Assert.AreEqual(_liveMode, _notify.Ftp("qc.com", "username", "password", "path/to/file.json", Encoding.ASCII.GetBytes("{}")));
|
||||
Assert.AreEqual(_liveMode ? 1 : 0, _notify.Messages.Count);
|
||||
if (_liveMode)
|
||||
{
|
||||
Assert.IsInstanceOf<NotificationFtp>(_notify.Messages.Single());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FtpAddsNotificationToMessagesWhenLiveModeIsTrueFromStringContents()
|
||||
{
|
||||
Assert.AreEqual(_liveMode, _notify.Ftp("qc.com", "username", "password", "path/to/file.json", "{}"));
|
||||
Assert.AreEqual(_liveMode ? 1 : 0, _notify.Messages.Count);
|
||||
if (_liveMode)
|
||||
{
|
||||
Assert.IsInstanceOf<NotificationFtp>(_notify.Messages.Single());
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase("email")]
|
||||
[TestCase("web")]
|
||||
public void PythonOverloads(string notificationType)
|
||||
{
|
||||
using (Py.GIL())
|
||||
{
|
||||
dynamic function;
|
||||
bool result;
|
||||
var test = PyModule.FromString("testModule",
|
||||
@"
|
||||
from AlgorithmImports import *
|
||||
|
||||
def email(notifier):
|
||||
headers = {'header-key': 'header-value'}
|
||||
return notifier.Email('me@email.com', 'subject', 'message', 'data', headers)
|
||||
|
||||
def web(notifier):
|
||||
headers = {'header-key': 'header-value'}
|
||||
data = {'objectA':'valueA', 'objectB':{'PropertyA':10, 'PropertyB':'stringB'}}
|
||||
return notifier.Web('api.quantconnect.com', data, headers)");
|
||||
|
||||
|
||||
switch (notificationType)
|
||||
{
|
||||
case "email":
|
||||
function = test.GetAttr("email");
|
||||
result = function(_notify);
|
||||
break;
|
||||
|
||||
case "web":
|
||||
function = test.GetAttr("web");
|
||||
result = function(_notify);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentException($"Invalid method: {notificationType}");
|
||||
}
|
||||
|
||||
if (_liveMode)
|
||||
{
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user