Exemplo n.º 1
0
    def test_existing_invitation(self):
        email = '*****@*****.**'
        self.contact = Contact.objects.create(user=self.test_healer.user,
                                              name='test',
                                              email=email)
        SiteJoinInvitation.objects.create(from_user=self.test_healer.user,
                                          contact=self.contact,
                                          status="2",
                                          confirmation_key="testkey")

        data = {'emails': email, 'message': 'test message'}
        response = self.rest_client.post(reverse('send_invite'),
                                         {'data': urllib.urlencode(data)})
        response = json.loads(response.content)
        self.assertFalse(response['reload_page'])
        invitations = SiteJoinInvitation.objects.filter(contact=self.contact)
        self.assertEqual(invitations.count(), 1)
        self.assertEqual(invitations[0].confirmation_key, 'testkey')

        email = get_email()
        self.assertNotEqual(email.subject.find('has added you as a Client'),
                            -1)
        self.assertNotEqual(email.body.find(data['message']), -1)

        self.test_healer = Healer.objects.get(pk=self.test_healer.pk)
        self.assertEqual(self.test_healer.invite_message, data['message'])
Exemplo n.º 2
0
	def test_add_post(self):
		self.test_healer.ratings_1_star = 0
		self.test_healer.ratings_2_star = 0
		self.test_healer.ratings_3_star = 2
		self.test_healer.ratings_4_star = 2
		self.test_healer.ratings_5_star = 2
		self.test_healer.ratings_average = 4
		self.test_healer.save()

		response = self.client.post(
			reverse('review_form', args=[self.username]),
			{'title': 'Test'*2, 'review': 'Test'*5, 'rating': 5})

		self.assertEqual(response.status_code, 302)

		review = Review.objects.get(title='Test'*2, review='Test'*5)
		self.assertEqual(review.reviewer, self.test_client)
		self.assertEqual(review.healer, self.test_healer)
		self.assertEqual(review.rating, 5)

		self.test_healer = Healer.objects.get(pk=1)
		self.assertEqual(self.test_healer.ratings_5_star, 3)
		self.assertEqual(
			'%.2f' % self.test_healer.ratings_average,
			'%.2f' % (float(29)/7))

		self.assertEqual(count_emails(), 1)
		self.assertEqual(
			get_email().subject,
			'You have a new review on HealerSource!')
Exemplo n.º 3
0
 def _ls_users(self, stanza):
     """ 列出成员 """
     frm = stanza.from_jid
     femail = get_email(frm)
     members = get_members_info()
     onlinebody = []
     offlinebody = []
     els = []
     for m in members:
         email = m.get("email")
         if email in els:
             continue
         els.append(email)
         if email == femail:
             r = "**{0}".format(m.get("nick"))
             onlinebody.append(r)
         elif m.get("isonline"):
             r = "*{0}".format(m.get("nick"))
             if m.get("status"):
                 r += " " + m.get("status")
             onlinebody.append(r)
         else:
             r = "  " + m.get("nick")
             offlinebody.append(r)
     onlinebody = sorted(onlinebody, key=lambda k: k.decode("utf-8")[1], reverse=False)
     offlinebody = sorted(offlinebody, key=lambda k: k.decode("utf-8")[1], reverse=False)
     body = []
     body.insert(0, "Pythoner Club 所有成员(** 表示你自己, * 表示在线):")
     body.extend(onlinebody)
     body.extend(offlinebody)
     online_num = len(onlinebody)
     total = online_num + len(offlinebody)
     body.append("共列出 {0} 位成员 {1} 位在线".format(total, online_num))
     self._send_cmd_result(stanza, "\n".join(body))
     return
Exemplo n.º 4
0
    def _run_cmd(self, stanza, body):
        """ 执行命令 """
        cmd = body[1:]
        c, args = self._parse_args(cmd)
        email = get_email(stanza.from_jid)
        cmds = [v.get("name") for v in self._get_cmd()]
        cmds.append("_ping")
        cmds.append("_tq")
        if c not in cmds:
            self._message_bus.send_all_msg(stanza, body)
            return
        try:
            self._logger.info("%s run cmd %s", email, c)
            m = getattr(self, c)(stanza, *args)
        except Exception as e:
            self._logger.warning(e.message)
            errorinfo = traceback.format_exc()
            body = u"{0} run command {1} happend an error:\
                    {2}".format(
                get_nick(email), c, errorinfo
            )
            self._message_bus.send_to_admin(stanza, body)
            self._message_bus.send_back_msg(stanza, c + " 命令异常,已通知管理员")
            return

        return m
Exemplo n.º 5
0
    def test_post_invite_only(self):
        message = 'test message'
        data = {
            'email_list': '*****@*****.**',
            'message': message,
            'invite_type': 'provider',
            'invite_provider_recommend': 'false',
            'postcard_background': PostcardBackgroundField().choices[0][0]
        }
        response = self.client.post(reverse('invite_postcard'), data)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(SiteJoinInvitation.objects.all()[0].create_friendship,
                         False)
        email = get_email()
        self.assertTrue('has invited you' in email.subject)
Exemplo n.º 6
0
    def test_new_email(self):
        data = {'emails': '*****@*****.**', 'message': 'test message'}
        response = self.rest_client.post(reverse('send_invite'),
                                         {'data': urllib.urlencode(data)})
        response = json.loads(response.content)
        self.assertFalse(response['reload_page'])
        self.assertEqual(
            Contact.objects.filter(email=data['emails']).count(), 1)
        self.assertEqual(
            SiteJoinInvitation.objects.filter(
                contact__email=data['emails']).count(), 1)

        email = get_email()
        self.assertNotEqual(email.subject.find('has added you as a Client'),
                            -1)
        self.assertNotEqual(email.body.find(data['message']), -1)

        self.test_healer = Healer.objects.get(pk=self.test_healer.pk)
        self.assertEqual(self.test_healer.invite_message, data['message'])
Exemplo n.º 7
0
    def test_post_invite_only_skip_for_client(self):
        message = 'test message'
        data = {
            'email_list': '*****@*****.**',
            'message': message,
            'invite_type': 'client',
            'invite_provider_recommend': 'true',
            'postcard_background': PostcardBackgroundField().choices[0][0]
        }
        response = self.client.post(reverse('invite_postcard'), data)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(SiteJoinInvitation.objects.all()[0].create_friendship,
                         True)
        email = get_email()
        self.assertTrue('has added you' in email.subject)
        message = str(email.message())
        self.assertTrue('To accept this invitation' in message)
        self.assertTrue('To accept this invitation, click here' in message)
Exemplo n.º 8
0
    def test_invite_view_post_existing_email(self):
        existing_user = Healer.objects.get(pk=3).user
        EmailAddress.objects.create(user=existing_user,
                                    email=existing_user.email,
                                    verified=True)
        self.emails.append(existing_user.email)

        data = {
            'emails': ';'.join(self.emails),
            'message': 'test',
            'invite_type': 'client'
        }
        response = self.client.post(reverse('invite_to_join'), data)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            Contact.objects.filter(email__in=self.emails).count(), 3)

        email = get_email()
        self.assertTrue('has added you as a Client' in email.subject)
Exemplo n.º 9
0
    def test_post_ambassador(self):
        message = 'test message'
        data = {
            'email_list': '*****@*****.**',
            'message': message,
            'invite_type': 'client',
            'postcard_background': PostcardBackgroundField().choices[0][0]
        }
        response = self.client.post(reverse('invite_postcard_ambassador'),
                                    data)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(SiteJoinInvitation.objects.all()[0].create_friendship,
                         True)
        email = get_email()
        self.assertTrue('has invited you to join' in email.subject)
        message = str(email.message())
        self.assertTrue(
            reverse('ambassador:signup', args=[self.test_healer.user.username])
            in message)
Exemplo n.º 10
0
    def test_post_review(self):
        message = 'test message'
        data = {
            'email_list': '*****@*****.**',
            'message': message,
            'invite_type': 'client',
            'postcard_background': PostcardBackgroundField().choices[0][0]
        }
        response = self.client.post(reverse('invite_postcard_review'), data)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(SiteJoinInvitation.objects.all()[0].create_friendship,
                         True)
        email = get_email()
        self.assertTrue('Please write a Review for' in email.subject)
        message = str(email.message())
        self.assertFalse('To accept this invitation' in message)
        self.assertTrue(
            'To write a review for %s, click here' %
            title(self.test_healer.user.get_full_name()) in message)
Exemplo n.º 11
0
 def _ls_channel_users(self, stanza):
     channel = get_info("channel", stanza.from_jid)
     channel = channel if channel else "main"
     frm = stanza.from_jid
     femail = get_email(frm)
     members = get_members_info()
     onlinebody = []
     offlinebody = []
     els = []
     for m in members:
         email = m.get("email")
         ch = get_info("channel", email)
         ch = ch if ch else "main"
         if ch != channel:
             continue
         if email in els:
             continue
         els.append(email)
         if email == femail:
             r = "**{0}".format(m.get("nick"))
             onlinebody.append(r)
         elif m.get("isonline"):
             r = "*{0}".format(m.get("nick"))
             if m.get("status"):
                 r += " " + m.get("status")
             onlinebody.append(r)
         else:
             r = "  " + m.get("nick")
             offlinebody.append(r)
     onlinebody = sorted(onlinebody, key=lambda k: k.decode("utf-8")[1], reverse=False)
     offlinebody = sorted(offlinebody, key=lambda k: k.decode("utf-8")[1], reverse=False)
     body = []
     body.append("当前频道({0})所有成员".format(channel))
     body.extend(onlinebody)
     body.extend(offlinebody)
     online_num = len(onlinebody)
     total = online_num + len(offlinebody)
     body.append("共列出 {0} 位成员 {1} 位在线".format(total, online_num))
     self._send_cmd_result(stanza, "\n".join(body))
     return
Exemplo n.º 12
0
    def test_appointment_cancel_view_success(self):
        start = create_test_time()
        end = start + timedelta(hours=1)
        appointment = self.create_appointment(
            healer=Healer.objects.get(pk=1),
            client=self.test_client,
            start_date=start.date(),
            end_date=end.date(),
            start_time=get_minutes(start),
            end_time=get_minutes(end),
            location=None,
            treatment_length=self.treatment_length)

        response = self.client.get(
            reverse('appointment_cancel', args=[appointment.id]))
        self.assertEqual(response.status_code, 302)
        self.assertTrue(
            Appointment.canceled_objects.get(pk=appointment.id).canceled)
        self.assertFalse(Appointment.objects.filter(pk=appointment.id).count())

        email = get_email()
        self.assertNotEqual(email.subject.find('canceled'), -1)
        self.assertNotEqual(email.body.find('canceled'), -1)
Exemplo n.º 13
0
    def test_invite_view_post(self):
        message = 'test message'
        data = {
            'emails':
            "%s, %s\n%s" % (self.emails[0], self.emails[1], self.emails[2]),
            'message':
            message,
            'invite_type':
            'client'
        }
        response = self.client.post(reverse('invite_to_join'), data)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            Contact.objects.filter(email__in=self.emails).count(), 3)

        email = get_email()
        self.assertNotEqual(email.subject.find('has added you as a Client'),
                            -1)
        self.assertNotEqual(email.body.find(message), -1)

        self.test_healer = Healer.objects.get(pk=self.test_healer.pk)
        self.assertEqual(self.test_healer.invite_message, message)