From 129064c0b71b1f34dd64faf9f8b39b6aa80264ce Mon Sep 17 00:00:00 2001 From: Harsh Singh Date: Mon, 8 Mar 2021 03:35:14 +0530 Subject: [PATCH] Update README.md --- README.md | 4 ++-- osp/utils/zulip_api.py | 9 ++++++--- tests/test_api_user_info.py | 7 ++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0e2084f..dffbd86 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Make sure you have installed the following: Next follow these instructions. -1.1 **Database Setup:** Before starting with the project create a db in you local using PostgreSQL with the following details. Refer to `main/settings.py` if you have any confusion. +1. **Database Setup:** Before starting with the project create a db in you local using PostgreSQL with the following details. Refer to `main/settings.py` if you have any confusion. ``` NAME: osp @@ -139,7 +139,7 @@ export SENDGRID_API_KEY= ## Testing **Test Database:** - You may run the following commands: + For creating a database while testing you have to give database creation permission to user `osp`. You may run the following commands: ``` cd open-source-programs-backend diff --git a/osp/utils/zulip_api.py b/osp/utils/zulip_api.py index 916b160..95cc2b1 100644 --- a/osp/utils/zulip_api.py +++ b/osp/utils/zulip_api.py @@ -3,14 +3,17 @@ # By default the API key file you download is named as 'download' by Zulip. You can place # this file one directory previous to the cuurent directory your file is in -def get_self_zulip_id(): - result = client.get_profile() - return result["user_id"] def get_client(): return Client(config_file="download") +def get_self_zulip_id(): + client = get_client() + result = client.get_profile() + return result["user_id"] + + def get_zulip_user(zulip_id: int) -> dict: """Takes the zulip user ID as an argument and returns a dictionary containing basic data on the Zulip user associated with that id diff --git a/tests/test_api_user_info.py b/tests/test_api_user_info.py index 0396b32..d398bdf 100644 --- a/tests/test_api_user_info.py +++ b/tests/test_api_user_info.py @@ -1,6 +1,7 @@ from django.contrib.auth import get_user_model from rest_framework import status from rest_framework.test import APIClient, APITestCase + from osp.utils.zulip_api import get_self_zulip_id User = get_user_model() @@ -58,12 +59,12 @@ def test_get_user_info_successfully(self): body = {"name": "Test User 1 Full Name", "user_type": "admin", "zulip_id": self.zulip_id} response = self.client.post("http://localhost:8000/api/info/", body, format="json") self.assertEqual(response.status_code, status.HTTP_201_CREATED) - self.assertNotEqual(response.data,[]) - + self.assertNotEqual(response.data, []) + response = self.client.get("http://localhost:8000/api/info/", format="json") response.data = response.data[0] self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertNotEqual(response.data,[]) + self.assertNotEqual(response.data, []) self.assertEqual(response.data["name"], body["name"]) self.assertEqual(response.data["user_type"], body["user_type"]) self.assertEqual(response.data["zulip_id"], body["zulip_id"])