Exemplo n.º 1
0
    def test_rack_search_kml__one(self):
        rack = Rack(address='148 Lafayette St, New York NY',
                    title='TOPP', date=datetime.utcfromtimestamp(0),
                    email='*****@*****.**', location=Point(20.0, 20.0, srid=SRID),
                    )
        rack.save()
        kml = self.client.get('/racks/search.kml').content
        tree = lxml.objectify.fromstring(kml)
        placemarks = tree.Document.getchildren()
        self.assertEqual(len(placemarks), 1)
        placemark = tree.Document.Placemark
        self.assertEqual(placemark.name, rack.title)
        self.assertEqual(placemark.address, rack.address)
        self.assertEqual(placemark.description, '')

        self.assertEqual(placemark.Point.coordinates, '20.0,20.0,0')

        # Argh. Searching child elements for specific attribute values
        # is making my head hurt. xpath should help, but I couldn't
        # find the right expression. Easier to extract them into a
        # dict.
        data = {}
        for d in placemark.ExtendedData.Data:
            data[d.attrib['name']] = d.value

        self.assertEqual(data['page_number'], 1)
        self.assertEqual(data['num_pages'], 1)
        self.assertEqual(data['source'], 'web')
        self.assertEqual(data['date'], 'Jan. 1, 1970')
        self.assertEqual(data['votes'], 0)
Exemplo n.º 2
0
 def test_get(self):
     rack = Rack(address='148 Lafayette St, New York NY',
                 title='TOPP', date=datetime.utcfromtimestamp(0),
                 email='*****@*****.**', location=Point(20.0, 20.0, srid=SRID),
                 )
     rack.save()
     self._login()
     response = self.client.get('/racks/%d/votes/' % rack.id)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.content, '{"votes": 0}')
Exemplo n.º 3
0
 def test_new_racks_not_added_to_pending_order(self):
     bo, rack = self._make_bo_and_rack()
     bo.save()
     bo.submit()
     self.assertEqual(bo.racks.count(), 1)
     self.assertEqual(bo.status, 'pending')
     rack2 = Rack(location='POINT (7.0 7.0)', date=EPOCH)
     rack2.save()
     self.failIf(rack2 in set(bo.racks))
     self.failIf(rack2.locked)
     self.assertEqual(bo.racks.count(), 1)
Exemplo n.º 4
0
 def test_rack_view_anonymous(self):
     rack = Rack(address='148 Lafayette St, New York NY',
                 title='TOPP', date=datetime.utcfromtimestamp(0),
                 email='*****@*****.**', location=Point(20.0, 20.0, srid=SRID),
                 user='******',
                 )
     rack.save()
     response = self.client.get('/racks/%d/' % rack.id)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.context['user_likes_this_rack'], None)
     self.assertEqual(response.context['canheart'], False)
Exemplo n.º 5
0
    def _make_bo_and_rack(self):
        from fixcity.bmabr.models import NYCDOTBulkOrder, User, Rack, CommunityBoard
        user = User()
        user.save()
        cb = CommunityBoard(
            the_geom='MULTIPOLYGON (((0.0 0.0, 10.0 0.0, 10.0 10.0, 0.0 10.0, 0.0 0.0)))',
            gid=1, borocd=1, board=1, borough_id=1)
        cb.save()
        rack = Rack(location='POINT (5.0 5.0)', date=EPOCH)
        rack.save()

        bo = NYCDOTBulkOrder(user=user, communityboard=cb)
        return bo, rack
Exemplo n.º 6
0
 def _make_rack(self):
     from fixcity.bmabr.models import Rack
     from fixcity.bmabr.models import TwitterSource
     user = self._make_user()
     ts = TwitterSource(name='twitter', user='******', status_id='99')
     rack = Rack(location='POINT (0.5 0.5)', email=user.email,
                 user=user.username,
                 title='A popular bar',
                 address='123 Something St, Brooklyn NY',
                 date=datetime.utcfromtimestamp(0),
                 source=ts,
                 )
     rack.save()
     return rack
Exemplo n.º 7
0
    def test_racks_within_boundaries(self):
        from fixcity.bmabr.models import CommunityBoard
        communityboard = CommunityBoard(the_geom='MULTIPOLYGON (((0.0 0.0, 10.0 0.0, 10.0 10.0, 0.0 10.0, 0.0 0.0)))')
        rack_inside = Rack(location='POINT (5.0 5.0)', date=EPOCH)
        rack_outside = Rack(location='POINT (20.0 20.0)', date=EPOCH)
        rack_edge = Rack(location='POINT (0.0 0.0)', date=EPOCH)
        rack_inside.save()
        rack_edge.save()
        rack_outside.save()

        self.assertEqual(set(communityboard.racks),
                         set([rack_inside, rack_edge]))
Exemplo n.º 8
0
    def test_filter_by_verified(self):
        from fixcity.bmabr.models import Rack
        # If ALL 3 fields are true, we filter it as verified.
        rack = Rack(address='67 s 3rd st, brooklyn, ny 11211',
                    title='williamsburg somewhere',
                    date=EPOCH,
                    email='*****@*****.**',
                    location=Point(-73.964858020364, 40.713349294636,
                                    srid=SRID),
                    verify_surface=True,
                    verify_objects=True,
                    verify_access=True)
        rack.save()
        self.assertEqual(1, Rack.objects.filter_by_verified('verified').count())
        self.assertEqual(0, Rack.objects.filter_by_verified('unverified').count())

        # If ANY of those fields are false, the rack is unverified.
        rack.verify_surface = False
        rack.save()
        self.assertEqual(0, Rack.objects.filter_by_verified('verified').count())
        self.assertEqual(1, Rack.objects.filter_by_verified('unverified').count())

        rack.verify_surface = True
        rack.verify_access = False
        rack.save()
        self.assertEqual(0, Rack.objects.filter_by_verified('verified').count())
        self.assertEqual(1, Rack.objects.filter_by_verified('unverified').count())

        rack.verify_access = True
        rack.verify_objects = False
        rack.save()
        self.assertEqual(0, Rack.objects.filter_by_verified('verified').count())
        self.assertEqual(1, Rack.objects.filter_by_verified('unverified').count())
Exemplo n.º 9
0
def updatephoto(request,rack_id): 
    rack_query = Rack.objects.get(id=rack_id) 
    rack_photo = request.FILES['photo']
    rack = Rack(id=rack_query.id,address=rack_query.address,title=rack_query.title,date=rack_query.date,description=rack_query.description,email=rack_query.email,communityboard=rack_query.communityboard,photo=rack_photo,status=rack_query.status,location=rack_query.location)
    rack.save()
    return HttpResponse(rack)