# Path: prometapi/compat.py
# def zlib_encode(data):
# 	if isinstance(data, type(u'')):
# 		data = data.encode('utf-8')
# 	return base64.b64encode(zlib.compress(data))


import unittest
import os
		import codecs
	import sys
from prometapi.compat import zlib_encode
		from prometapi.encoders import encrypt, decrypt
		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
			from prometapi import models
		self.assertEqual(data, data_back.rstrip('\x00'))

	def test_manythings(self):
		
		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)

# Path: prometapi/compat.py
# def zlib_encode(data):
# 	if isinstance(data, type(u'')):
# 		data = data.encode('utf-8')
# 	return base64.b64encode(zlib.compress(data))


# Path: prometapi/tests.py
import unittest
import os
		import codecs
	import sys
from prometapi.compat import zlib_encode
		from prometapi.encoders import encrypt, decrypt
		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
			from prometapi import models

		self.assertEqual(data, data_back.rstrip('\x00'))

	def test_manythings(self):
		
		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])))