Beispiel #1
0
	def test_manythings(self):
		import codecs
		from django.test.client import Client
		from prometapi.models import parse_burja, parse_burjaznaki, parse_counters, parse_events, parse_parkirisca_lpt
		from prometapi.models import Burja, BurjaZnaki, Counters, Events, ParkiriscaLPT
		from prometapi.models import _decode, _loads, _dumps
		
		modls = {
			'burja': Burja,
			'burjaznaki': BurjaZnaki,
			'counters': Counters,
			'events': Events,
			}
		
		for fn in ('burja', 'burjaznaki', 'counters', 'events'):
			for n in (1, 2, 3):
				obf = open(obffile('%s_%s.txt' % (fn, n))).read()
				
				self.assertEqual(_decode(obf), codecs.open(obffile('%s_%s.json' % (fn, n)), 'r', 'utf-8').read(), 'obfuscated vs. json mismatch, %s_%s.json' % (fn, n))
				
				parser = locals()['parse_%s' % fn]
				json = parser(obf)
				self.assertEqual(type(json), type({}))
				
				m = modls[fn]
				original_data=zlib_encode(obf)
				obj = m(json_data=_dumps(json), original_data=original_data)
				obj.save()
		
		# load parkirisca
		park = open(testfile('parkirisca_1.xml')).read()
		occu = open(testfile('occupancy_1.xml')).read()
		json = parse_parkirisca_lpt(park, occu)
		obj = ParkiriscaLPT(json_data=_dumps(json), original_data=zlib_encode(_dumps([park, occu])))
		obj.save()
		
		# GET
		c = Client()
		
		resp = c.get('/promet/events/')
		self.assertEqual(resp.status_code, 200)
		json = _loads(resp.content)
		self.assertEqual(type(json), type({}))
		resp = c.get('/promet/burja/')
		self.assertEqual(resp.status_code, 200)
		json = _loads(resp.content)
		self.assertEqual(type(json), type({}))
		resp = c.get('/promet/burjaznaki/')
		self.assertEqual(resp.status_code, 200)
		json = _loads(resp.content)
		self.assertEqual(type(json), type({}))
		resp = c.get('/promet/counters/')
		self.assertEqual(resp.status_code, 200)
		json = _loads(resp.content)
		self.assertEqual(type(json), type({}))
		resp = c.get('/promet/parkirisca/lpt/')
		self.assertEqual(resp.status_code, 200)
		json = _loads(resp.content)
		self.assertEqual(type(json), type({}))
Beispiel #2
0
	def runTest(self):
		import codecs
		from django.test.client import Client
		from prometapi.models import parse_burja, parse_burjaznaki, parse_counters, parse_events, parse_parkirisca_lpt
		from prometapi.models import Burja, BurjaZnaki, Counters, Events, ParkiriscaLPT
		from prometapi.models import _decode, _loads, _dumps
		
		modls = {
			'burja': Burja,
			'burjaznaki': BurjaZnaki,
			'counters': Counters,
			'events': Events,
			}
		
		for fn in ('burja', 'burjaznaki', 'counters', 'events'):
			for n in (1, 2, 3):
				obf = open(obffile('%s_%s.txt' % (fn, n))).read()
				
				self.assertEqual(_decode(obf), codecs.open(obffile('%s_%s.json' % (fn, n)), 'r', 'utf-8').read(), 'obfuscated vs. json mismatch, %s_%s.json' % (fn, n))
				
				parser = locals()['parse_%s' % fn]
				json = parser(obf)
				self.assertEqual(type(json), type({}))
				
				m = modls[fn]
				obj = m(json_data=_dumps(json), original_data=obf.encode('zlib').encode('base64'))
				obj.save()
		
		# load parkirisca
		park = open(testfile('parkirisca_1.xml')).read()
		occu = open(testfile('occupancy_1.xml')).read()
		json = parse_parkirisca_lpt(park, occu)
		obj = ParkiriscaLPT(json_data=_dumps(json), original_data=_dumps([park, occu]).encode('zlib').encode('base64'))
		obj.save()
		
		# GET
		c = Client()
		
		resp = c.get('/promet/events/')
		self.assertEqual(resp.status_code, 200)
		json = _loads(resp.content)
		self.assertEqual(type(json), type({}))
		resp = c.get('/promet/burja/')
		self.assertEqual(resp.status_code, 200)
		json = _loads(resp.content)
		self.assertEqual(type(json), type({}))
		resp = c.get('/promet/burjaznaki/')
		self.assertEqual(resp.status_code, 200)
		json = _loads(resp.content)
		self.assertEqual(type(json), type({}))
		resp = c.get('/promet/counters/')
		self.assertEqual(resp.status_code, 200)
		json = _loads(resp.content)
		self.assertEqual(type(json), type({}))
		resp = c.get('/promet/parkirisca/lpt/')
		self.assertEqual(resp.status_code, 200)
		json = _loads(resp.content)
		self.assertEqual(type(json), type({}))
	def handle(self, *args, **options):
		from prometapi.models import _dumps, fetch_parkirisca_lpt, parse_parkirisca_lpt, ParkiriscaLPT
		import simplejson
		
		data = fetch_parkirisca_lpt()
		try:
			json = parse_parkirisca_lpt(*data)
		except simplejson.decoder.JSONDecodeError:
			json = None
		e = ParkiriscaLPT(json_data=_dumps(json), original_data=_dumps(data).encode('zlib').encode('base64'))
		e.save()
Beispiel #4
0
    def handle(self, *args, **options):
        from prometapi.models import _dumps, fetch_parkirisca_lpt, parse_parkirisca_lpt, ParkiriscaLPT
        import simplejson

        data = fetch_parkirisca_lpt()
        try:
            json = parse_parkirisca_lpt(*data)
        except simplejson.decoder.JSONDecodeError:
            json = None
        e = ParkiriscaLPT(
            json_data=_dumps(json),
            original_data=_dumps(data).encode('zlib').encode('base64'))
        e.save()