示例#1
0
 def test_create_a_dojo_from_a_json(self):
     DojoApiHandler.get_current_user().AndReturn(self.logged_user)
     DojoApiHandler.get_current_user().AndReturn(self.logged_user)
     self.mox.ReplayAll()
     expected = dict(
         language = "python",
         location = 'GruPy HeadQuarters',
         address = 'asdf',
         city = 'São Paulo',
         date_hour = 'Sex Out 21 18:40:23 BRST 2011'
     )
     headers = {'Accept': 'application/json'}
     body = json_encode(expected)
     response = self.fetch('/api/dojo', method='POST', body=body, follow_redirects=False, headers=headers)
     self.assertEquals(200, response.code)
     db = database.Connection("localhost", "dojo_to")
     dojos = db.execute_rowcount("SELECT * FROM dojos")
     self.assertEquals(4, dojos)
     actual = db.get('SELECT * from dojos WHERE id = 4')
     self.assertEquals(expected['language'], actual['language'])
     self.assertEquals(expected['location'], actual['location'])
     self.assertEquals(expected['address'], actual['address'])
     #TODO self.assertEquals(expected['city'], actual['city'])
     db.close()
     self.mox.VerifyAll()
示例#2
0
    def test_create_a_dojo_with_a_simple_post(self):
        '''
        Create a dojo using a simple post, this api will be used
        on forms from the page, when the user hasn't javascript enabled.

        TODO: date_hour must be passed somehow!?
        TODO: if they are separated fields?!? The server code must catch
        with GMT user is and make the correct conversion!

        How to render it to a microformat?!

        '''
        DojoApiHandler.get_current_user().AndReturn(self.logged_user)
        DojoApiHandler.get_current_user().AndReturn(self.logged_user)
        self.mox.ReplayAll()
        expected = dict(
            language = "python",
            location = 'GruPy HeadQuarters',
            address = 'Rua A Ser definida mas com varios caracteres, 42, Bairro',
            city = 'São Paulo',
            date_hour = 'Sex Out 21 18:40:23 BRST 2011'
        )
        body = urlencode(expected)
        headers = {'Accept': 'application/x-www-form-urlencoded'}
        response = self.fetch('/api/dojo', method='POST', body=body, follow_redirects=False, headers=headers)
        self.assertEquals(302, response.code)
        db = database.Connection("localhost", "dojo_to")
        dojos = db.execute_rowcount("SELECT * FROM dojos")
        self.assertEquals(4, dojos)
        actual = db.get('SELECT * from dojos WHERE id = 4')
        self.assertEquals(expected['language'], actual['language'])
        self.assertEquals(expected['location'], actual['location'])
        self.assertEquals(expected['address'], actual['address'])
        #TODO: self.assertEquals(expected['city'], actual['city'])
        db.close()
        self.mox.VerifyAll()