Преглед изворни кода

fix(e2e2): make api_user behave more intuitively

Peter Thomassen пре 4 година
родитељ
комит
8c63c02d9e
1 измењених фајлова са 7 додато и 6 уклоњено
  1. 7 6
      test/e2e2/conftest.py

+ 7 - 6
test/e2e2/conftest.py

@@ -57,7 +57,6 @@ class DeSECAPIV1Client:
         self.email = None
         self.email = None
         self.password = None
         self.password = None
         self.domains = []
         self.domains = []
-        self.verify = True
 
 
         # We support two certificate verification methods
         # We support two certificate verification methods
         # (1) against self-signed certificates, if /autocert path is present
         # (1) against self-signed certificates, if /autocert path is present
@@ -151,11 +150,13 @@ class DeSECAPIV1Client:
         )
         )
 
 
     def login(self, email: str, password: str) -> requests.Response:
     def login(self, email: str, password: str) -> requests.Response:
-        token = self.post(
+        response = self.post(
             "/auth/login/", data={"email": email, "password": password}
             "/auth/login/", data={"email": email, "password": password}
         )
         )
-        self.headers["Authorization"] = f'Token {token.json()["token"]}'
-        return token
+        token = response.json().get('token')
+        if token is not None:
+            self.headers["Authorization"] = f'Token {response.json()["token"]}'
+        return response
 
 
     def domain_list(self) -> requests.Response:
     def domain_list(self) -> requests.Response:
         return self.get("/domains/")
         return self.get("/domains/")
@@ -195,12 +196,12 @@ def api_anon() -> DeSECAPIV1Client:
 
 
 
 
 @pytest.fixture()
 @pytest.fixture()
-def api_user(api_anon, random_email, random_password) -> DeSECAPIV1Client:
+def api_user(random_email, random_password) -> DeSECAPIV1Client:
     """
     """
     Access to the API with a fresh user account (zero domains, one token). Authorization header
     Access to the API with a fresh user account (zero domains, one token). Authorization header
     is preconfigured, email address and password are randomly chosen.
     is preconfigured, email address and password are randomly chosen.
     """
     """
-    api = api_anon
+    api = DeSECAPIV1Client()
     email = random_email()
     email = random_email()
     password = random_password()
     password = random_password()
     api.register(email, password)
     api.register(email, password)