There are significant restraints on an employer's right to engage in medical testing to determine if an applicant or employee is using drugs.
The law basically allows any employer to do a pre-employment drug test on any applicant as long as the procedure used minimizes the invasion of privacy. Therefore, if the blood or urine test is done in private, and there are protocols in place to make sure the results are treated like confidential medical records, most employers can drug test applicants.
If you are an employee (i.e., you have already been hired) the employer can only drug test you if (1) it is part of a truly random drug testing policy, (2) the employer has objective evidence that give it a reasonable suspicion that the employee is using drugs, or (3) if the employee has been involved in a workplace accident or injury and the test is done immediately upon the happening of that event.
Where you work for an agency, the issue of who is the employer is a little more complicated, but not hard to understand. Essentially, if you are paid by one company, but you work under the direction and control of another, both companies are usually considered an employer. This is called the "joint employer doctrine." Both companies are allowed to act as employer with regard to the drug testing, and both employers are bound by most of the laws that protect employees against employer wrongdoing.
If you test positive on a drug test and therefore are terminated or not hired, it is highly unlikely you will qualify for unemployment insurance benefits. The basic concept of unemployment benefits is that you may be compensated if you are unemployed through no fault of your own. Failing a drug test is usually sufficient grounds to constitute "misconduct" which disqualifies you from eligibility for benefits.
Good luck to you.
This answer should not be construed to create any attorney-client relationship. Such a relationship can be formed only through the mutual execution of an attorney-client agreement. The answer given is based on the extremely limited facts provided and the proper course of action might change significantly with the introduction of other facts. All who read this answer should not rely on the answer to govern their conduct. Please seek the advice of competent counsel after disclosing all facts to that attorney. This answer is intended for California residents only. The answering party is only licensed to practice in the State of California.