Пример #1
0
  def test_create_inactive_user(self):
      from kay.auth.models import DatastoreUser
      from kay.utils import crypto

      user = DatastoreUser.create_inactive_user("testuser", "password", "*****@*****.**") 
      self.assertEqual(user.key().name(), DatastoreUser.get_key_name("testuser"))
      self.assertEqual(user.user_name, "testuser")
    
      self.assertTrue(crypto.check_pwhash(user.password, "password"))
      self.assertEqual(user.email, "*****@*****.**")
Пример #2
0
    def test_create_inactive_user(self):
        from kay.auth.models import DatastoreUser
        from kay.utils import crypto

        user = DatastoreUser.create_inactive_user("testuser",
                                                  "password",
                                                  "*****@*****.**",
                                                  do_registration=False)
        self.assertEqual(user.key().name(),
                         DatastoreUser.get_key_name("testuser"))
        self.assertEqual(user.user_name, "testuser")

        self.assertTrue(crypto.check_pwhash(user.password, "password"))
        self.assertEqual(user.email, "*****@*****.**")
Пример #3
0
    def test_facebook_first_visit(self):
        profiles = UserProfile.all().fetch(100)
        self.assertEquals(len(profiles), 0)
        fb_profiles = FacebookProfile.all().fetch(100)
        self.assertEquals(len(fb_profiles), 0)
        users = DatastoreUser.all().fetch(100)
        self.assertEquals(len(users), 0)
        _facebook_login(self)

        fb_profiles = FacebookProfile.all().fetch(100)
        self.assertEquals(len(fb_profiles), 1)
        profiles = UserProfile.all().fetch(100)
        self.assertEquals(len(profiles), 1)
        users = DatastoreUser.all().fetch(100)
        self.assertEquals(len(users), 1)
Пример #4
0
def _create_fb_user(fb_uid):
    from kay.auth.models import DatastoreUser
    user = DatastoreUser(email = '*****@*****.**' % fb_uid, 
                         user_name = 'facebook_user_%s' % fb_uid,
                         password = '******',
                         key_name = 'u:' + str(fb_uid))
    user.put()
    #facebook_data = get_facebook_data_for_uid(fb_uid)
    # TODO: Use OAuth2 to retrieve userprofile values from fb
    userprofile = UserProfile(location = '',
                              bio = '',
                              website = '',
                              user = user)
    userprofile.put()
    facebook_profile = FacebookProfile(fb_uid = fb_uid, userprofile = userprofile) 
    facebook_profile.put()
    return user
Пример #5
0
 def test_update_facebook_user(self):
     _create_fb_user(FACEBOOK_UID)
     facebook_data = dict(first_name = 'Mos', last_name = "Def")
     user = DatastoreUser.all().fetch(100)[0]
     self.assertTrue(user.user_name.find(FACEBOOK_UID) > -1)
     user = update_facebook_user(user = user, 
                          facebook_user_data = facebook_data)
     self.assertTrue(user.first_name == "Mos")
Пример #6
0
    def test_facebook_return_visit(self):

        _create_fb_user(FACEBOOK_UID)

        profiles = UserProfile.all().fetch(100)
        self.assertEquals(len(profiles), 1)
        fb_profiles = FacebookProfile.all().fetch(100)
        self.assertEquals(len(fb_profiles), 1)
        users = DatastoreUser.all().fetch(100)
        self.assertEquals(len(users), 1)
        _facebook_login(self)

        fb_profiles = FacebookProfile.all().fetch(100)
        self.assertEquals(len(fb_profiles), 1)
        profiles = UserProfile.all().fetch(100)
        self.assertEquals(len(profiles), 1)
        users = DatastoreUser.all().fetch(100)
        self.assertEquals(len(users), 1)
Пример #7
0
def send_order_to_manager(request, order_key):
    order = Order.get(order_key)

    subject = render_to_string('cart/notifications/order2manager_subject.html', {'order_id':order.key().id()})
    subject = ''.join(subject.splitlines())
    message = render_to_string('cart/notifications/order2manager_body.html', {'order': order})

    email = mail.EmailMessage()
    email.subject = subject
    email.html = message
    email.sender = settings.DEFAULT_MAIL_FROM

    managers = DatastoreUser.all()
    for manager in managers:
        if manager.email:
            email.to = manager.email
            email.send()

    return Response("OK")
Пример #8
0
  def test_cron_only_admin(self):
    from kay.auth.models import DatastoreUser
    user = DatastoreUser(
        key_name=DatastoreUser.get_key_name("foobar"),
        user_name="foobar",
        password=DatastoreUser.hash_password("password")
    )
    user.is_admin = True
    user.put()

    self.client.test_login(username='******')
    response = self.client.get('/cron')
    self.assertEqual(response.status_code, 200)
    self.assertTrue(response.data == "OK")