fabric_factory / src / worker / tests / __init__.py

yml ...@gmail.co… 2eca06b 
yml ...@gmail.co… 4ac2c5e 

yml ...@gmail.co… 2eca06b 
yml ...@gmail.co… 4ac2c5e 


yml ...@gmail.co… 2eca06b 

yml ...@gmail.co… 4ac2c5e 

yml ...@gmail.co… 2eca06b 










yml ...@gmail.co… 4ac2c5e 




yml ...@gmail.co… 2eca06b 




yml ...@gmail.co… 4ac2c5e 

yml ...@gmail.co… 2eca06b 
















yml ...@gmail.co… 0fa64a0 
dready d0454cc 
yml ...@gmail.co… 0fa64a0 
yml ...@gmail.co… 2eca06b 


yml ...@gmail.co… 6a89c05 
yml ...@gmail.co… 2eca06b 

yml ...@gmail.co… 5004289 


import os
import urllib2

from django.core.urlresolvers import reverse
from django.test.testcases import TestCase

from factory.tests import create_fabfile_recipe, create_build
from worker import WorkerError
from worker import Worker
from worker import settings

def create_worker():
    kitchen_path = settings.WORKER_KITCHEN
    worker_dict = {u'task': u'hello_world',
                   u'name': u'my build',
                   u'build_package_url': u'http://example.com/site_media/build_packages/1_recipeotPIHY.tar.bz2',
                   u'post_back_url': u'http://example.com/factory/build/update/1/'}
    worker = Worker(name=worker_dict['name'], task=worker_dict['task'],
                post_back_url=worker_dict['post_back_url'],
                build_package_url=worker_dict['build_package_url'],
                kitchen_path=kitchen_path)
    return worker

class WorkerTest(TestCase):
    def setUp(self):
        self.fabfile_recipe = create_fabfile_recipe(name="test recipe")
        self.build = create_build(fabfile_recipe=self.fabfile_recipe)
    def test_create_worker(self):
        """
        Test that I can build a Worker
        """
        worker = create_worker()
        
        
    def test_worker_download_build_package_wrong_url(self):
        worker = create_worker()
        try:
            worker.download_build_package()
        except Exception, e:
            self.assertEqual(True, isinstance(e, WorkerError))
    
class ExecuteTaskFromFabfile(TestCase):
    def setUp(self):
        self.fabfile_path = os.path.join(
            os.path.dirname(os.path.normpath(__file__)),
            "test_fabfile.py"
        )
        self.task = "hello_world"
        self.wrong_task = "wrong task"
        
    def test_execute_task_from_fabfile(self):
        output, error = Worker._execute_task_from_fabfile(self.fabfile_path, self.task)
        self.assertEqual(output, 'hello world\n[localhost] local: ls -l\n')
        self.assertEqual(error, "")
        
    def test_execute_wrong_task_from_fabfile(self):
        try:
            output, error = Worker._execute_task_from_fabfile(self.fabfile_path, self.wrong_task)
        except Exception, e:
            self.assertEqual(True, isinstance(e, WorkerError))
            
#class FaillingTest(TestCase):
#    def test_faillure(self):
#        self.assertEqual(True, False)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.