Ejemplo n.º 1
0
    def test_newrack_json_twitter(self):
        from fixcity.bmabr.views import newrack_json
        self.assertEqual(len(Source.objects.all()), 0)

        class MockRequest:

            method = 'POST'
            POST = {}
            raw_post_data = json.dumps(dict(
                title='foo title',
                description='foo description',
                date='2009-11-18 15:14',
                address='148 Lafayette St, New York, NY',
                geocoded=1,  # Skip server-side geocoding.
                location=str(Point(-73.999548, 40.719545, srid=SRID)),
                source_type='twitter',
                twitter_user='******',
                twitter_id=456,
                ))

        response = newrack_json(MockRequest)
        data = json.loads(response._get_content())
        self.failUnless(data.has_key('photo_post_url'))
        self.failUnless(type(data.get('rack')) == int)
        self.failUnless(data.has_key('user'))
        self.failUnless(data.has_key('message'))
        self.assertEqual(len(Source.objects.all()), 1)
Ejemplo n.º 2
0
    def test_newrack__source_gets_rolled_back(self, mock_error):
        from fixcity.bmabr.views import newrack_json

        self.assertEqual(len(Source.objects.all()), 0)

        class MockRequest:

            method = 'POST'
            POST = {}
            # Leave out some stuff, we want this to fail.
            raw_post_data = json.dumps(dict(
                description='foo description',
                date='2009-11-18 15:14',
                geocoded=1,  # Skip server-side geocoding.
                source_type='twitter',
                twitter_user='******',
                twitter_id=456,
                ))

        response = newrack_json(MockRequest)
        data = json.loads(response._get_content())
        self.failUnless(data.has_key('errors'))
        # Here's the rub: We should not have left a dangling source
        # lying around.
        self.assertEqual(len(Source.objects.all()), 0)