Remove duplicated code of credentials in test.py

I created a method to generate credentials because, as with tuples, attributes in named tuples are immutable.