Fakultas Ilmu Komputer UI

Verified Commit 4b527286 authored by Muhammad Ariq Basyar's avatar Muhammad Ariq Basyar
Browse files

remove repeated code at base test, make more general method

parent 2298e07c
Pipeline #64624 passed with stages
in 7 minutes
......@@ -141,29 +141,26 @@ class InformasiFasilitasTest(TestCase):
dislike_test.save()
return dislike_test
def client_user_token(self):
Client().post(REGISTER, self.user_post)
test_user = User.objects.get(username=self.user_post["email"])
def get_client_from_user(self, user_dict):
Client().post(REGISTER, user_dict)
test_user = User.objects.get(username=user_dict['email'])
test_user.is_active = True
test_user.save()
token_response = Client().post(TOKEN_AUTH, {'username': self.user_post["email"],
'password': self.user_post["password"]})
token_response = Client().post(TOKEN_AUTH, {'username': user_dict["email"],
'password': user_dict["password"]})
content = json.loads(token_response.content.decode('utf-8'))
token = content['token']
client = Client(HTTP_AUTHORIZATION=TOKEN_SUFFIX+token)
return client
def client_user_token(self):
return self.get_client_from_user(self.user_post)
def client_user_token2(self):
Client().post(REGISTER, self.user_post)
test_user = User.objects.get(username=self.default_username_email)
test_user.is_active = True
test_user.save()
token_response = Client().post(TOKEN_AUTH, {'username': self.default_username_email,
'password': self.default_password})
content = json.loads(token_response.content.decode('utf-8'))
token = content['token']
client = Client(HTTP_AUTHORIZATION=TOKEN_SUFFIX+token)
return client
return self.get_client_from_user({'name': self.default_username_email,
'email': self.default_username_email,
'phone_number': self.default_no_telp,
'password': self.default_password})
class InformasiFasilitasViewTest(InformasiFasilitasTest):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment