def get_random_node_list(inventory_size: int = 200) -> Tuple[Dict, Dict, Dict]: """Generate a list of random devices Args: inventory_size (int): Number of nodes in the list. Default 200 Returns: Tuple[Dict, Dict, Dict]: Three dictionaries containing: device info, credentials, and a combination of the two dictionaries """ inventory = {} credentials = {} all_nodes = {} fake = Faker() Faker.seed(random.randint(1, 10000)) ports = [22, 443, 1244, 8080, 4565] transports = ['ssh', 'https', 'http'] devtypes = ['panos', 'eos', None] namespaces = ['data-center-north', 'south-data-center'] keys = ['tests/unit/poller/shared/sample_key', None] for _ in range(inventory_size): entry = { 'address': fake.ipv4(address_class='c'), 'username': fake.domain_word(), 'port': fake.word(ports), 'transport': fake.word(transports), 'devtype': fake.word(devtypes), 'namespace': fake.word(namespaces), 'jump_host': fake.word([f"// {fake.domain_word()}@{fake.ipv4()}", None]) } cred = { 'password': fake.password(), 'ssh_keyfile': fake.word(keys), 'jump_host_key_file': fake.word(keys), 'passphrase': fake.word([fake.password(), None]) } key = f"{entry['namespace']}.{entry['address']}.{entry['port']}" inventory[key] = entry credentials[key] = cred all_nodes[key] = cred.copy() all_nodes[key].update(entry) return inventory, credentials, all_nodes
class TestSendMessageToDiscordUserView(TestCase): def setUp(self): self.discord_user = USER_WITH_SAME_SERVER self.faker = Faker() self.data = { 'discord_user_id': self.discord_user, 'message_content': self.faker.word(), } self.url = reverse('bot:utils:send_message') def test_post_ok(self): response = self.client.post(self.url, data=self.data) self.assertEqual(201, response.status_code) def test_post_missing_data_ko(self): response = self.client.post(self.url, data={}) self.assertEqual(400, response.status_code) @override_settings(ALLOWED_HOSTS=['localhost', 'testserver', '127.0.0.1']) def test_post_from_outer_ko(self): response = self.client.post(self.url, data=self.data, REMOTE_ADDR=self.faker.ipv4()) self.assertEqual(403, response.status_code) @override_settings( ALLOWED_HOSTS=['develop.oilandrope-project.com', 'testserver']) def test_post_from_outer_ok(self): response = self.client.post( self.url, data=self.data, HTTP_ORIGIN='http://develop.oilandrope-project.com') self.assertEqual(201, response.status_code) def test_post_msg_created_ok(self): response = self.client.post(self.url, data=self.data) channel = Channel(response.json()['channel_id']) msg = Message(channel, response.json()['id']) self.assertEqual(response.json(), msg.json_response)