Exemplo n.º 1
0
    def setUp(self):
        super().setUp()
        self.company1 = CompanyFactory.create()
        self.user_company1 = UserFactory.create(post__company=self.company1)
        self.admin_company1 = UserFactory.create(
            post__company=self.company1, post__has_admin_rights=True
        )

        self.company2 = CompanyFactory.create()
        self.user_company2 = UserFactory.create(post__company=self.company2)
        self.admin_company2 = UserFactory.create(
            post__company=self.company2, post__has_admin_rights=True
        )
Exemplo n.º 2
0
 def setUp(self):
     super().setUp()
     self.company = CompanyFactory.create()
     self.team_leader = UserFactory.create(first_name="Tim",
                                           last_name="Leader",
                                           post__company=self.company)
     self.team_mates = [
         UserFactory.create(post__company=self.company,
                            first_name="Tim",
                            last_name="Mate") for i in range(0, 3)
     ]
     self.team = [self.team_leader] + self.team_mates
     self.team_ids = [u.id for u in self.team]
Exemplo n.º 3
0
def test_get_user_chats(auth_client):
    '''Test if user gets all chat he tooks part in'''
    users_count = random.randrange(1, 10)

    url = reverse('app:profile-list') + '?me=true'
    response = auth_client.get(url)
    user_profile = Profile.objects.get(id=response.data['id'])

    for i in range(users_count):
        user: User = UserFactory()
        profile: Profile = ProfileFactory(
            fname=user.first_name, 
            lname=user.last_name, 
            user=user,
            gender='F'
            )
        location: Location = LocationFactory(profile=profile)
        if i % 2 == 0:
            chat: Chat = ChatFactory(user1=user_profile, user2=profile)
        else:
            chat: Chat = ChatFactory(user1=profile, user2=user_profile)

    url = reverse('chat:chat-list')
    response = auth_client.get(url)

    assert response.status_code == 200
    assert len(response.data) == users_count
Exemplo n.º 4
0
def test_get_messages_from_chat(auth_client):
    '''Get messages from user specified chat test'''
    url = reverse('app:profile-list') + '?me=true'
    response = auth_client.get(url)
    user_profile = Profile.objects.get(id=response.data['id'])
    
    user: User = UserFactory()
    profile: Profile = ProfileFactory(
        fname=user.first_name, 
        lname=user.last_name, 
        user=user,
        gender='F'
        )
    location: Location = LocationFactory(profile=profile)

    chat: Chat = ChatFactory(user1=user_profile, user2=profile)

    messages_count = random.randint(1, 10)
    for i in range(messages_count):
        message = factory.Faker('sentence')
        if i % 2 == 0:
            user = user_profile
        else:
            user = profile
        message: Message = MessageFactory(message=message, sender=user, chat=chat)

    url = reverse('chat:chat-detail', kwargs={'pk':chat.id})
    response = auth_client.get(url)

    assert response.status_code == 200
    assert len(response.data) == messages_count
Exemplo n.º 5
0
def test_send_message(auth_client):
    '''
        Test whether user can send message
        and it's sent to correct chat
    '''
    url = reverse('app:profile-list') + '?me=true'
    response = auth_client.get(url)
    user_profile = Profile.objects.get(id=response.data['id'])
    
    user: User = UserFactory()
    profile: Profile = ProfileFactory(
        fname=user.first_name, 
        lname=user.last_name, 
        user=user,
        gender='F'
        )
    location: Location = LocationFactory(profile=profile)

    chat: Chat = ChatFactory(user1=user_profile, user2=profile)

    url = reverse('chat:chat-list')
    data = {'chat':chat.id, 'message':'Hello world!'}
    response = auth_client.post(url, data=data)

    assert response.status_code == 201
    assert response.data['sender']['id'] == user_profile.id
    assert response.data['chat']['id'] == chat.id
Exemplo n.º 6
0
def test_swipe_limit(auth_client):
    '''Test whether user cant swipe anymore according to his subscription limit'''
    url = reverse('app:profile-list') + '?me=true'
    response = auth_client.get(url)
    user_profile = Profile.objects.get(id=response.data['id'])

    limit = settings.BASIC_SUBSCRIPTION_SWIPES if user_profile.vip else settings.VIP_SUBSCRIBTION_SWIPES
    gender = 'F' if user_profile.gender == 'M' else 'M'
    last_profile = None
    for i in range(limit + 1):
        user: User = UserFactory()
        profile: Profile = ProfileFactory(fname=user.first_name,
                                          lname=user.last_name,
                                          user=user,
                                          gender=gender)
        location: Location = LocationFactory(profile=profile)
        if i == limit:
            last_profile = profile
            break
        swipe = SwipeFactory(profile=user_profile,
                             swiped=profile,
                             liked=random.choice([True, False]))

    url = reverse('activities:swipe-list')
    data = {'swiped': last_profile.id, 'liked': True}
    response = auth_client.post(url, data=data)

    assert response.status_code == 400
    assert response.data['detail'] == 'swipes limit is exceeded for today'
Exemplo n.º 7
0
def test_get_matches(auth_client):
    '''Test getting matches of current user'''
    url = reverse('app:profile-list') + '?me=true'
    response = auth_client.get(url)
    user_profile = Profile.objects.get(id=response.data['id'])

    user: User = UserFactory()
    profile: Profile = ProfileFactory(fname=user.first_name,
                                      lname=user.last_name,
                                      user=user,
                                      gender='F')
    location: Location = LocationFactory(profile=profile)

    swipe_user: Swipe = SwipeFactory(profile=user_profile,
                                     swiped=profile,
                                     liked=True)
    swipe: Swipe = SwipeFactory(profile=profile,
                                swiped=user_profile,
                                liked=True)

    url = reverse('activities:swipe-list')
    response = auth_client.get(url)

    assert (response.data[0]['profile']['id'] == profile.id
            and response.data[0]['swiped']['id'] == user_profile.id)
Exemplo n.º 8
0
    def setUp(self):
        super().setUp()
        self.user = UserFactory.create(password="******")
        self.login_query = """
            mutation ($email: String!, $password: String!) {
                    auth {
                        login (email: $email, password: $password) {
                            accessToken
                            refreshToken
                        }
                    }
                }
            """

        self.refresh_query = """
            mutation {
                    auth {
                        refresh {
                            accessToken
                            refreshToken
                        }
                    }
                }
            """

        self.check_query = """
Exemplo n.º 9
0
def auth_client():
    client = APIClient()
    user: User = UserFactory()
    profile: Profile = ProfileFactory(fname=user.first_name, lname=user.last_name, user=user)
    location: Location = LocationFactory(profile=profile)
    refresh = RefreshToken.for_user(user)
    client.credentials(HTTP_AUTHORIZATION=f'Bearer {refresh.access_token}')
    return client
Exemplo n.º 10
0
def test_get_matched_profile(auth_client):
    '''Getting info of matched and unmatched users'''
    url = reverse('app:profile-list') + '?me=true'
    response = auth_client.get(url)
    user_profile = Profile.objects.get(id=response.data['id'])

    user: User = UserFactory()
    profile: Profile = ProfileFactory(fname=user.first_name,
                                      lname=user.last_name,
                                      user=user,
                                      gender='F')
    location: Location = LocationFactory(profile=profile)

    swipe_user: Swipe = SwipeFactory(profile=user_profile,
                                     swiped=profile,
                                     liked=True)
    swipe: Swipe = SwipeFactory(profile=profile,
                                swiped=user_profile,
                                liked=True)

    url = reverse('app:profile-detail', kwargs={'pk': profile.id})
    response = auth_client.get(url)

    assert response.status_code == 200

    user_unmatched: User = UserFactory()
    profile_unmatched: Profile = ProfileFactory(fname=user.first_name,
                                                lname=user.last_name,
                                                user=user,
                                                gender='F')
    location_unmatched: Location = LocationFactory(profile=profile)

    url = reverse('app:profile-detail', kwargs={'pk': profile_unmatched.id})
    response = auth_client.get(url)

    assert response.status_code == 400
    assert response.data[
        'detail'] == 'user can\'t get info about unmatched profile'
Exemplo n.º 11
0
def test_already_swiped_user(auth_client):
    '''Test whether user already swiped user he wants to swipe now'''
    user: User = UserFactory()
    profile: Profile = ProfileFactory(fname=user.first_name,
                                      lname=user.last_name,
                                      user=user,
                                      gender='F')
    location: Location = LocationFactory(profile=profile)

    url = reverse('activities:swipe-list')
    data = {'swiped': profile.id, 'liked': True}
    response = auth_client.post(url, data=data)

    assert response.status_code == 201

    response_repeat = auth_client.post(url, data=data)

    assert response_repeat.status_code == 400
    assert response_repeat.data[
        'detail'] == 'user have already swiped this profile'
Exemplo n.º 12
0
def test_user_swipe(auth_client):
    '''User swipe test'''
    url = reverse('app:profile-list') + '?me=true'
    response = auth_client.get(url)
    id = response.data['id']

    user: User = UserFactory()
    profile: Profile = ProfileFactory(fname=user.first_name,
                                      lname=user.last_name,
                                      user=user,
                                      gender='F')
    location: Location = LocationFactory(profile=profile)

    url = reverse('activities:swipe-list')
    data = {'swiped': profile.id, 'liked': True}
    response = auth_client.post(url, data=data)

    assert response.status_code == 201
    assert response.data['swipe']['profile']['id'] == id
    assert response.data['swipe']['swiped']['id'] == profile.id
Exemplo n.º 13
0
def test_create_chat_on_match(auth_client):
    '''Test whether new chat created when users are matched'''
    url = reverse('app:profile-list') + '?me=true'
    response = auth_client.get(url)
    user_profile = Profile.objects.get(id=response.data['id'])
    
    user: User = UserFactory()
    profile: Profile = ProfileFactory(
        fname=user.first_name, 
        lname=user.last_name, 
        user=user,
        gender='F'
        )
    location: Location = LocationFactory(profile=profile)

    swipe: Swipe = SwipeFactory(profile=profile, swiped=user_profile, liked=True)

    url = reverse('activities:swipe-list')
    data = {'swiped':profile.id, 'liked':True} 
    response = auth_client.post(url, data=data)

    assert response.status_code == 201
    assert response.data['match'] == True
    assert Chat.objects.filter(user1=user_profile, user2=profile).count() == 1