First and foremost, I would advise you to learn German to a respectable level (at least B1) in your home country before going to take the 1-year preparatory course in Germany. Don’t underestimate the difficulty of the German language and the DSH test. To study successfully in the German language, you need to be really proficient in German and it’s really difficult to achieve this in just one year if you are starting from the scratch.
The DSH is a university language exam which certifies the existence of a German language proficiency sufficient for taking up studies in that language. You normally need an admission to study at a university in order to take the DSH test and is usually part of the requirement to study a degree program in German at a German university.
If you receive an admission to study at a German university, and they invite you to come and take their DSH test in order to study at their university in German, you will be going to Germany with a student visa and hence don’t need to return home once you pass the DSH test since it’s part of the requirement of the course.
On the other hand, if you don’t receive any admission letter from a university, you will need a language visa in order to study the German language in Germany which is totally different from a student visa. In that case, you can’t convert your language visa to a student visa once you are done with your language course and need to return home and apply for a student visa if you are successful in securing admission at a German university.