def test_get_friend_list(self): self.author1 = createAuthor(self, 0) self.author2 = createAuthor(self, 1) self.author3 = createAuthor(self, 2) self.author1.friends.add(self.author2.id) response = self.client.post('/friends/%s/' % (self.author1.id), { "query": "abc", }, format='json') self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response) response = self.client.post( '/friends/%s/' % (self.author1.id), { "query": "friends", "author": self.author1.id, "authors": [self.author2.id, self.author3.id] }, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK, response) self.assertEqual("friends", response.data['query']) self.assertEqual(str(self.author1.id), str(response.data['author'])) self.assertEqual(1, len(response.data['authors'])) self.assertEqual(str(self.author2.id), str(response.data['authors'][0]))
def test_get_friends(self): self.author1 = createAuthor(self, 0) self.author2 = createAuthor(self, 1) self.author1.friends.add(self.author2.id) response = self.client.get('/friends/%s/' % (self.author1.id), {}, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK, response) self.assertEqual("friends", response.data['query']) self.assertEqual(self.author2.id, response.data['authors'][0])
def test_send_request(self): self.sender = createAuthor(self, 0) self.receiver = createAuthor(self, 1) response = self.client.post('/friendrequest/', { "query": "friendrequest", "author": { "id": self.sender.id, "host": self.sender.host, "displayName": self.sender.user.username, }, "friend": { "id": self.receiver.id, "host": self.receiver.host, "displayName": self.receiver.user.username, "url": self.receiver.host + "author/" + str(self.receiver.id) } }, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK, response) self.assertTrue( Author.objects.get( id=self.receiver.id).friend_request_received.all().filter( id=self.sender.id).exists()) self.assertTrue( Author.objects.get( id=self.sender.id).friend_request_sent.all().filter( id=self.receiver.id).exists()) response = self.client.post('/friendrequest/', { "query": "friendrequest", "author": { "id": self.sender.id, "host": self.sender.host, "displayName": self.sender.user.username, }, "friend": { "id": self.receiver.id, "host": self.receiver.host, "displayName": self.receiver.user.username, "url": self.receiver.host + "author/" + str(self.receiver.id) } }, format='json') self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response)
def test_update_author_profile(self): self.author = createAuthor(self, 0) response = self.client.put('/author/%s/' % self.author.id, { "displayName": "CoolBears", "first_name": "Cool", "last_name": "Bears", "email": "*****@*****.**", "bio": "I am a cool bear!", "host": "http://coolbears.com/mostCoolBear/", "github_username": "******", "password": "******" }, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK, response) updated_author = Author.objects.get(id=self.author.id) updated_user = updated_author.user self.assertEqual(updated_author.bio, "I am a cool bear!") self.assertEqual(updated_author.host, "http://coolbears.com/mostCoolBear/") self.assertEqual(updated_author.github_username, "https://github.com/coolbear") self.assertEqual(updated_user.username, "CoolBears") self.assertEqual(updated_user.first_name, "Cool") self.assertEqual(updated_user.last_name, "Bears") self.assertEqual(updated_user.email, "*****@*****.**") self.assertEqual(updated_user.password, "a1b2c3d4")
def test_get_author(self): self.author1 = createAuthor(self, 0) self.author2 = createAuthor(self, 1) self.author3 = createAuthor(self, 2) self.author1.friends.add(self.author2) self.author1.friends.add(self.author3) response = self.client.get('/author/%s/' % self.author1.id, {}, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK, response) self.assertEqual( getAuthor(self, 0)['username'], response.data['displayName']) self.assertEqual(str(self.author1.id), response.data['id']) self.assertEqual(str(self.author2.id), response.data['friends'][1]['id']) self.assertEqual(str(self.author3.id), response.data['friends'][0]['id'])
def test_unfriend(self): self.sender = createAuthor(self, 0) self.receiver = createAuthor(self, 1) self.sender.friends.add(self.receiver) response = self.client.post('/friendrequest/', { "query": "unfriend", "author": { "id": self.sender.id }, "friend": { "id": self.receiver.id }, "accepted": 'true' }, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK, response) self.assertTrue( Author.objects.get(id=self.receiver.id).friends.all().filter( id=self.sender.id).exists() == False) self.assertTrue( Author.objects.get(id=self.sender.id).friends.all().filter( id=self.receiver.id).exists() == False)
def setUp(self): self.author = createAuthor(self, 0)