Setup integration test to test data file
This commit is contained in:
parent
c8df2a6ab5
commit
fbf144622d
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
venv
|
venv
|
||||||
.idea
|
.idea
|
||||||
|
/torch_sub/test/clients.json
|
|
@ -9,18 +9,18 @@ from torch_sub import torch_sub
|
||||||
|
|
||||||
host = "mqtt.example.com"
|
host = "mqtt.example.com"
|
||||||
port = 8883
|
port = 8883
|
||||||
configPath = "agent-config/"
|
config_path = "agent-config/"
|
||||||
mqttCaFile = configPath + "ca.crt"
|
mqtt_ca_file = config_path + "ca.crt"
|
||||||
mqttCertFile = configPath + "vagrant.crt"
|
mqtt_cert_file = config_path + "vagrant.crt"
|
||||||
mqttKeyFile = configPath + "vagrant.key"
|
mqtt_key_file = config_path + "vagrant.key"
|
||||||
|
|
||||||
|
|
||||||
def agent_connect():
|
def agent_connect():
|
||||||
client = mqtt.Client()
|
client = mqtt.Client()
|
||||||
client.tls_set(
|
client.tls_set(
|
||||||
ca_certs=mqttCaFile,
|
ca_certs=mqtt_ca_file,
|
||||||
certfile=mqttCertFile,
|
certfile=mqtt_cert_file,
|
||||||
keyfile=mqttKeyFile,
|
keyfile=mqtt_key_file,
|
||||||
cert_reqs=ssl.CERT_REQUIRED)
|
cert_reqs=ssl.CERT_REQUIRED)
|
||||||
client.connect(host, port, 60)
|
client.connect(host, port, 60)
|
||||||
return client
|
return client
|
||||||
|
@ -39,22 +39,28 @@ def agent_publish(client_id, onion_hostname):
|
||||||
topic = "torch/" + client_id + "/wake"
|
topic = "torch/" + client_id + "/wake"
|
||||||
|
|
||||||
client.publish(topic, json.dumps(payload))
|
client.publish(topic, json.dumps(payload))
|
||||||
print("Log: Connected to MQTT Broker at %s://%s:%s/%s" % ("mqtts", host, port, topic))
|
print("Debug: Connected to MQTT Broker at %s://%s:%s/%s" % ("mqtts", host, port, topic))
|
||||||
print("Log: Published payload: " + json.dumps(payload))
|
print("Debug: Published payload: " + json.dumps(payload))
|
||||||
|
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
print("Log: Disconnected from MQTT Broker")
|
print("Debug: Disconnected from MQTT Broker")
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MyTestCase(unittest.TestCase):
|
class GivenBrokerAndTorchAgent(unittest.TestCase):
|
||||||
def test_something(self):
|
def test_when_agent_publishes_should_get_hostname_from_subscriber(self):
|
||||||
torch_sub.attach(host, port)
|
|
||||||
|
clients_json = "clients.json"
|
||||||
|
|
||||||
|
torch_sub.attach(host, port, clients_json)
|
||||||
|
|
||||||
agent_publish("client1", "crazyonion.onion")
|
agent_publish("client1", "crazyonion.onion")
|
||||||
|
|
||||||
self.assertEqual(True, False)
|
file = open(clients_json, "r")
|
||||||
|
response = json.load(file)
|
||||||
|
|
||||||
|
self.assertEqual(response['results']['client1']['onionAddress'], "crazyonion.onion")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -1,2 +1,15 @@
|
||||||
def attach(host, port):
|
import json
|
||||||
return None
|
|
||||||
|
|
||||||
|
def attach(host, port, datafile):
|
||||||
|
|
||||||
|
response = {
|
||||||
|
'results': {
|
||||||
|
'client1': {
|
||||||
|
'onionAddress': 'crazytime'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
with open(datafile, 'w') as outfile:
|
||||||
|
json.dump(response, outfile)
|
Loading…
Reference in New Issue
Block a user