def test_locationname_insert(self):
        """
        Tests insertion of a name to a specific location .
        """
        import pdb; pdb.set_trace()
        loc= Location.objects.first()
        
        c = AdminClient()
        response = c.get(reverse('getloc', args=[loc.id]))
        self.assertEqual(response.status_code, 200)

        c.login_as_admin()

        data = {"name":"The Gong","language":'en'}

        response = c.post(reverse('recordname', args=[loc.id]), data=json.dumps(data), content_type='application/json')
        self.assertEqual(response.status_code, 200)

        locx = Location.objects.get(id=loc.id)

        response = c.get(reverse('getloc', args=[loc.id]))
        
        self.assertEqual(response.status_code, 200)
        locr = json.loads(response.content)
    
        data = {"name":"732","namespace":'http://abs.gov.au/admincodes/',"language":''}
        response = c.post(reverse('recordname', args=[loc.id]), data=json.dumps(data), content_type='application/json')
        self.assertEqual(response.status_code, 200)    

        response = c.get(reverse('getloc', args=[loc.id]))
        
        self.assertEqual(response.status_code, 200)
        locr = json.loads(response.content)
Пример #2
0
    def test_locationname_insert(self):
        """
        Tests insertion of a name to a specific location .
        """

        loc= Location.objects.first()
        
        c = AdminClient()
        c.login_as_admin()
        import pdb; pdb.set_trace()
        response = c.get(reverse('getloc', args=[loc.id]))
        self.assertEqual(response.status_code, 200)

        # test various equivalent null forms are handled
        for data in [  {"name":"The Gong","language":None},  {"name":"The Gong","language":''} ,  {"name":"The Gong"} ] :
        
            response = c.post(reverse('recordname', args=[loc.id]), data=json.dumps(data), content_type='application/json')
            self.assertEqual(response.status_code, 200,'Insert name failed')
            response = c.get(reverse('getloc', args=[loc.id]))
            self.assertEqual(response.status_code, 200,'Location not retrieved after insert of name')
            locr = json.loads(response.content)
            # check only one exists, and it has no language set
            count = 0
            for n in locr['names'] :
                if n['name'] == data['name'] :
                    self.assertIsNone(n.get('language'),'language value should be missing')
                    count +=1
            self.assertEqual( count, 1, 'Insert of name with no language failed: incorrect count {0!s}'.format( count)) 

        # test overiding null language, and inserting new name 
        for data in [  {"name":"The Gong","language":'en'},  {"name":"Wollongong City","language":'fr'} , {"name":"Wollongong City","language":'en'} ] :
        
            response = c.post(reverse('recordname', args=[loc.id]), data=json.dumps(data), content_type='application/json')
            self.assertEqual(response.status_code, 200,'Insert name failed')
            response = c.get(reverse('getloc', args=[loc.id]))
            self.assertEqual(response.status_code, 200,'Location not retrieved after insert of name')
            locr = json.loads(response.content)
            # check only one exists, and it has no language set
            count = 0
            for n in locr['names'] :
                if n['name'] == data['name'] :
                    if n['language'] == data['language'] :
                        count +=1
                    else :
                        self.assertIsNotNone(n.get('language'),'Name with language not set should not occur after language specified for name')
            
            self.assertEqual( count, 1, 'Insert of name with no language failed: incorrect count {0!s}'.format( count)) 
            
        data = {"name":"732","namespace":'http://abs.gov.au/admincodes/',"language":''}
        response = c.post(reverse('recordname', args=[loc.id]), data=json.dumps(data), content_type='application/json')
        self.assertEqual(response.status_code, 200)    

        response = c.get(reverse('getloc', args=[loc.id]))
        
        self.assertEqual(response.status_code, 200)
        locr = json.loads(response.content)
Пример #3
0
    def test_boxes_view(self):
        """
        Tests various methods of the boxes view.
        """

        m = Map.objects.first()

        c = AdminClient()
        response = c.get(reverse('boxes', args=[m.id]))
        self.assertEqual(response.status_code, 200)

        response = c.delete(reverse('boxes', args=[m.id]))
        self.assertEqual(response.status_code, 400)

        response = c.put(reverse('boxes', args=[m.id]))
        self.assertEqual(response.status_code, 400)

        data = dict(map=m.id, title='this is a test', geometry=make_point(-77.464599609375, 37.61423141542417))
        response = c.post(reverse('boxes', args=[m.id]), data=data)
        self.assertEqual(response.status_code, 403)

        # TODO: Test POST request with box payload
        c.login_as_admin()

        data = {"type":"FeatureCollection","features":[{"type":"Feature","properties":{"playback":3,"playbackRate":"seconds","interval":1,"intervalRate":"years","title":"Sample Title","description":"Sample Description","start_time":946684800,"end_time":1577836800,"zoom":6,"center":[1766040.0266747456,729122.1624405942],"range":{"start":946684800000,"end":1577836800000},"speed":{"interval":31536000000,"seconds":3},"_offset":0,"_id":1444749022177}}]}

        response = c.post(reverse('boxes', args=[m.id]), data=json.dumps(data), content_type='application/json')
        self.assertEqual(response.status_code, 200)

        box = StoryBox.objects.first()
        feature = data['features'][0]
        self.assertEqual(box.map, m)
        self.assertEqual(box.title, feature['properties']['title'])
        self.assertEqual(box.playback, feature['properties']['playback'])
        self.assertEqual(box.playbackRate, feature['properties']['playbackRate'])
        self.assertEqual(box.interval, feature['properties']['interval'])
        self.assertEqual(box.intervalRate, feature['properties']['intervalRate'])
        self.assertEqual(box.description, feature['properties']['description'])
        self.assertEqual(box.start_time, feature['properties']['start_time'])
        self.assertEqual(box.end_time, feature['properties']['end_time'])
        self.assertEqual(box.zoom, feature['properties']['zoom'])
        self.assertEqual(eval(box.center), feature['properties']['center'])
        self.assertEqual(eval(box.speed), feature['properties']['speed'])
    def test_locationname_insert(self):
        """
        Tests insertion of a name to a specific location .
        """
        import pdb
        pdb.set_trace()
        loc = Location.objects.first()

        c = AdminClient()
        response = c.get(reverse('getloc', args=[loc.id]))
        self.assertEqual(response.status_code, 200)

        c.login_as_admin()

        data = {"name": "The Gong", "language": 'en'}

        response = c.post(reverse('recordname', args=[loc.id]),
                          data=json.dumps(data),
                          content_type='application/json')
        self.assertEqual(response.status_code, 200)

        locx = Location.objects.get(id=loc.id)

        response = c.get(reverse('getloc', args=[loc.id]))

        self.assertEqual(response.status_code, 200)
        locr = json.loads(response.content)

        data = {
            "name": "732",
            "namespace": 'http://abs.gov.au/admincodes/',
            "language": ''
        }
        response = c.post(reverse('recordname', args=[loc.id]),
                          data=json.dumps(data),
                          content_type='application/json')
        self.assertEqual(response.status_code, 200)

        response = c.get(reverse('getloc', args=[loc.id]))

        self.assertEqual(response.status_code, 200)
        locr = json.loads(response.content)
Пример #5
0
    def test_flag_view(self):
        """
        Tests the flag view.
        """
        m = Map.objects.first()
        ct = ContentType.objects.get_for_model(m)
        c = AdminClient()
        response = c.get(reverse('flag'))
        self.assertLoginRequired(response)

        c.login_as_admin()
        response = c.get(reverse('flag'))
        self.assertEqual(response.status_code, 405)

        data = dict(content_type=ct.id, object_id=m.id, comment="what is this?", creator_field='owner')

        response = c.post(reverse('flag'), data=data)
        self.assertEqual(response.status_code, 302)

        flag = FlaggedContent.objects.first()
        self.assertEqual(flag.content_type, ct)
        self.assertEqual(flag.object_id, data['object_id'])
        self.assertEqual(flag.flaginstance_set.first().comment, data['comment'])
        self.assertEqual(flag.flaginstance_set.first().user, User.objects.get(username='******'))
Пример #6
0
    def test_boxes_view(self):
        """
        Tests various methods of the boxes view.
        """

        m = Map.objects.first()

        c = AdminClient()
        response = c.get(reverse('boxes', args=[m.id]))
        self.assertEqual(response.status_code, 200)

        response = c.delete(reverse('boxes', args=[m.id]))
        self.assertEqual(response.status_code, 400)

        response = c.put(reverse('boxes', args=[m.id]))
        self.assertEqual(response.status_code, 400)

        data = dict(map=m.id,
                    title='this is a test',
                    geometry=make_point(-77.464599609375, 37.61423141542417))
        response = c.post(reverse('boxes', args=[m.id]), data=data)
        self.assertEqual(response.status_code, 403)

        # TODO: Test POST request with box payload
        c.login_as_admin()

        data = {
            "type":
            "FeatureCollection",
            "features": [{
                "type": "Feature",
                "properties": {
                    "playback": 3,
                    "playbackRate": "seconds",
                    "interval": 1,
                    "intervalRate": "years",
                    "title": "Sample Title",
                    "description": "Sample Description",
                    "start_time": 946684800,
                    "end_time": 1577836800,
                    "zoom": 6,
                    "center": [1766040.0266747456, 729122.1624405942],
                    "range": {
                        "start": 946684800000,
                        "end": 1577836800000
                    },
                    "speed": {
                        "interval": 31536000000,
                        "seconds": 3
                    },
                    "_offset": 0,
                    "_id": 1444749022177
                }
            }]
        }

        response = c.post(reverse('boxes', args=[m.id]),
                          data=json.dumps(data),
                          content_type='application/json')
        self.assertEqual(response.status_code, 200)

        box = StoryBox.objects.first()
        feature = data['features'][0]
        self.assertEqual(box.map, m)
        self.assertEqual(box.title, feature['properties']['title'])
        self.assertEqual(box.playback, feature['properties']['playback'])
        self.assertEqual(box.playbackRate,
                         feature['properties']['playbackRate'])
        self.assertEqual(box.interval, feature['properties']['interval'])
        self.assertEqual(box.intervalRate,
                         feature['properties']['intervalRate'])
        self.assertEqual(box.description, feature['properties']['description'])
        self.assertEqual(box.start_time, feature['properties']['start_time'])
        self.assertEqual(box.end_time, feature['properties']['end_time'])
        self.assertEqual(box.zoom, feature['properties']['zoom'])
        self.assertEqual(eval(box.center), feature['properties']['center'])
        self.assertEqual(eval(box.speed), feature['properties']['speed'])