From 482feee8043202f42781cbc157316d5ebf39909c Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Thu, 15 May 2014 19:43:09 +0300 Subject: [PATCH] Add login test. Fix bugs in socket teardown, RPC retry. Remove chunk of broken merge code pending rewrite. --- lib/models.py | 20 +------------------- static/cosmopolite.js | 10 +++++++--- static/test.js | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/lib/models.py b/lib/models.py index d968677..8b4ca7c 100644 --- a/lib/models.py +++ b/lib/models.py @@ -54,25 +54,7 @@ class Profile(db.Model): # Merge from another profile into this one, using last_set time as the # arbiter. # TODO: this is totally broken - my_states = {} - for state_entry in self.GetStateEntries(): - my_states[state_entry.entry_key] = state_entry - - for state_entry in (StateEntry.all() - .ancestor(source_profile) - .run()): - my_state_entry = my_states.get(state_entry.entry_key, None) - if my_state_entry: - if state_entry.last_set > my_state_entry.last_set: - # newer, merge in - my_state_entry.entry_value = state_entry.entry_value - my_state_entry.put() - else: - # entirely new, add - StateEntry(parent=self, - entry_key=state_entry.entry_key, - entry_value=state_entry.entry_value - ).put() + pass class Client(db.Model): diff --git a/static/cosmopolite.js b/static/cosmopolite.js index 99c41de..9d46803 100644 --- a/static/cosmopolite.js +++ b/static/cosmopolite.js @@ -187,13 +187,17 @@ Cosmopolite.prototype.onLoad_ = function() { Cosmopolite.prototype.onReceiveMessage_ = function(data) { switch (data) { case 'login_complete': - this.socket_.close(); + if (this.socket_) { + this.socket_.close(); + } break; case 'logout_complete': localStorage.removeItem(this.namespace_ + ':client_id'); localStorage.removeItem(this.namespace_ + ':google_user_id'); this.$('#google_user').empty(); - this.socket_.close(); + if (this.socket_) { + this.socket_.close(); + } break; default: console.log('cosmopolite: unknown event type:', data); @@ -284,7 +288,7 @@ Cosmopolite.prototype.sendRPCs_ = function(commands, delay) { } if (data['status'] == 'retry') { // Discard delay - this.sendRPCs_(commands, onSuccess); + this.sendRPCs_(commands); return; } if (data['status'] != 'ok') { diff --git a/static/test.js b/static/test.js index cfb6758..cd7916c 100644 --- a/static/test.js +++ b/static/test.js @@ -182,3 +182,23 @@ asyncTest('Complex object', function() { var cosmo1 = new Cosmopolite(callbacks1, null, randstring()); var cosmo2 = new Cosmopolite(callbacks2, null, randstring()); }); + + +module('dev_appserver only'); + +asyncTest('Login', function() { + expect(2); + var callbacks = { + 'onLogin': function(login_url) { + ok(true, 'onLogin fired'); + cosmo.shutdown(); + start(); + }, + 'onLogout': function(login_url) { + ok(true, 'onLogout fired'); + // 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'); + } + }; + var cosmo = new Cosmopolite(callbacks); +});