def test_message(self): """ Zakladajac, ze znajduje sie dwoch uzytkownikow w systemie z wypelnionym profilem Gdy uzytkownik wysle zadanie wyslania wiadomosci do drugiego uzytkownika To system wysle wiadomosc """ response = self.client.post('/api/messages/', { 'recipient': self.user2.id, 'content': 'Hello' }) expected_response = { 'is_read': True, 'content': 'Hello', 'type': 'message', 'sender': { 'first_name': '', 'last_name': '', 'avatar': None }, 'conversation_partner': { 'email': '', 'first_name': '', 'last_name': '', 'avatar': None, 'relationship_status': 'not_exists' }, 'can_accept': False } self.assertEquals( expected_response, cleaned(data_from(response), fields=['id', 'created_date'])) self.assertEquals(201, response.status_code) self.assertEquals(Message.objects.count(), 1)
def test_album_edit(self): """ Zakladajac, ze w systemie znajduje sie uzytkownik z wypelnionym profilem i albumem Gdy uzytkownik wysle zadanie edycji albumu To system edytuje album """ self.album = mommy.make('Album', user=self.user, name='album', place=Place.objects.create(city='place')) photo = mommy.make('Photo', is_thumbnail=True) photo2 = mommy.make('Photo', is_thumbnail=False) self.album.photos = [photo, photo2] self.album.save() response = self.client.put('/api/albums/{}/'.format(self.album.id), { 'place': 'Paris', 'name': 'Name', 'photos': [photo.id] }) expected_response = { 'place': 'Paris', 'name': 'Name', 'photos_readable': [{ 'photo': {} }] } self.assertEquals(expected_response, cleaned(data_from(response), fields=['id'])) self.assertEquals(200, response.status_code) self.assertEquals(Album.objects.count(), 1)
def test_album(self): """ Zakladajac, ze w systemie znajduje sie uzytkownik z wypelnionym profilem Gdy uzytkownik wysle zadanie utworzenia albumu To system utworzy album """ photo = mommy.make('Photo', is_thumbnail=False) photo2 = mommy.make('Photo', is_thumbnail=False) response = self.client.post('/api/albums/', { 'place': 'Paris', 'name': 'Name', 'photos': [photo.id, photo2.id] }) expected_response = { 'place': 'Paris', 'name': 'Name', 'photos_readable': [{ 'photo': {} }, { 'photo': {} }] } self.assertEquals(expected_response, cleaned(data_from(response), fields=['id'])) self.assertEquals(201, response.status_code) self.assertEquals(Album.objects.count(), 1)
def test_message_details(self): """ Zakladajac, ze znajduje sie 2 uzytkownikow w systemie i 2 konwersacje Gdy uzytkownik wysle zadanie pobrania podgladu konwersacji To system zwroci podglad konwersacji """ response = self.client.get('/api/messages/{}/'.format(self.message.id)) expected_response = [{ 'is_read': True, 'content': '', 'type': 'message', 'can_accept': False }, { 'is_read': True, 'content': '', 'type': 'message', 'can_accept': False }] self.assertEquals( expected_response, cleaned(data_from(response), fields=[ 'id', 'created_date', 'modified_date', 'sender', 'conversation_partner' ])) self.assertEquals(200, response.status_code)
def test_profile_edition(self): """ Zakladajac, ze w systemie znajduje sie uzytkowik z wypelnionym profilem Gdy gosc wysle zadanie edycji profilu To system edytuje profil """ mommy.make('Profile', user=self.user, best_things='best_things', about_me='about_me', why_like_travel='like', places_been_to='places') payload = { 'about_me': 'about_me2', 'places_been_to': 'places2', 'why_like_travel': 'like2', 'best_things': 'things2' } response = self.client.put('/api/profiles/{}/'.format(self.user.id), payload) expected_response = { 'about_me': 'about_me2', 'places_been_to': 'places2', 'why_like_travel': 'like2', 'best_things': 'things2' } self.assertEquals( expected_response, cleaned(data_from(response), fields=['created_date', 'modified_date', 'id'])) self.assertEquals(200, response.status_code) self.assertEquals(Profile.objects.count(), 1)
def test_register(self): """ Zakladajac, ze system jest pusty Gdy gosc wysle zadanie utworzenia nowego konta To system utworzy konto """ self.assertEquals(User.objects.count(), 0) payload = { 'first_name': 'Imie', 'last_name': 'Nazwisko', 'email': '*****@*****.**', 'password': '******' } response = self.client.post('/api/users/', payload) expected_response = { 'email': '*****@*****.**', 'first_name': 'Imie', 'last_name': 'Nazwisko', 'avatar': None, 'relationship_status': 'not_logged_in' } self.assertEquals(expected_response, cleaned(data_from(response), fields=['id'])) self.assertEquals(201, response.status_code) self.assertEquals(User.objects.count(), 1)
def test_photo_upload(self): """ Zakladajac, ze w systemie znajduje sie uzytkownik z wypelnionym profilem Gdy uzytkownik wysle zadanie przekazania obrazu To system utworzy obraz """ image = Image.new('RGB', (100, 100)) tmp_file = tempfile.NamedTemporaryFile(suffix='.jpg') image.save(tmp_file) tmp_file.seek(0) response = self.client.post('/api/photos/', {'photo': tmp_file}, format='multipart') filename = os.path.splitext(os.path.basename(tmp_file.name))[0] expected_response = { 'photo': { 'thumbnail': 'http://testserver/media/__sized__/photos/{}-crop-c0-5__0-5-200x200-90.jpg' .format(filename), 'full_size': 'http://testserver/media/photos/{}.jpg'.format(filename) } } self.assertEquals(expected_response, cleaned(data_from(response), fields=['id'])) self.assertEquals(201, response.status_code) self.assertEquals(Photo.objects.count(), 1)
def test_profile(self): """ Zakladajac, ze w systemie znajduje sie uzytkowik bez wypelnionego profilu Gdy gosc wysle zadanie utworzenia profilu To system utworzy profil """ payload = { 'about_me': 'about_me', 'places_been_to': 'places', 'why_like_travel': 'like', 'best_things': 'things' } response = self.client.put('/api/profiles/{}/'.format(self.user.id), payload) expected_response = { 'about_me': 'about_me', 'places_been_to': 'places', 'why_like_travel': 'like', 'best_things': 'things' } self.assertEquals( expected_response, cleaned(data_from(response), fields=['created_date', 'modified_date', 'id'])) self.assertEquals(201, response.status_code) self.assertEquals(Profile.objects.count(), 1)
def test_message_list(self): """ Zakladajac, ze znajduje sie 3 uzytkownikow w systemie i 2 konwersacje Gdy uzytkownik wysle zadanie pobrania listy konwersacji To system zwroci liste konwersacji """ prnt = Message.objects.create(sender=self.user, recipient=self.user2) Message.objects.create(sender=self.user, recipient=self.user2, parent=prnt) Message.objects.create(sender=self.user, recipient=self.user2) response = self.client.get('/api/messages/') expected_response = [{ 'is_read': True, 'content': '', 'type': 'message', 'can_accept': False }, { 'is_read': True, 'content': '', 'type': 'message', 'can_accept': False }] self.assertEquals( expected_response, cleaned(data_from(response)['results'], fields=[ 'id', 'created_date', 'sender', 'conversation_partner' ])) self.assertEquals(200, response.status_code)
def test_album_list_on_profile(self): """ Zakladajac, ze znajduje sie 2 uzytkownikow w systemie i 2 albumy Gdy uzytkownik wysle zadanie pobrania listy albumow nalezacych do drugiego uzytkownika To system zwroci liste albumow """ self.client.credentials( HTTP_AUTHORIZATION='Token f09e9009b180d937552b9e52499d3dae6f6de059' ) response = self.client.get('/api/users/{}/albums/'.format( self.user.id)) expected_response = [{ 'place': 'London', 'name': 'drugi', 'photos_readable': [] }, { 'place': 'Paris', 'name': 'pierwszy', 'photos_readable': [] }] self.assertEquals(expected_response, cleaned(data_from(response), fields=['id'])) self.assertEquals(200, response.status_code)
def test_profile_details(self): """ Zakladajac, ze znajduje sie 2 uzytkownikow w systemie z wypelnionym profilem Gdy uzytkownik wysle zadanie pobrania profilu drugiego uzytkownika To system zwroci profil uzytkownika """ mommy.make('Profile', user=self.user2, about_me='about_me', places_been_to='places', best_things='things', why_like_travel='like') response = self.client.get('/api/profiles/{}/'.format(self.user2.id)) expected_response = { 'about_me': 'about_me', 'places_been_to': 'places', 'why_like_travel': 'like', 'best_things': 'things' } self.assertEquals( expected_response, cleaned(data_from(response), fields=['created_date', 'modified_date', 'id'])) self.assertEquals(200, response.status_code)
def test_post_list_on_profile(self): """ Zakladajac, ze znajduje sie 2 znajomych w systemie z wypelnionym profilem i jeden wpis Gdy uzytkownik wysle zadanie pobrania tablicy drugiego uzytkownika To system zwroci liste zawierajaca post uzytkownika """ self.uct = ContentType.objects.get_for_model(self.user) mommy.make('Action', actor_object_id=self.user.id, actor_content_type=self.uct, verb='published', public=True, target_object_id=self.user.id, target_content_type=self.uct, data={'content': 'Hello'}) self.client.credentials( HTTP_AUTHORIZATION='Token f09e9009b180d937552b9e52499d3dae6f6de059' ) response = self.client.get('/api/users/{}/posts/'.format(self.user.id)) expected_response = [{ 'verb': 'published', 'data': { 'content': 'Hello' } }] self.assertEquals( expected_response, cleaned(data_from(response)['results'], fields=['id', 'actor', 'target', 'timestamp'])) self.assertEquals(200, response.status_code)
def test_user_list(self): """ Zakladajac, ze znajduje sie 5 uzytkownikow w systemie z wypelnionym profilem Gdy uzytkownik wysle zadanie pobrania listy uzytkownikow podajac fraze znajdujaca sie w profilu 2 uzytkownikow To system zwroci liste skladajaca sie z tych 2 uzytkownikow """ response = self.client.get('/api/users/?query=phrase') expected_response = [{ "first_name": "Adam", "last_name": "", "profile": { "about_me": "contains phrase here" }, "avatar": None }, { "first_name": "Adam", "last_name": "", "profile": { "about_me": "test" }, "avatar": None }] self.assertEquals( expected_response, cleaned(data_from(response)['results'], fields=['id'])) self.assertEquals(200, response.status_code)
def test_user_list_label(self): """ Zakladajac, ze znajduje sie 5 uzytkownikow w systemie z wypelnionym profilem Gdy uzytkownik wysle zadanie pobrania listy uzytkownikow podajac fraze pasujaca do imienia badz nazwiska 2 uzytkownikow To system zwroci liste skladajaca sie z tych 2 uzytkownikow """ response = self.client.get('/api/users/?label=Ada') expected_response = [{"label": "Adam "}, {"label": "Adam "}] self.assertEquals( expected_response, cleaned(data_from(response)['results'], fields=['value'])) self.assertEquals(200, response.status_code)
def test_post_friend_list(self): """ Zakladajac, ze znajduje sie 2 znajomych w systemie z wypelnionym profilem i jeden wpis Gdy znajomy autora wpisu wysle zadanie pobrania indywidualnej tablicy To system zwroci liste zawierajaca post uzytkownika """ self.uct = ContentType.objects.get_for_model(self.user) mommy.make('Action', actor_object_id=self.user.id, actor_content_type=self.uct, verb='published', public=True, target_object_id=self.user.id, target_content_type=self.uct, data={'content': 'Hello'}) mommy.make('Relationship', initiator=self.user, recipient=self.user2, status=Relationship.STATUS_ACCEPTED) mommy.make('Follow', user=self.user, content_type=self.uct, object_id=self.user2.id) mommy.make('Follow', user=self.user2, content_type=self.uct, object_id=self.user.id) self.client.credentials( HTTP_AUTHORIZATION='Token f09e9009b180d937552b9e52499d3dae6f6de059' ) response = self.client.get('/api/posts/') expected_response = [{ 'verb': 'published', 'data': { 'content': 'Hello' } }] self.assertEquals( expected_response, cleaned(data_from(response)['results'], fields=['id', 'actor', 'target', 'timestamp'])) self.assertEquals(200, response.status_code)
def test_album_list(self): """ Zakladajac, ze znajduje sie 2 uzytkownikow w systemie i 2 albumy Gdy uzytkownik wysle zadanie pobrania listy albumow To system zwroci liste albumow """ response = self.client.get('/api/albums/') expected_response = [{ 'place': 'London', 'name': 'drugi', 'photos_readable': [] }, { 'place': 'Paris', 'name': 'pierwszy', 'photos_readable': [] }] self.assertEquals(expected_response, cleaned(data_from(response), fields=['id'])) self.assertEquals(200, response.status_code)
def test_album_details(self): """ Zakladajac, ze znajduje sie uzytkownik w systemie i 1 album z 2 obrazami Gdy uzytkownik wysle zadanie pobrania podgladu albumu To system zwroci podglad albumu """ response = self.client.get('/api/albums/{}/'.format(self.album.id)) expected_response = { 'place': None, 'name': 'album', 'photos_readable': [{ 'photo': {} }, { 'photo': {} }] } self.assertEquals(expected_response, cleaned(data_from(response), fields=['id'])) self.assertEquals(200, response.status_code)