Beispiel #1
0
    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)
Beispiel #2
0
    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_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)
Beispiel #4
0
    def test_profile_details_no_profile(self):
        """
        Zakladajac, ze w systemie znajduje sie 1 uzytkownik z wypelnionym profilem i 1 bez
        Gdy uzytkownik z profilem wysle zadanie pobrania profilu drugiego uzytkownika
        To system zwroci blad
        """
        response = self.client.get('/api/profiles/{}/'.format(self.user2.id))

        expected_response = {'detail': 'Not found.'}
        self.assertEquals(expected_response, data_from(response))
        self.assertEquals(404, response.status_code)
Beispiel #5
0
    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)
Beispiel #6
0
    def test_post_list_on_profile_empty_list(self):
        """
        Zakladajac, ze znajduje sie 2 znajomych w systemie z wypelnionym profilem
        Gdy uzytkownik wysle zadanie pobrania tablicy drugiego uzytkownika
        To system zwroci pusta liste
        """
        self.client.credentials(
            HTTP_AUTHORIZATION='Token f09e9009b180d937552b9e52499d3dae6f6de059'
        )
        response = self.client.get('/api/users/{}/posts/'.format(self.user.id))

        expected_response = []
        self.assertEquals(expected_response, data_from(response)['results'])
        self.assertEquals(200, response.status_code)
Beispiel #7
0
    def test_request(self):
        """
        Zakladajac, ze w systemie znajduje sie uzytkownik z wypelnionym profilem
        Gdy uzytkownik wysle zadanie utworzenia wpisu o tresci `I ask for accomodation in Szczecin`
        To system utworzy wpis proszacy o nocleg w Szczecinie
        """
        response = self.client.post(
            '/api/posts/', {'content': 'I ask for accomodation in Szczecin'})

        expected_response = {'action': 'requested', 'place': 'Szczecin'}
        self.assertEquals(expected_response, data_from(response))
        self.assertEquals(200, response.status_code)
        self.assertEquals(Action.objects.count(), 1)
        self.assertEquals(Action.objects.first().verb, 'requested')
        self.assertEquals(Action.objects.first().data, None)
Beispiel #8
0
    def test_dream(self):
        """
        Zakladajac, ze w systemie znajduje sie uzytkownik z wypelnionym profilem
        Gdy uzytkownik wysle zadanie utworzenia wpisu o tresci `I want to go to Paris`
        To system utworzy wpis wyrazajacy chec wyjazdu do Paryza
        """
        response = self.client.post('/api/posts/',
                                    {'content': 'I want to go to Paris'})

        expected_response = {"action": "dreamed", "place": "Paris"}
        self.assertEquals(expected_response, data_from(response))
        self.assertEquals(200, response.status_code)
        self.assertEquals(Action.objects.count(), 1)
        self.assertEquals(Action.objects.first().verb, 'dreamed')
        self.assertEquals(Action.objects.first().data, None)
Beispiel #9
0
    def test_overrate(self):
        """
        Zakladajac, ze w systemie znajduje sie uzytkownik z wypelnionym profilem
        Gdy uzytkownik wysle zadanie utworzenia wpisu o tresci `I rate London in terms of atmosphere at 7`
        To system zwroci blad
        """
        response = self.client.post(
            '/api/posts/',
            {'content': 'I rate London in terms of atmosphere at 7'})

        expected_response = {
            'detail': 'Rating value should be between 1-5 stars.'
        }
        self.assertEquals(expected_response, data_from(response))
        self.assertEquals(400, response.status_code)
        self.assertEquals(Action.objects.count(), 0)
    def test_message_to_yourself(self):
        """
        Zakladajac, ze znajduje sie dwoch uzytkownikow w systemie z wypelnionym profilem
        Gdy uzytkownik wysle zadanie wyslania wiadomosci do siebie samego
        To system zwroci blad
        """
        response = self.client.post('/api/messages/', {
            'recipient': self.user.id,
            'content': 'Hello'
        })

        expected_response = {
            'recipient': ['you cannot send a message to yourself']
        }
        self.assertEquals(expected_response, data_from(response))
        self.assertEquals(400, response.status_code)
        self.assertEquals(Message.objects.count(), 0)
Beispiel #11
0
    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)
Beispiel #12
0
    def test_public_message(self):
        """
        Zakladajac, ze w systemie znajduje sie uzytkownik z wypelnionym profilem
        Gdy uzytkownik wysle zadanie utworzenia wpisu o tresci `Example content`
        To system utworzy publiczna wiadomosc o tresci `Example content`
        """
        response = self.client.post('/api/posts/',
                                    {'content': 'Example content'})

        expected_response = {
            "action": "published",
            "content": "Example content"
        }
        self.assertEquals(expected_response, data_from(response))
        self.assertEquals(200, response.status_code)
        self.assertEquals(Action.objects.count(), 1)
        self.assertEquals(Action.objects.first().verb, 'published')
        self.assertEquals(Action.objects.first().data,
                          {'content': 'Example content'})
    def test_message_reply(self):
        """
        Zakladajac, ze znajduje sie dwoch uzytkownikow w systemie z wypelnionym profilem i jedna konwersacja
        Gdy uzytkownik wysle zadanie wyslania wiadomosci w odpowiedzi na konwersacje
        To system wysle wiadomosc jako odpowiedz
        """
        self.message = Message.objects.create(sender=self.user,
                                              recipient=self.user2)

        response = self.client.post(
            '/api/messages/{}/reply/'.format(self.message.id),
            {'content': 'Hello'})

        expected_response = {'content': 'Hello'}
        self.assertEquals(expected_response, data_from(response))
        self.assertEquals(201, response.status_code)
        self.assertEquals(Message.objects.count(), 2)
        self.assertEquals(Message.objects.last().parent,
                          Message.objects.first())
Beispiel #14
0
    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)
Beispiel #15
0
    def test_user_logged(self):
        """
        Zakladajac, ze znajduje sie uzytkownik w systemie
        Gdy uzytkownik wysle zadanie pobrania informacji o zalogowanym uzytkowniku
        To system zwroci informacje o zalogowanym uzytkowniku
        """
        response = self.client.get('/api/users/logged/')

        expected_response = {
            'id': self.user.id,
            'first_name': 'Piotr',
            'last_name': 'Skowronek',
            'has_profile': False,
            'unread_messages_count': 0,
            'avatar': {
                'id': self.photo.id,
                'photo': {}
            }
        }
        self.assertEquals(expected_response, data_from(response))
        self.assertEquals(200, response.status_code)
Beispiel #16
0
    def test_text(self):
        """
        Zakladajac, ze w systemie znajduje sie 2 uzytkownikow z wypelnionym profilem
        Gdy uzytkownik wysle zadanie napisania publicznej wiadomosci do drugiego o tresci `Hello`
        To system utworzy publiczna wiadomosc do drugiego uzytkownika
        """
        self.user2 = mommy.make('User',
                                username='******',
                                is_active=True)
        mommy.make('Profile', user=self.user2)

        response = self.client.post(
            '/api/users/{}/public_message/'.format(self.user2.id),
            {'content': 'Hello'})

        expected_response = {'content': 'Hello'}
        self.assertEquals(expected_response, data_from(response))
        self.assertEquals(201, response.status_code)
        self.assertEquals(Action.objects.count(), 1)
        self.assertEquals(Action.objects.first().verb, 'texted')
        self.assertEquals(Action.objects.first().data, {'content': 'Hello'})
Beispiel #17
0
    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)
    def test_profile_incomplete(self):
        """
        Zakladajac, ze w systemie znajduje sie uzytkowik bez wypelnionego profilu
        Gdy gosc wysle zadanie edycji profilu nie podajac wszystkich pol
        To system zwroci blad
        """
        payload = {
            'about_me': 'about_me2',
            'places_been_to': 'places2',
        }
        response = self.client.put('/api/profiles/{}/'.format(self.user.id),
                                   payload)

        expected_response = {
            'best_things': ['This field is required.'],
            'why_like_travel': ['This field is required.']
        }

        self.assertEquals(expected_response, data_from(response))
        self.assertEquals(400, response.status_code)
        self.assertEquals(Profile.objects.count(), 0)
Beispiel #19
0
    def test_message_list_with_invitation(self):
        """
        Zakladajac, ze znajduje sie 3 uzytkownikow w systemie, 2 konwersacje i jedno zaproszenie
        Gdy uzytkownik wysle zadanie pobrania listy konwersacji
        To system zwroci liste konwersacji i zaproszenie
        """
        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)
        Message.objects.create(sender=self.user,
                               recipient=self.user2,
                               type=Message.TYPE_INVITATION)

        response = self.client.get('/api/messages/')

        expected_response = [{
            'is_read': True,
            'content': '',
            'type': 'invitation',
            'can_accept': False
        }, {
            '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)
Beispiel #20
0
    def test_rate(self):
        """
        Zakladajac, ze w systemie znajduje sie uzytkownik z wypelnionym profilem
        Gdy uzytkownik wysle zadanie utworzenia wpisu o tresci `I rate London in terms of atmosphere at 3`
        To system utworzy wpis oceniajacy Londyn
        """
        response = self.client.post(
            '/api/posts/',
            {'content': 'I rate London in terms of atmosphere at 3'})

        expected_response = {
            'action': 'rated',
            'place': 'London',
            'value': 3,
            'category': 'Atmosphere'
        }
        self.assertEquals(expected_response, data_from(response))
        self.assertEquals(200, response.status_code)
        self.assertEquals(Action.objects.count(), 1)
        self.assertEquals(Action.objects.first().verb, 'rated')
        self.assertEquals(Action.objects.first().data, {
            'rating': 3,
            'category': 'Atmosphere'
        })
Beispiel #21
0
    def test_post_stranger_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'})

        self.client.credentials(
            HTTP_AUTHORIZATION='Token f09e9009b180d937552b9e52499d3dae6f6de059'
        )
        response = self.client.get('/api/posts/')

        expected_response = []
        self.assertEquals(expected_response, data_from(response)['results'])
        self.assertEquals(200, response.status_code)