Testing of Devtas according to Kena Upanishad and Sri Shiva Mahapuran.:
After Khseera sagara madanam, the Devas got Amrutam. The devas became very strong and easily defeated the Asuras. The Devas thought that it was their own strength which was responsible for the Victory over Asuras. They forgot altogether that it was only by the grace of Lord Shiva, the absolute brahman. The Devas started feeling very proud about their strength. They said to themselves.:
"vijayo'smakamevayam mahimeti "
"Verily, this victory is ours;
verily, this glory is ours only."
Lord Shiva who's in Yaksha form, asked him: "Who are you?"
Agni deva said : "I am known as Agni; I am also called Jataveda."
tasmimstvayi kim viryamityapidam sarvam
daheyam yadidam prithivyamiti
Yaksha said: "What power is in you, who are so well known?"
Agni deva replied: "I can burn all— whatever there is on earth."
tasmai trinam nidadhavetaddaheti |
tadupapreyaya sarvajavena tanna shashaka dagdhum sa tata eva
nivavrite naitadashakam vijnatum yadetadyakshamiti
Iswara put a straw before him and said: "Burn this."
Agnideva rushed toward it with all his ardour but could not burn it. Then he returned from the Spirit and said to the gods: "I could not find out who this Spirit is,"
atha vayumabruvanvayavetadvijanihi
kimetadyakshamiti tatheti
Then the devas said to Vayu : "O Vayu! Find out who this great Spirit is."
Vayu deva said : "Yes," , then he hastened to It.
tadabhyadravattamabhyavadatko'siti vayurva
ahamasmityabravinmatarishva va ahamasmiti
Parameswara asked him: "Who are you?"
Vayu replied : "I am known as Vayu; I am also called Matarisva."
tasmimstvayi kim viryamityapidam
sarvamadadiya yadidam prithivyamiti
Lord shiva said: "What power is in you, who are so well known?"
Vayu replied: "I can carry off all— whatever there is on earth."
tasmai trinam nidadhavetadadatsveti
tadupapreyaya sarvajavena tanna shashakadatum sa tata eva
nivavrite naitadashakam vijnatum yadetadyakshamiti
Brahman put a straw before him and said: "Carry this." He rushed toward it with all his ardour but could not move it. Then he returned from the Spirit and said to the gods: "I could not find out who this Spirit is,"
athendramabruvanmaghavannetadvijanihi kimetadyakshamiti tatheti
tadabhyadravattasmattirodadhe
Then the gods said to Indra: "O Maghavan! Find out who this great Spirit is."
Indra said: "Yes," and hastened to It.
sa tasminnevakashe striyamajagama bahushobhamanamuma
haimavatim tamhovaca kimetadyakshamiti
But the Lord shiva disappeared from him. Then Indra beheld in that very region of the sky a Woman highly adorned. She was Uma, the daughter of the Himalayas. In order to marry Lord shiva, she was doing severe penance. Uma knew the supreme nature of Lord Shiva.
Uma devi, The Daughter of Himalayas
Indra approached her and said: "Who is this great Spirit?"
sa brahmeti hovaca brahmano va etadvijaye mahiyadhvamiti
tato haiva vidancakara brahmeti
tasmadva ete deva atitaramivanyandevanyadagnirvayurindraste
hyenannedishtham pasparshuste hyenatprathamo vidancakara brahmeti
Parvati replied : "It is, indeed,Absolute Brahman Shiva . Through the victory of Brahman alone have you attained glory." Later, she taught Indra about the supreme nature of Lord Shiva. After that Indra understood that It was Brahman (Lord Shiva).
tasmadva indro'titaramivanyandevansa
hyenannedishtham pasparsha sa hyenatprathamo vidancakara brahmeti
Since they approached very near in comprehending the Supreme nature of Lord Shiva and were the first to know that the Yaksha was Brahman (Shiva) , these devas, namely, Agni, Vayu and Indra, excelled the other gods. And since Indra was the one got the knowledge of Brahman from maa uma he became the king of the devtas.
This story can be found in Kena Upanishad and purnas like Shiva Maha Puranam, etc.
Everyone got their Position and Powers by the grace of Bhagawan Mahadeva only by worshipping him.
He, the omniscient Rudra, the Creator of the Gods and the Bestower of their powers and positions, the Support of the universe, He who, in the beginning, gave birth to Hiranyagarbha -may He endow us with clear intellect! (Svet Up. 3.4).
Mahābhārat — Anūśāsan Parva- Chapter —18 , Verse-64.:
Vasudeva said., "...If Rudra be gratified with a person, he can confer upon him the states of eIther Brahma or of Kesava or of Sakra with all the deities under him, or the sovereignty of the three worlds. Those men, O sire, who worship Bhava even mentally, succeed in freeing themselves from all sins and attain to a residence in heaven with all the gods..."
~ Mahābhārata Anushāsana Parva Sec. XVIII.
Skanda Purāṇam — Kaśi Khaṅda, 1st section —(13:9).:
Putātmā said: 9. O Great lord, O Lord of the Devas, O bestower of freedom from fear unto the Devas, O bestower of the positions to all the Devas including Brahmā, Nārāyaṇa, Indra and others!
Parāśar Ūpa Purāṇam — Chapter-16.:
Viṣṇu attains Viṣṇu Position, Bramhā attains Bramhā Position and Indra attains Indra's Position by doing Śiva Bhakti.,
Matsya Purāṇam — Chapter —154.:
kings, Siddhas, Yakṣas and Gandharvas, Rākṣasas, Bhūtas and Pisacas, besides other acheived their respective positions by adoring Śiva. All the gods achieved god-hoods, with the same process. Brahma achieved Brahmattva, Visņu achieved the position of Vişņu, Rudra got Rudratva, and Indra got the position of Indra. Gaṇeśa was bestowed Gaṇeśahood with the same process. Bathing Siva-linga with the white sandal paste it should be adored with the white lotus flowers. The salutation should be offered thereafter.
Śrī śivānanda Laharī ||18.:
It means Viṣṇu, Bramhā , Indra all attain their positions by mere grace of Śiva and they always worship Śiva.
Skanda Purana/Khanda. 8 (Ambika Khanda), Chapter 21.:
13-14. Pleased with Nandi’s devotion, Lord Shiva offers him boons: Ask whether you want Brahmatva, Vishnutva, Indratva, or something else – Aditya or Rudra.
46-48. Nandi replied: I don’t want Brahmatva Vishnutva Indratva, I want to be near you as one of your servants. Please grant me this boons.
Skanda Purana 5:1:38.:
Sanatkumāra said:
Even as a hundred years elapsed while he was eulogizing thus, Lord Śaṅkara, the trident-bearing Lord, with a bull as his emblem, was pleased and he spoke thus:
“Son, welfare unto you. I am pleased with you. Now you have become free from impurities. I shall give you divine vision. Look at me without mental affliction.
O excellent Dānava, tell me whatever benefit has been desired mentally by you; I shall grant you.”
The Dānava Andhaka said:
The position of Brahmā, Viṣṇu or Indra is characterized by coming and going (i.e. impermanence). All this is known to me. I do not desire it at all.
O Lord of Devas, if you are pleased, grant me Gāṇapatya—lordship of the Gaṇas. That is something especially pure and everlasting.
Mahabali in his previous birth became Indra and due to his devotion was born as grandson of Prahlada due to the grace of Bhagawan Mahadeva as mentioned here.
I hope this clarifies all your queries. Prd..