Setup integration test to test data file
This commit is contained in:
parent
c8df2a6ab5
commit
fbf144622d
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
venv
|
||||
.idea
|
||||
/torch_sub/test/clients.json
|
|
@ -9,18 +9,18 @@ from torch_sub import torch_sub
|
|||
|
||||
host = "mqtt.example.com"
|
||||
port = 8883
|
||||
configPath = "agent-config/"
|
||||
mqttCaFile = configPath + "ca.crt"
|
||||
mqttCertFile = configPath + "vagrant.crt"
|
||||
mqttKeyFile = configPath + "vagrant.key"
|
||||
config_path = "agent-config/"
|
||||
mqtt_ca_file = config_path + "ca.crt"
|
||||
mqtt_cert_file = config_path + "vagrant.crt"
|
||||
mqtt_key_file = config_path + "vagrant.key"
|
||||
|
||||
|
||||
def agent_connect():
|
||||
client = mqtt.Client()
|
||||
client.tls_set(
|
||||
ca_certs=mqttCaFile,
|
||||
certfile=mqttCertFile,
|
||||
keyfile=mqttKeyFile,
|
||||
ca_certs=mqtt_ca_file,
|
||||
certfile=mqtt_cert_file,
|
||||
keyfile=mqtt_key_file,
|
||||
cert_reqs=ssl.CERT_REQUIRED)
|
||||
client.connect(host, port, 60)
|
||||
return client
|
||||
|
@ -39,22 +39,28 @@ def agent_publish(client_id, onion_hostname):
|
|||
topic = "torch/" + client_id + "/wake"
|
||||
|
||||
client.publish(topic, json.dumps(payload))
|
||||
print("Log: Connected to MQTT Broker at %s://%s:%s/%s" % ("mqtts", host, port, topic))
|
||||
print("Log: Published payload: " + json.dumps(payload))
|
||||
print("Debug: Connected to MQTT Broker at %s://%s:%s/%s" % ("mqtts", host, port, topic))
|
||||
print("Debug: Published payload: " + json.dumps(payload))
|
||||
|
||||
client.disconnect()
|
||||
print("Log: Disconnected from MQTT Broker")
|
||||
print("Debug: Disconnected from MQTT Broker")
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class MyTestCase(unittest.TestCase):
|
||||
def test_something(self):
|
||||
torch_sub.attach(host, port)
|
||||
class GivenBrokerAndTorchAgent(unittest.TestCase):
|
||||
def test_when_agent_publishes_should_get_hostname_from_subscriber(self):
|
||||
|
||||
clients_json = "clients.json"
|
||||
|
||||
torch_sub.attach(host, port, clients_json)
|
||||
|
||||
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__':
|
||||
|
|
|
@ -1,2 +1,15 @@
|
|||
def attach(host, port):
|
||||
return None
|
||||
import json
|
||||
|
||||
|
||||
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