mirror of https://github.com/snachodog/mybuddy.git
Add tests, add username to api/profile endpoint
This commit is contained in:
parent
7424155ba4
commit
878ff64fad
|
@ -273,6 +273,7 @@ class WeightSerializer(CoreModelSerializer, TaggableSerializer):
|
||||||
|
|
||||||
class ProfileSerializer(serializers.ModelSerializer):
|
class ProfileSerializer(serializers.ModelSerializer):
|
||||||
api_key = serializers.SerializerMethodField("get_api_key")
|
api_key = serializers.SerializerMethodField("get_api_key")
|
||||||
|
username = serializers.SerializerMethodField("get_username")
|
||||||
first_name = serializers.SerializerMethodField("get_first_name")
|
first_name = serializers.SerializerMethodField("get_first_name")
|
||||||
last_name = serializers.SerializerMethodField("get_last_name")
|
last_name = serializers.SerializerMethodField("get_last_name")
|
||||||
email = serializers.SerializerMethodField("get_email")
|
email = serializers.SerializerMethodField("get_email")
|
||||||
|
@ -281,6 +282,9 @@ class ProfileSerializer(serializers.ModelSerializer):
|
||||||
def get_api_key(self, value):
|
def get_api_key(self, value):
|
||||||
return self.instance.api_key().key
|
return self.instance.api_key().key
|
||||||
|
|
||||||
|
def get_username(self, value):
|
||||||
|
return self.instance.user.username
|
||||||
|
|
||||||
def get_first_name(self, value):
|
def get_first_name(self, value):
|
||||||
return self.instance.user.first_name
|
return self.instance.user.first_name
|
||||||
|
|
||||||
|
@ -297,6 +301,7 @@ class ProfileSerializer(serializers.ModelSerializer):
|
||||||
model = babybuddy_models.Settings
|
model = babybuddy_models.Settings
|
||||||
fields = (
|
fields = (
|
||||||
"user",
|
"user",
|
||||||
|
"username",
|
||||||
"first_name",
|
"first_name",
|
||||||
"last_name",
|
"last_name",
|
||||||
"email",
|
"email",
|
||||||
|
|
29
api/tests.py
29
api/tests.py
|
@ -874,3 +874,32 @@ class WeightAPITestCase(TestBase.BabyBuddyAPITestCaseBase):
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
self.assertEqual(response.data, entry)
|
self.assertEqual(response.data, entry)
|
||||||
|
|
||||||
|
|
||||||
|
class TestProfileAPITestCase(APITestCase):
|
||||||
|
endpoint = reverse("api:profile")
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.client.login(username="admin", password="admin")
|
||||||
|
|
||||||
|
def test_get(self):
|
||||||
|
response = self.client.get(self.endpoint)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertDictContainsSubset(
|
||||||
|
{
|
||||||
|
"user": 1,
|
||||||
|
"username": "admin",
|
||||||
|
"first_name": "",
|
||||||
|
"last_name": "",
|
||||||
|
"email": "",
|
||||||
|
"staff": True,
|
||||||
|
"language": "en-US",
|
||||||
|
"timezone": "UTC",
|
||||||
|
},
|
||||||
|
response.data,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Test that api_key is in the mix and "some long string"
|
||||||
|
self.assertIn("api_key", response.data)
|
||||||
|
self.assertTrue(isinstance(response.data["api_key"], str))
|
||||||
|
self.assertGreater(len(response.data["api_key"]), 30)
|
||||||
|
|
|
@ -87,7 +87,7 @@
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-sm-2 col-form-label">{% trans "Login QR code" %}</label>
|
<label class="col-sm-2 col-form-label">{% trans "Login QR code" %}</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<div style="display:inline-block;background-color:white;">
|
<div style="display:inline-block;background-color:white;" data-qr-code-content="{{ qr_code_data }}">
|
||||||
{% qr_from_text qr_code_data size="s" %}
|
{% qr_from_text qr_code_data size="s" %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -52,6 +52,11 @@ class ViewsTestCase(TestCase):
|
||||||
page = self.c.get("/user/settings/")
|
page = self.c.get("/user/settings/")
|
||||||
self.assertEqual(page.status_code, 200)
|
self.assertEqual(page.status_code, 200)
|
||||||
|
|
||||||
|
self.assertRegex(
|
||||||
|
page.content.decode(),
|
||||||
|
r""".*<div [^>]* data-qr-code-content="[^"]+"[^>]*>.*""",
|
||||||
|
)
|
||||||
|
|
||||||
def test_user_views(self):
|
def test_user_views(self):
|
||||||
# Staff setting is required to access user management.
|
# Staff setting is required to access user management.
|
||||||
page = self.c.get("/users/")
|
page = self.c.get("/users/")
|
||||||
|
|
Loading…
Reference in New Issue