1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
   | """funkload MEP test
 
$Id$
"""
import unittest
import os, urllib, urllib2, time, sys, string
import random
import json
from funkload.FunkLoadTestCase import FunkLoadTestCase as fltc
from funkload.Lipsum import Lipsum as rand
from funkload.utils import Data
from urllib2 import urlopen
 
class RecuperationPhotos(fltc):
    """This test use a configuration file mep.conf"""
 
    def setUpCycle(self):
        """Setting up test."""
        self.logd("setUp.")
        self.label = 'Recuperation Photos test'
 
	#get configuration details from RecuperationPhotos.conf
 
	self.server_url = self.conf_get('main', 'url')
	self.assertEqual(self.server_url, "http://mep.magency.fr:3000/contacts.json")
 
	self.server_url_photos = self.conf_get('main', 'url_photos')
	self.assertEqual(self.server_url_photos, "http://mep.magency.fr:3000")
 
	#dir = self.conf_get('main','dir')
 
 
	response = self.urllib2.urlopen(server_url)
	the_dict = self.json.load(response)
	i = 0
	liste_photos = [0]*37
	while i <37 : 
		liste_photos[i] = the_dict[i]['avatar_url'].encode('utf-8')
		i+=1
 	choicePhoto = self.choice(liste_photos)	
	return choicePhoto
 
    def test_RecPhotos(self):
	server_url_Photos = self.server_url_Photos
	namePhoto=self.Lipsum().getWord()
	namePhoto=namePhoto+'.jpg'
 
	filephoto=self.open(namePhoto,'wb')
 
	filephoto.write(self.requests.get(server_url_photos+choicePhoto).content)
 
	filephoto.close()
 
    def tearDownCycle(self):
        """Setting up test."""
        self.logd("tearDown.")
 
if __name__ in ('main', '__main__'):
    unittest.main() | 
Partager