How long do you have to wait to take a pregnancy test?

Any time of two weeks after unprotected sex? Or do you have to wait until after your period is supposed to come?