Commit 1912099a authored by Erlend Ydse's avatar Erlend Ydse
Browse files

Merge branch 'fix-profile' into 'master'

Fix profile

See merge request !4
parents a3c0b2ab 6fb7450c
Pipeline #117171 passed with stages
in 2 minutes and 58 seconds
......@@ -129,7 +129,6 @@ class UserRegistration2WayDomainTests(APITestCase):
self.assertEquals((status_code == 201), validity)
except AssertionError as e:
failures.append({ first_field.name: first_field.value, second_field.name: second_field.value, "error": e })
print(failures)
print(len(failures))
self.assertEqual(len(failures), 0)
\ No newline at end of file
......@@ -45,19 +45,19 @@ class EditProfileAPITests(APITestCase):
img.save("test.jpg")
with open("test.jpg", "rb") as f:
data = { "profile_image": f }
response = self.client.patch(path=f"{self.path}{self.alice_data['id']}/", data=data)
response = self.client.put(path=f"{self.path}{self.alice_data['id']}/", data=data)
self.assertEqual(response.status_code, 200)
self.assertContains(response=response, text="test.jpg")
img = Image.new(mode="RGB", size=(400, 400), color=(255, 0, 0))
img.save("test2.jpg")
with open("test2.jpg", "rb") as f:
data = { "profile_image": f }
response = self.client.patch(path=f"{self.path}{self.alice_data['id']}/", data=data)
response = self.client.put(path=f"{self.path}{self.alice_data['id']}/", data=data)
self.assertEqual(response.status_code, 200)
self.assertContains(response=response, text="test2.jpg")
def test_edit_bio(self):
data = { "bio": "hello", "athletes": self.alice_data['athletes'] }
response = self.client.patch(path=f"{self.path}{self.alice_data['id']}/", data=data)
response = self.client.put(path=f"{self.path}{self.alice_data['id']}/", data=data)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["bio"], "hello")
\ No newline at end of file
......@@ -54,16 +54,16 @@ class FriendRequestAPITests(APITestCase):
def test_can_add_friends(self):
data = { "symmetric_friends": self.bob_data['id'] }
response = self.client.patch(path=f"{self.path}{self.alice_data['id']}/", data=data)
response = self.client.put(path=f"{self.path}{self.alice_data['id']}/", data=data)
data = { "symmetric_friends": self.clair_data['id'] }
response = self.client.patch(path=f"{self.path}{self.alice_data['id']}/", data=data)
response = self.client.put(path=f"{self.path}{self.alice_data['id']}/", data=data)
self.assertEqual(len(response.data["symmetric_friends"]), 2)
def test_can_add_and_view_friends(self):
data = { "symmetric_friends": self.bob_data['id'] }
response = self.client.patch(path=f"{self.path}{self.alice_data['id']}/", data=data)
response = self.client.put(path=f"{self.path}{self.alice_data['id']}/", data=data)
data = { "symmetric_friends": self.clair_data['id'] }
response = self.client.patch(path=f"{self.path}{self.alice_data['id']}/", data=data)
response = self.client.put(path=f"{self.path}{self.alice_data['id']}/", data=data)
self.assertEqual(len(response.data["symmetric_friends"]), 2)
response = self.client.get(path=f"{self.path}{self.alice_data['id']}/")
self.assertEqual(len(response.data["symmetric_friends"]), 2)
......
......@@ -100,7 +100,8 @@ class UserPutSerializer(serializers.ModelSerializer):
if "profile_image" in validated_data:
instance.profile_image = validated_data["profile_image"]
if "symmetric_friends" in validated_data:
instance.symmetric_friends.add(validated_data["symmetric_friends"][0])
if len(validated_data["symmetric_friends"]) > 0:
instance.symmetric_friends.add(validated_data["symmetric_friends"][0])
return instance
......
......@@ -83,7 +83,7 @@ class UserDetail(
return self.update(request, *args, **kwargs)
def patch(self, request, *args, **kwargs):
self.serializer_class = UserPutSerializer
#self.serializer_class = UserPutSerializer
return self.partial_update(request, *args, **kwargs)
......
......@@ -166,7 +166,7 @@ function renderSearchResult(friends) {
a.href = `profile.html?id=${friend.id}`;
const button = divFriendRequest.querySelector("button");
button.addEventListener("click", () => addFriend(friend.id));
button.addEventListener("click", () => addFriend(friend.url));
container.appendChild(cloneFriendRequest);
});
......
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