Before I start answering I don't know this particular bike so I could be wrong but try the following
If your getting a spark chances are its not the cdi itself more likely a part short i.e. plug lead in bad condition
if connecting the battery stops it working this points to a similar issue or a 'diode' issue if I remember correctly cdi units work AC if you connect a battery and the reverse polarity diode is blown it will short all the time (preventing any spark working, additionally this could be the stator/alternator partially shorting or breaking down you can test this with a voltmeter check your haynes manual for details of this check

maybe this will help:-
With the battery charged do the lights all work? if so most wiring ok no short on dc circuit!
if so do they work whilst kicking it over and ignition on
with battery connected? (yes main loom and stator OK - probably, No, intermittent - possible stator or diode, all off short somewhere)
with battery disconnected lights should glow at least a little otherwise short or stator issue
working all the time (unlikely to be a short except in main ignition circuit cdi to spark plug or cdi to chassis)
fuel test try
Kick the bike over with the ignition off and throttle fully open choke off (around 40 times) then smell the exhaust if it smells of fuel your carb is working (although it may be badly adjusted) go make a cup of tea as it will be flooded - then return to the bike and kick it with no or minimal throttle - My XR doesn't have a choke (removed as they have a habit of shattering) I kick it over 40 time with full throttle ignition off then go make a cup of tea - it will start first or second kick afterwards with half throttle.
Hope this helps