Fix profile merge code on login, add test.
This commit is contained in:
@@ -49,12 +49,14 @@ class Profile(db.Model):
|
|||||||
profile.put()
|
profile.put()
|
||||||
return profile
|
return profile
|
||||||
|
|
||||||
@db.transactional(xg=True)
|
|
||||||
def MergeFrom(self, source_profile):
|
def MergeFrom(self, source_profile):
|
||||||
# Merge from another profile into this one, using last_set time as the
|
# This is non-transactional and racy (new messages can be introduced by the
|
||||||
# arbiter.
|
# old client after we start). This is hard to solve because a) we're not in
|
||||||
# TODO: this is totally broken
|
# a single hierarchy and b) we don't revoke the old client ID, so it can
|
||||||
pass
|
# still be used.
|
||||||
|
for message in Message.all().filter('sender =', source_profile):
|
||||||
|
message.sender = self;
|
||||||
|
message.put()
|
||||||
|
|
||||||
|
|
||||||
class Client(db.Model):
|
class Client(db.Model):
|
||||||
|
|||||||
@@ -181,21 +181,62 @@ asyncTest('Complex object', function() {
|
|||||||
module('dev_appserver only');
|
module('dev_appserver only');
|
||||||
|
|
||||||
asyncTest('Login', function() {
|
asyncTest('Login', function() {
|
||||||
expect(2);
|
expect(3);
|
||||||
|
|
||||||
|
var anonymousProfile;
|
||||||
|
|
||||||
logout(function() {
|
logout(function() {
|
||||||
var callbacks = {
|
var callbacks = {
|
||||||
|
'onLogout': function(login_url) {
|
||||||
|
ok(true, 'onLogout fired');
|
||||||
|
anonymousProfile = cosmo.profile();
|
||||||
|
// Entirely magic URL that sets the login cookie and redirects.
|
||||||
|
window.open('/_ah/login?email=test%40example.com&action=Login&continue=/cosmopolite/static/login_complete.html');
|
||||||
|
},
|
||||||
'onLogin': function(login_url) {
|
'onLogin': function(login_url) {
|
||||||
ok(true, 'onLogin fired');
|
ok(true, 'onLogin fired');
|
||||||
|
notEqual(anonymousProfile, cosmo.profile(), 'profile changed');
|
||||||
cosmo.shutdown();
|
cosmo.shutdown();
|
||||||
logout();
|
logout();
|
||||||
start();
|
start();
|
||||||
},
|
},
|
||||||
'onLogout': function(login_url) {
|
};
|
||||||
ok(true, 'onLogout fired');
|
var cosmo = new Cosmopolite(callbacks);
|
||||||
// Entirely magic URL that sets the login cookie and redirects.
|
});
|
||||||
window.open('/_ah/login?email=test%40example.com&action=Login&continue=/cosmopolite/static/login_complete.html');
|
});
|
||||||
}
|
|
||||||
|
asyncTest('Profile merge', function() {
|
||||||
|
expect(6);
|
||||||
|
|
||||||
|
var subject = randstring();
|
||||||
|
var message = randstring();
|
||||||
|
|
||||||
|
var messages = 0;
|
||||||
|
|
||||||
|
logout(function() {
|
||||||
|
var callbacks = {
|
||||||
|
'onReady': function() {
|
||||||
|
cosmo.sendMessage(subject, message);
|
||||||
|
cosmo.subscribe(subject, -1);
|
||||||
|
},
|
||||||
|
'onMessage': function(msg) {
|
||||||
|
messages++;
|
||||||
|
equal(msg['subject'], subject);
|
||||||
|
equal(msg['message'], message);
|
||||||
|
equal(msg['sender'], cosmo.profile());
|
||||||
|
if (messages == 1) {
|
||||||
|
cosmo.unsubscribe(subject);
|
||||||
|
// Entirely magic URL that sets the login cookie and redirects.
|
||||||
|
window.open('/_ah/login?email=test%40example.com&action=Login&continue=/cosmopolite/static/login_complete.html');
|
||||||
|
}
|
||||||
|
if (messages == 2) {
|
||||||
|
cosmo.shutdown();
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'onLogin': function(logout_url) {
|
||||||
|
cosmo.subscribe(subject, -1);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
var cosmo = new Cosmopolite(callbacks);
|
var cosmo = new Cosmopolite(callbacks);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user