Ejemplo n.º 1
0
    def test_get_chat_home_previous_conversations_received_message(self):
        self.client.login(username='******', password='******')
        current_profile = Profile.objects.get(user_id__username='******')
        receiver_profile = Profile.objects.get(user_id__username='******')
        # Make user premium
        current_profile.is_premium = True
        current_profile.save()
        subscription = Subscription(plan="monthly",
                                    customer_id="cus_FMdSeBRaEVZlmh",
                                    user_id=current_profile.user.id)
        subscription.save()

        # Create conversation and messages
        conversation = Conversations()
        conversation.save()
        conversation.participants.add(current_profile.user.id)
        conversation.participants.add(receiver_profile.user.id)
        message = Messages(message_content="foo",
                           is_read=False,
                           receiver_id=current_profile.user.id,
                           sender_id=receiver_profile.user.id,
                           conversation_id=conversation.id)
        message.save()

        page = self.client.get('/chat/home/')
        self.assertEqual(page.status_code, 200)
        self.assertTemplateUsed(page, 'chat_home.html')
Ejemplo n.º 2
0
    def test_get_cancel_sub(self):
        self.client.login(username='******', password='******')
        current_profile = Profile.objects.get(user_id__username='******')

        # Set premium status
        current_profile.is_premium = True
        current_profile.save()
        subscription = Subscription(plan="monthly",
                                    customer_id="cus_FMdSeBRaEVZlmh",
                                    user_id=current_profile.user.id)
        subscription.save()
        sub_id = 'sub_FMdVFN7OCb4D3O'

        # Test subscription is currently active
        active_subscription = stripe.Subscription.retrieve(sub_id)
        self.assertEqual(active_subscription.cancel_at_period_end, False)

        page = self.client.get('/my-account/cancel/%s' % sub_id)
        self.assertRedirects(page, reverse('account'), status_code=302)

        active_subscription = stripe.Subscription.retrieve(sub_id)
        self.assertNotEqual(active_subscription.cancel_at_period_end, False)

        # Resubscribe for subsequent tests
        stripe.Subscription.modify(sub_id, cancel_at_period_end=False)
Ejemplo n.º 3
0
    def test_post_chat_page(self):
        self.client.login(username='******', password='******')
        current_profile = Profile.objects.get(user_id__username='******')
        receiver_profile = User.objects.get(username='******')
        # Make user premium
        current_profile.is_premium = True
        current_profile.save()
        subscription = Subscription(plan="monthly",
                                    customer_id="cus_FMdSeBRaEVZlmh",
                                    user_id=current_profile.user.id)
        subscription.save()
        # Make conversation
        conversation = Conversations()
        conversation.save()
        conversation.participants.add(current_profile.user.id)
        conversation.participants.add(receiver_profile.id)

        page = self.client.post(
            reverse('chat', kwargs={'id': conversation.id}),
            {'message_content': 'foo'})

        self.assertTrue(Messages.objects.get(message_content='foo'))
        self.assertRedirects(page,
                             '/chat/%s' % conversation.id,
                             status_code=302)
Ejemplo n.º 4
0
    def test_ajax_message_conversation_exists(self):
        self.client.login(username='******', password='******')
        receiver_user = User.objects.get(username='******')
        current_user = User.objects.get(username='******')
        # Make user premium
        current_user.profile.is_premium = True
        current_user.profile.save()
        subscription = Subscription(plan="monthly",
                                    customer_id="cus_FMdSeBRaEVZlmh",
                                    user_id=current_user.id)
        subscription.save()

        # Create conversation
        conversation = Conversations()
        conversation.save()
        conversation.participants.add(current_user.id)
        conversation.participants.add(receiver_user.id)
        conversation.save()

        page = self.client.post(reverse('new_message'), {
            'message_receiver': receiver_user.id,
            'message_content': 'foo'
        }, **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'})

        response_content = page.content
        if six.PY3:
            response_content = str(response_content, encoding='utf8')

        message = Messages.objects.filter(message_content='foo',
                                          sender_id=current_user,
                                          receiver_id=receiver_user).exists()
        self.assertTrue(message)
        self.assertJSONEqual(response_content,
                             {'message': 'Message Successfully Sent'})
Ejemplo n.º 5
0
    def test_ajax_new_message_check(self):
        self.client.login(username='******', password='******')
        current_profile = Profile.objects.get(user_id__username='******')
        receiver_profile = User.objects.get(username='******')
        # Create conversation and messages
        conversation = Conversations()
        conversation.save()
        conversation.participants.add(current_profile.user.id)
        conversation.participants.add(receiver_profile.id)
        message = Messages(message_content="foo",
                           is_read=False,
                           receiver_id=current_profile.id,
                           sender_id=receiver_profile.id,
                           conversation_id=conversation.id)
        message.save()
        # Make user premium
        current_profile.is_premium = True
        current_profile.save()
        subscription = Subscription(plan="monthly",
                                    customer_id="cus_FMdSeBRaEVZlmh",
                                    user_id=current_profile.user.id)
        subscription.save()

        page = self.client.get(reverse('new_message_check'),
                               {'url_id': conversation.id},
                               **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'})

        response_content = page.content
        # https://stackoverflow.com/questions/27472663/how-to-use-djangos-assertjsonequal-to-verify-response-of-view-returning-jsonres
        if six.PY3:
            response_content = str(response_content, encoding='utf8')

        self.assertJSONEqual(response_content, {'conversation': True})
Ejemplo n.º 6
0
    def test_post_member_page_premium_user(self):
        visited_user = User.objects.get(username='******')
        current_user = User.objects.get(username='******')

        # Sexuality and gender options set to allow visit
        current_profile = Profile.objects.get(user_id=current_user.id)
        current_profile.looking_for = "MALE"
        current_profile.gender = "FEMALE"
        # Set premium status
        current_profile.is_premium = True
        current_profile.save()
        subscription = Subscription(plan="monthly",
                                    customer_id="cus_FMdSeBRaEVZlmh",
                                    user_id=current_user.id)
        subscription.save()

        visited_profile = Profile.objects.get(user_id=visited_user.id)
        visited_profile.looking_for = "FEMALE"
        visited_profile.gender = "MALE"
        visited_profile.save()

        self.client.login(username='******', password='******')
        page = self.client.post('/accounts/member/%s' % visited_user.id, {
            'message_content': 'foo',
            'message_submit': 'message_submit'
        })

        self.assertRedirects(page, '/chat/1', status_code=302)
Ejemplo n.º 7
0
 def test_get_chat_home_no_previous_conversations(self):
     self.client.login(username='******', password='******')
     current_profile = Profile.objects.get(user_id__username='******')
     # Make user premium
     current_profile.is_premium = True
     current_profile.save()
     subscription = Subscription(plan="monthly",
                                 customer_id="cus_FMdSeBRaEVZlmh",
                                 user_id=current_profile.user.id)
     subscription.save()
     page = self.client.get('/chat/home/')
     self.assertEqual(page.status_code, 200)
     self.assertTemplateUsed(page, 'chat_home.html')
Ejemplo n.º 8
0
    def test_ajax_read_view_premium(self):
        self.client.login(username='******', password='******')
        current_user = User.objects.get(username='******')
        # Make user premium
        current_user.profile.is_premium = True
        current_user.profile.save()
        subscription = Subscription(plan="monthly",
                                    customer_id="cus_FMdSeBRaEVZlmh",
                                    user_id=current_user.id)
        subscription.save()

        page = self.client.post(reverse('read_view'), {'page': 1},
                                **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'})

        self.assertEqual(page.status_code, 204)
Ejemplo n.º 9
0
    def test_chat_page(self):
        self.client.login(username='******', password='******')
        current_profile = Profile.objects.get(user_id__username='******')
        receiver_profile = User.objects.get(username='******')
        # Make user premium
        current_profile.is_premium = True
        current_profile.save()
        subscription = Subscription(plan="monthly",
                                    customer_id="cus_FMdSeBRaEVZlmh",
                                    user_id=current_profile.user.id)
        subscription.save()
        # Make conversation
        conversation = Conversations()
        conversation.save()
        conversation.participants.add(current_profile.user.id)
        conversation.participants.add(receiver_profile.id)

        page = self.client.get('/chat/%s' % conversation.id)
        self.assertEqual(page.status_code, 200)
        self.assertTemplateUsed(page, 'chat.html')