def setUp(self): self.api_key = "consumer key" self.consumer = oauth.Consumer(self.api_key, "consumer secret") self.access_token = oauth.Token("oauth token", "oauth token secret") self.client = pyblr.Pyblr( oauth.Client(self.consumer, self.access_token)) self.params = {"name": "toqoz", "sex": "male"} self.parsed_params = "name=toqoz&sex=male" self.trackar = TraceTracker() mock("pyblr.Pyblr.get", tracker=self.trackar) mock("pyblr.Pyblr.post", tracker=self.trackar)
def test_check_prereqs(self): "Test active_site_finder.check_prereqs method" # THIS TEST HAS TO BE UPDATED WHEN NEW PROFILES ARE ADDED TO THE MODULE! self.tt = TraceTracker() mock('utils.locate_executable', returns="/my/path/to/executable", tracker=self.tt) mock('utils.locate_file', returns="/my/path/to/file", tracker=self.tt) result = self.my_ASF.check_prereqs() self.assertListEqual(result, [], "return empty list if executables/files are found") expected = """ Called utils.locate_executable('blastp') Called utils.locate_executable('hmmpfam2') Called utils.locate_executable('hmmscan') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/PKSI-KR.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/PKSI-KS_N.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/PKSI-KS_C.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/PKSI-AT.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/PKSI-ACP.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/PKSI-DH.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/PKSI-KR.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/Thioesterase.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/PKSI-ER.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/PKSI-AT.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/aa-activating.aroundLys.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/p450.hmm3')""" assert_same_trace(self.tt, expected) restore() self.tt = TraceTracker() mock('utils.locate_executable', returns=None, tracker=self.tt) mock('utils.locate_file', returns="/my/path/to/file", tracker=self.tt) result = self.my_ASF.check_prereqs() expected = ["Failed to locate file: 'blastp'", "Failed to locate file: 'hmmpfam2'", "Failed to locate file: 'hmmscan'"] self.assertListEqual(result, expected, "test result if file not found") restore()
def setUp(self): self.config = Namespace() self.tt = TraceTracker() self.fake_features = [ _make_fake_feature(10, 20, 0.1, 'FAKE007'), _make_fake_feature(30, 40, 0.3, 'PF00106'), _make_fake_feature(50, 60, 0.4, 'PF00107'), _make_fake_feature(60, 70, 0.7, 'PF00109'), _make_fake_feature(70, 80, 0.98, 'PF08484'), _make_fake_feature(90, 100, 0.8, 'PF02401'), _make_fake_feature(100, 110, 0.32, 'PF04369'), _make_fake_feature(110, 120, 1.0, 'PF00128'), _make_fake_feature(130, 140, 0.2, 'FAKE234'), _make_fake_feature(500, 505, pfam_id='FAKE505'), _make_fake_feature(1010, 1020, 0.1, 'FAKE007'), _make_fake_feature(1030, 1040, 0.3, 'PF00106'), _make_fake_feature(1050, 1060, 0.4, 'PF00107'), _make_fake_feature(1060, 1070, 0.7, 'PF00109'), _make_fake_feature(1070, 1080, 0.98, 'PF08484'), _make_fake_feature(1090, 1100, 0.8, 'PF02401'), _make_fake_feature(1100, 1110, 0.32, 'PF04369'), _make_fake_feature(1110, 1120, 1.0, 'PF00128'), ] mock('antismash.utils.get_cds_features', tracker=self.tt, returns=self.fake_features) self.config.cdsnr = 5 self.config.cf_prob_thres = 0.6 self.config.cf_npfams = 5 self.config.borderpredict = False
def setUp(self): self._old_max_evalue = cluster_hmmer.MAX_EVALUE self._old_min_score = cluster_hmmer.MIN_SCORE cluster_hmmer.MAX_EVALUE = 0.02 cluster_hmmer.MIN_SCORE = 1. self.config = build_config([], isolated=True, modules=antismash.get_all_modules()) self.latest_pfam = pfamdb.find_latest_database_version( self.config.database_dir) self.tracer = TraceTracker() self.file_list = [ 'Pfam-A.hmm', 'Pfam-A.hmm.h3f', 'Pfam-A.hmm.h3i', 'Pfam-A.hmm.h3m', 'Pfam-A.hmm.h3p' ] mock('antismash.common.path.locate_file', returns_iter=self.file_list, tracker=self.tracer) mock('antismash.common.subprocessing.run_hmmscan', returns=[]) self.expected_trace = """Called antismash.common.path.locate_file( '{0}/pfam/{1}/Pfam-A.hmm') Called antismash.common.path.locate_file( '{0}/pfam/{1}/Pfam-A.hmm.h3f') Called antismash.common.path.locate_file( '{0}/pfam/{1}/Pfam-A.hmm.h3i') Called antismash.common.path.locate_file( '{0}/pfam/{1}/Pfam-A.hmm.h3m') Called antismash.common.path.locate_file( '{0}/pfam/{1}/Pfam-A.hmm.h3p')""".format(self.config.database_dir, self.latest_pfam)
def setUp(self): self.tt = TraceTracker() self.options = Namespace(full_hmmer=True, clusterblast=True, subclusterblast=True, knownclusterblast=True, smcogs=True) mock('antismash.generic_modules.fullhmmer.check_prereqs', returns=['fullhmmer'], tracker=self.tt) mock('antismash.generic_modules.genefinding.check_prereqs', returns=['genefinding'], tracker=self.tt) mock('antismash.generic_modules.hmm_detection.check_prereqs', returns=['hmm_detection'], tracker=self.tt) mock('antismash.generic_modules.clusterblast.check_prereqs', returns=['clusterblast'], tracker=self.tt) mock('antismash.generic_modules.subclusterblast.check_prereqs', returns=['subclusterblast'], tracker=self.tt) mock('antismash.generic_modules.knownclusterblast.check_prereqs', returns=['knownclusterblast'], tracker=self.tt) mock('antismash.generic_modules.smcogs.check_prereqs', returns=['smcogs'], tracker=self.tt)
def setUp(self): self.tt = TraceTracker() mock('helperlibs.bio.seqio.write', tracker=self.tt) self.options = Mock('options', tracker=self.tt, outputfoldername='test', input_type='nucl') rec1_features = [ generate_cluster_feature(23, 42, 'lantipeptide', 1), generate_cluster_feature(300, 500, 'nrps', 2) ] rec2_features = [ generate_cluster_feature(50, 70, 'lassopeptide', 3), generate_cluster_feature(500, 700, 't1pks', 4) ] record1 = SeqRecord(UnknownSeq(1000), 'record1', name='record1', features=rec1_features) record2 = SeqRecord(UnknownSeq(1000), 'record2', name='record2', features=rec2_features) self.records = [record1, record2] self.expected_template = """\
def setUp(self): self.tt = TraceTracker() self.cwd = '/old/cur/dir' mock("tempfile.mkdtemp", tracker=self.tt, returns="/fake/tmp/dir") mock("shutil.rmtree", tracker=self.tt) mock("os.getcwd", tracker=self.tt, returns=self.cwd) mock("os.chdir", tracker=self.tt, returns_func=self._fake_chdir)
def setUp(self): self.api = MediaMosaAPI('http://video.example.com') self.tt = TraceTracker() mock('self.api.session', tracker=self.tt) self.response = Mock('requests.Response') self.response.status_code = 200 self.api.session.get.mock_returns = self.response
def setUp(self): self.rec = FakeRecord() self.types = [ "CDS", "gene", "CDS", "PFAM_domain", "cluster", "CDS", "aSDomain", ] idx = 1 for t in self.types: f = FakeFeature(t) f.qualifiers['locus_tag'] = ["orf%04d" % idx] f.qualifiers['note'] = [ 'PFAM-Id: PF%05d' % idx, 'smCOG: SMCOG{0:04d}:FAKE{0:04d} (Score: {0} ; E-value: 1.1e-1{0};' .format(idx) ] f.qualifiers['db_xref'] = ['PFAM: PF%05d' % idx] f.qualifiers['translation'] = ['FAKESEQ'] self.rec.features.append(f) idx += 1 self.trace_tracker = TraceTracker()
def setUp(self): self.trace_tracker = TraceTracker() def fake_exit(code): raise IntTestExit(code) mock("sys.exit", tt=self.trace_tracker, returns_func=fake_exit)
def test__execute_tool(self): "Test active_site_finder._execute_tool method" self.tt = TraceTracker() self.tt2 = TraceTracker() mock('utils.execute', returns=["shell output", 0, 0], tracker=self.tt) mock('SearchIO.parse', returns=["SearchIO object"], tracker=self.tt2) result = self.my_ASF._execute_tool(self.ETObj.find('./analysis'), fileName="testTempfile") self.assertListEqual(result, ["SearchIO object"]) expected = """ Called utils.execute( ['hmmscan', '--domE', '0.1', '--cpu', '1', '.../antismash/generic_modules/active_site_finder/hmm/p450.hmm3', 'testTempfile']) """ assert_same_trace(self.tt, expected) expected = " Called SearchIO.parse(<cStringIO.StringI object at ...>, 'hmmer3-text')" assert_same_trace(self.tt2, expected) restore() self.tt = TraceTracker() self.tt2 = TraceTracker() mock('utils.execute', returns=["shell output", 0, 0], tracker=self.tt) mock('SearchIO.parse', returns=["SearchIO object"], tracker=self.tt2) result = self.my_ASF._execute_tool( self.ETObj.find('./analysis'), stdin_data="fasta sequence from stdin") self.assertListEqual(result, ["SearchIO object"]) expected = """ Called utils.execute( ['hmmscan', '--domE', '0.1', '--cpu', '1', '.../antismash/generic_modules/active_site_finder/hmm/p450.hmm3'], input='fasta sequence from stdin') """ assert_same_trace(self.tt, expected) expected = " Called SearchIO.parse(<cStringIO.StringI object at ...>, 'hmmer3-text')" assert_same_trace(self.tt2, expected) restore() self.tt = TraceTracker() del self.tt2
def setUp(self): "set up database test framework and test for db connection" self.options = Namespace() self.options.BioSQLconfig = Namespace() self.options.BioSQLconfig.dbdriver = 'psycopg2' self.options.BioSQLconfig.dbuser = '******' self.options.BioSQLconfig.dbpass = '******' self.options.BioSQLconfig.dbhost = 'localhost' self.options.BioSQLconfig.dbport = '5432' self.options.BioSQLconfig.dbdb = 'antiSMASHnosetest' self.options.BioSQLnamespace = 'test' self.trace_tracker = TraceTracker() # test correct method call for db.asDB)() mock('BioSeqDatabase.open_database', tracker=self.trace_tracker, returns=['mock result']) expected = """Called BioSeqDatabase.open_database( db='antiSMASHnosetest', driver='psycopg2', host='localhost', passwd='biosql', port='5432', user='******') """ mydb = db.aSDB(self.options) assert_same_trace(self.trace_tracker, expected) # restore mocked objects that other tests can run with the original code restore() self.trace_tracker = TraceTracker() #test initializing database object db.__init__" try: mydb = db.aSDB(self.options) except Exception: self.skipTest( 'database connection could not be established, skipping tests') self.assertIsInstance(mydb, db.aSDB) self.mydb = mydb
def setUp(self): self.tracker = TraceTracker() self.locate_exe = Mock('antismash.common.path.locate_executable', tracker=self.tracker, returns="/fake/path/to/binary") mock('antismash.common.path.locate_executable', mock_obj=self.locate_exe, tracker=self.tracker)
def test__init(self): "Test active_site_finder.__init__ method" self.tt = TraceTracker() class dummyET: def __init__(self): pass def getroot(self): return dummyET() def findall(self, a): return "ET-Subtree" mock('ET.parse', returns=dummyET(), tracker=self.tt) #mock('ET.getroot', returns="XMLTree", tracker=self.tt) #mock('ET.findall', returns="XMLSubtree", tracker=self.tt) mock( 'antismash.generic_modules.active_site_finder.active_site_finder.check_prereqs', returns=[], tracker=self.tt) expected = """ Called ET.parse( '.../antismash/generic_modules/active_site_finder/config/SignatureResources.xml')""" ASF = antismash.generic_modules.active_site_finder.active_site_finder( self.seq_record, self.options) assert_same_trace(self.tt, expected) # restore mocked objects that other tests can run with the original code restore() self.tt = TraceTracker() # now acutally generate ASF object myASF = antismash.generic_modules.active_site_finder.active_site_finder( self.seq_record, self.options) assert_is_instance( myASF, antismash.generic_modules.active_site_finder.active_site_finder) self.my_ASF = myASF
def setUp(self): """Mock out httplib.HTTPConnection and httplib.HTTPSConnection""" self.trace_tracker = TraceTracker() self.conn = Mock('httplib.HTTPConnection', tracker=self.trace_tracker) mock('httplib.HTTPConnection', mock_obj=self.conn) mock('httplib.HTTPSConnection', mock_obj=self.conn) self.conn.mock_returns = self.conn
def __init__(self, *args, **kw): super(TestCase, self).__init__(*args, **kw) self.tt = TraceTracker() self.request = testing.DummyRequest() self.request.resource_url = None self.config = testing.setUp(request=self.request) self.config.add_settings(settings)
def setUp(self): self.tt = TraceTracker() # Fall over when we try to call the real download functions mock('utils.fix_supercontig_record', tracker=self.tt, raises=NotImplementedError) mock('utils.fix_wgs_master_record', tracker=self.tt, raises=NotImplementedError)
def setUp(self): self.maxDiff = None self.tt = TraceTracker() self.locate_exe = Mock('antismash.utils.locate_executable', tracker=self.tt, returns="/fake/path/to/binary") mock('antismash.utils.locate_executable', mock_obj=self.locate_exe, tracker=self.tt)
def setUp(self): self.api = MediaMosaAPI('http://video.example.com') self.tt = TraceTracker() mock('self.api.session', tracker=self.tt) self.response = Mock('requests.Response') self.response.status_code = 200 self.api.session.get.mock_returns = self.response self.partial_dict = { u'is_original_file': u'FALSE', u'is_streamable': u'FALSE', u'is_downloadable': u'FALSE', u'app_id': u'2', u'transcode_inherits_acl': u'TRUE', u'tag': '', u'response_metafile_available': u'TRUE', u'mediafile_id_source': u'u2ilZNiHdl7iNUdexL7BcFMY', u'asset_id': u'g1QkoSmSeHdWfGkMKlOlldLn', u'mediafile_id': u'Md2RgaUEVFhfJMeUIbwPOMei', u'transcode_profile_id': u'17', u'filename': u'Sintel_Trailer1.1080p.DivX_Plus_HD.mp4', u'is_protected': u'FALSE', u'ega_stream_url': '', u'file_extension': u'mp4', 'metadata': { u'is_inserted_md': u'FALSE', u'fps': u'24', u'bpp': u'0.31', u'file_duration': u'00:00:52.20', u'colorspace': u'yuv420p', u'container_type': u'mov;mp4;m4a;3gp;3g2;mj2', u'height': u'478', u'channels': u'stereo', u'width': u'852', u'sample_rate': u'44100', u'filesize': u'20543936', u'audio_codec': u'aac', u'video_codec': u'h264', u'is_hinted': u'TRUE', u'bitrate': u'3012', u'mime_type': u'video/mp4' }, u'ega_download_url': '', u'ega_play_url': '', u'tool': u'ffmpeg', u'response_plain_available': u'TRUE', u'owner_id': u'krkeppen', u'response_object_available': u'TRUE', u'created': u'2012-07-05 11:38:14', u'changed': u'2012-07-05 11:38:14', u'uri': '', u'is_still': u'FALSE', u'command': u'audiocodec:libfaac;audiobitrate:128000;audiosamplingrate:44100;audiochannels:2;videocodec:libx264;videopreset_quality:slow;videopreset_profile:baseline;2_pass_h264_encoding:2;videobitrate:800000;qmax:17;size:852x480;maintain_aspect_ratio:yes', u'group_id': '' }
class TestCase(unittest.TestCase): def __init__(self, *args, **kw): super(TestCase, self).__init__(*args, **kw) self.tt = TraceTracker() self.request = testing.DummyRequest() self.request.resource_url = None self.config = testing.setUp(request=self.request) self.config.add_settings(settings) def setUp(self, *args, **kw): mock('self.request.resource_url', tracker=self.tt, returns=True) def tearDown(self): restore() def assertTrace(self, want): assert self.tt.check(want), self.tt.diff(want)
def setUp(self): self.config = Namespace() self.config.cpus = 2 config.set_config(self.config) self.tt = TraceTracker() proc = Mock('proc', tracker=self.tt, returncode=0) proc.communicate = Mock('proc.communicate', returns=('output', 'error'), tracker=self.tt) mock('subprocess.Popen', tracker=self.tt, returns=proc)
def setUp(self): self.tt = TraceTracker() mock('helperlibs.bio.seqio.write', tracker=self.tt) self.options = Mock('options', tracker=self.tt, outputfoldername='test', input_type='nucl') record1 = Mock('record1', tracker=self.tt, id='record1', features=[]) record2 = Mock('record2', tracker=self.tt, id='record2', features=[]) self.records = [record1, record2]
def setUp(self): self.config = Namespace() self.config.cpus = 2 config.set_config(self.config) self.tt = TraceTracker() proc = Mock('proc', tracker=self.tt, returncode=0) proc.communicate = Mock('proc.communicate', returns=('output', 'error'), tracker=self.tt) mock('subprocess.Popen', tracker=self.tt, returns=proc) self.tmpdir = tempfile.mkdtemp(prefix="as_tests_util")
def setUp(self): self.api_key = "consumer key" self.consumer = oauth.Consumer(self.api_key, "consumer secret") self.access_token = oauth.Token("oauth token", "oauth token secret") self.client = pyblr.Pyblr(oauth.Client(self.consumer, self.access_token)) self.params = { "name": "toqoz", "sex": "male" } self.parsed_params = "name=toqoz&sex=male" self.trackar = TraceTracker() mock("pyblr.Pyblr.get", tracker=self.trackar) mock("pyblr.Pyblr.post", tracker=self.trackar)
def test__run_external_tool(self): "Test active_site_finder._run_external_tool method" self.tt = TraceTracker() SeqFeatureList = utils.get_all_features_of_type_with_query(self.seq_record, "PFAM_domain", "domain", "p450") self.assertEqual(6, len(SeqFeatureList)) mock('antismash.generic_modules.active_site_finder.active_site_finder._execute_tool', returns=["external program call successful"], tracker=self.tt) result = self.my_ASF._run_external_tool(self.ETObj.find('./analysis'), SeqFeatureList) expected = ["external program call successful"] self.assertListEqual(result, expected)
def setUp(self): self.url = 'http://video.example.com' self.username = '******' self.app_id = 5 self.secret = 'test_secret' # mock requests library self.tt = TraceTracker() self.api = MediaMosaAPI(self.url) mock('self.api.session', tracker=self.tt) self.response = Mock('requests.Response') self.response.status_code = 200 self.api.session.get.mock_returns = self.response self.api.session.post.mock_returns = self.response
def setUp(self): repo = Mock('repo') repo.name = 'standard' repo.arch = 'x86_64' package = Mock('package') package.project = 'openSUSE:11.3' package.name = 'osc' self.build = obswatch.Build(package=package, repo=repo, interested={'geeko':'*****@*****.**'}) self.package = package self.tt = TraceTracker() obswatch.SLEEP_TIME = 0
def test_generate_confirmation_mail(): """Test generation of a confirmation email""" # abuse the TraceTracker to make use of doctest features tt = TraceTracker() mail = utils.generate_confirmation_mail(message="Test!") tt.out.write(mail) expected = """We have received your feedback to antiSMASH and will reply to you as soon as possible. Your message was: <BLANKLINE> Test! """ assert_same_trace(tt, expected)
def setUp(self): f_config = Namespace(score='1', evalue='0.02') self.config = Namespace(fullhmmer=f_config) self.tt = TraceTracker() mock('antismash.utils.locate_executable', returns='hmmsearch', tracker=self.tt) self.file_list = [ 'Pfam-A.hmm', 'Pfam-A.hmm.h3f', 'Pfam-A.hmm.h3i', 'Pfam-A.hmm.h3m', 'Pfam-A.hmm.h3p' ] mock('antismash.utils.locate_file', returns_iter=self.file_list, tracker=self.tt) mock('antismash.utils.run_hmmscan', returns=[])
def setUp(self): "set up database connection" # restore all mocked methods restore() #Open testfile and parse it with Biopython testfile = path.join(path.dirname(__file__), "AAA26493.embl") testfile_fh = open(testfile, "rU") self.seq_record = SeqIO.read(testfile_fh, 'embl') self.options = Namespace() self.options.BioSQLconfig = Namespace() self.options.BioSQLconfig.dbdriver = 'psycopg2' self.options.BioSQLconfig.dbuser = '******' self.options.BioSQLconfig.dbpass = '******' self.options.BioSQLconfig.dbhost = 'localhost' self.options.BioSQLconfig.dbport = '5432' self.options.BioSQLconfig.dbdb = 'antiSMASHnosetest' self.options.BioSQLnamespace = 'test' self.options.dbnamespace = self.options.BioSQLnamespace self.trace_tracker = TraceTracker() try: mydb = db.aSDB(self.options) except Exception: self.skipTest( 'database connection could not be established, skipping tests') if not mydb: self.skipTest('database connection impossible; skipping tests') try: del mydb.server[self.options.BioSQLnamespace] mydb.commit() except Exception: pass mydb.generate_namespace(self.options.BioSQLnamespace, 'test namespace for nosetests') mydb.connect(self.options.BioSQLnamespace) rec_no = mydb.load_records([self.seq_record]) mydb.commit() self.mydb = mydb
def test_get_record(self): "Test get_record() function" Fake_seq_rec = Namespace() Fake_seq_rec.name = 'fakedName' mock('db.aSDB.get_record_by_name', tracker=self.trace_tracker, returns=Fake_seq_rec) db_seq_rec = db.get_record('AAA26493', self.options) expected = "Called db.aSDB.get_record_by_name('AAA26493')" assert_same_trace(self.trace_tracker, expected) restore() self.trace_tracker = TraceTracker() db_seq_rec = db.get_record('AAA26493', self.options) myrecord_class = db_seq_rec.__class__.__name__ self.assertEqual(myrecord_class, "DBSeqRecord") self.assertEqual(str(db_seq_rec.seq), str(self.seq_record.seq)) self.assertEqual(db_seq_rec.id, self.seq_record.id) self.assertEqual(db_seq_rec.name, self.seq_record.name)
def setUp(self): self.api = MediaMosaAPI('http://video.example.com') self.tt = TraceTracker() mock('self.api.session', tracker=self.tt) self.response = Mock('requests.Response') self.response.status_code = 200 self.api.session.get.mock_returns = self.response self.item_dict = { u'provider_id': '', u'is_unappropriate': u'FALSE', u'videotimestampmodified': u'2012-07-05 11:34:35', u'app_id': u'2', u'is_favorite': u'FALSE', u'has_streamable_mediafiles': u'TRUE', u'viewed': u'4', u'asset_id': u'g1QkoSmSeHdWfGkMKlOlldLn', u'ega_still_url': '', u'granted': u'TRUE', u'played': u'1', u'mediafile_duration': u'00:00:52.20', # u'videotimestamp': u'2012-07-05 11:34:01', # cleared it for partial u'vpx_still_url': u'http://filvideod.ugent.be/media/17/Z/Z14cWALWKmfTRjTUKhhQQLv2.jpeg', u'owner_id': u'krkeppen', u'is_empty_asset': u'FALSE', u'play_restriction_end': '', u'asset_property_is_hidden': u'FALSE', u'dublin_core': {u'publisher': u'Kristof Keppens', u'rights': u'Kristof Keppens', u'description': u'test', u'language': u'nl', u'creator': u'Kristof Keppens', u'format': u'streaming video', u'coverage_spatial': '', u'date': '', u'relation': '', u'source': u'ugent', u'contributor': u', ', u'title': u'test sintel 2', u'identifier': '', u'type': u'video', u'coverage_temporal': '', u'subject': u'test'}, u'reference_id': '', u'isprivate': u'TRUE', u'qualified_dublin_core': {u'isformatof': '', u'description_abstract': '', u'license': '', u'created': '', u'issued': '', u'rightsholder': '', u'hasformat': '', u'title_alternative': '', u'format_medium': '', u'format_extent': '', u'isreferencedby': ''}, u'mediafile_container_type': u'matroska;webm', u'is_unappropiate': u'FALSE', u'is_external': u'FALSE', u'is_protected': u'FALSE', u'play_restriction_start': '', u'group_id': ''}
class TestPyblr: def setUp(self): self.api_key = "consumer key" self.consumer = oauth.Consumer(self.api_key, "consumer secret") self.access_token = oauth.Token("oauth token", "oauth token secret") self.client = pyblr.Pyblr(oauth.Client(self.consumer, self.access_token)) self.params = { "name": "toqoz", "sex": "male" } self.parsed_params = "name=toqoz&sex=male" self.trackar = TraceTracker() mock("pyblr.Pyblr.get", tracker=self.trackar) mock("pyblr.Pyblr.post", tracker=self.trackar) def assert_not_raise(self, excClass, callable_, *args, **kwargs): try: callable_(*args, **kwargs) except excClass: if hasattr(excClass,"__name__"): excName = excClass.__name__ else: excName = str(excClass) message = "Against the expectationm Raised %s" % (excClass) raise AssertionError(message) def create_response(self, status, msg): result = ( {}, json.dumps({ "meta": { "status": status, "msg": msg }, "response": {} }) ) return result # when assert_same_trace # required space between colon(:) and value in dict # [use this two times or more in same method] required call trackar.clear() def info_test(self): self.client.info("toqoz.tumblr.com") assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.get('/v2/blog/toqoz.tumblr.com/info', %s) """ % ({'api_key': self.api_key})) def followers_test(self): self.client.followers("toqoz.tumblr.com") assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.get('/v2/blog/toqoz.tumblr.com/followers', %s) """ % ({})) self.trackar.clear() self.client.followers("toqoz.tumblr.com", {"limit": 10}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.get('/v2/blog/toqoz.tumblr.com/followers', %s) """ % ({'limit': 10})) def posts_test(self): self.client.posts("toqoz.tumblr.com") assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.get('/v2/blog/toqoz.tumblr.com/posts', %s) """ % ({'api_key': self.api_key})) self.trackar.clear() self.client.posts("toqoz.tumblr.com", {"type": "photo"}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.get('/v2/blog/toqoz.tumblr.com/posts', %s) """ % ({'api_key': self.api_key, 'type': 'photo'})) def queue_test(self): self.client.queue("toqoz.tumblr.com") assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.get('/v2/blog/toqoz.tumblr.com/posts/queue', %s) """ % ({})) def draft_test(self): self.client.draft("toqoz.tumblr.com") assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.get('/v2/blog/toqoz.tumblr.com/posts/draft', %s) """ % ({})) def submission_test(self): self.client.submission("toqoz.tumblr.com") assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.get('/v2/blog/toqoz.tumblr.com/posts/submission', %s) """ %({})) def create_post_test(self): self.client.create_post("toqoz.tumblr.com", {'type': 'text', 'body': 'text'}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.post('/v2/blog/toqoz.tumblr.com/post', %s) """ % ({"type": "text", "body": "text"})) self.trackar.clear() self.client.create_post("toqoz.tumblr.com", {"type": "photo", "source": "http://example.com/photo.png"}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.post('/v2/blog/toqoz.tumblr.com/post', %s) """ % ({'type': 'photo', 'source': 'http://example.com/photo.png'})) self.trackar.clear() self.client.create_post("toqoz.tumblr.com", {"type": "quote", "quote": "quote"}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.post('/v2/blog/toqoz.tumblr.com/post', %s) """ % ({'type': 'quote', 'quote': 'quote'})) self.trackar.clear() self.client.create_post("toqoz.tumblr.com", {'type': 'like', 'url': 'http://example.com/'}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.post('/v2/blog/toqoz.tumblr.com/post', %s) """ % ({'type': 'like', 'url': 'http://example.com/'})) self.trackar.clear() self.client.create_post("toqoz.tumblr.com", {"type": "chat", "conversation": "conversation"}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.post('/v2/blog/toqoz.tumblr.com/post', %s) """ % ({'type': 'chat', 'conversation': 'conversation'})) self.trackar.clear() self.client.create_post("toqoz.tumblr.com", {"type": "audio", "external_url": "http://example.com/audio.mp3"}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.post('/v2/blog/toqoz.tumblr.com/post', %s) """ % ({'type': 'audio', 'external_url': 'http://example.com/audio.mp3'})) self.trackar.clear() self.client.create_post("toqoz.tumblr.com", {"type": "video", "embed": "<embed>code</embed>"}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.post('/v2/blog/toqoz.tumblr.com/post', %s) """ % ({"type": "video", "embed": "<embed>code</embed>"})) def edit_post_test(self): self.client.edit_post("toqoz.tumblr.com", {"id": 123456789, "type": "text", "body": "new text"}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.post('/v2/blog/toqoz.tumblr.com/post/edit', %s) """ % ({"id": 123456789, "type": "text", "body": "new text"})) def reblog_post_test(self): self.client.reblog_post("toqoz.tumblr.com", {"id": 123456789, "reblog_key": "adcdefg"}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.post('/v2/blog/toqoz.tumblr.com/post/reblog', %s) """ % ({"id": 123456789, "reblog_key": "adcdefg"})) self.trackar.clear() self.client.reblog_post("toqoz.tumblr.com", {"id": 123456789, "reblog_key": "adcdefg", "comment": "comment"}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.post('/v2/blog/toqoz.tumblr.com/post/reblog', %s) """ % ({"id": 123456789, "reblog_key": "adcdefg", "comment": "comment"})) def delete_post_test(self): self.client.delete_post("toqoz.tumblr.com", {"id": 123456789}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.post('/v2/blog/toqoz.tumblr.com/post/delete', %s) """ % ({"id": 123456789})) def dashboard_test(self): self.client.dashboard() assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.get('/v2/user/dashboard', %s) """ % ({})) self.trackar.clear() self.client.dashboard({"type": "photo"}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.get('/v2/user/dashboard', %s) """ % ({"type": "photo"})) def likes_test(self): self.client.likes() assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.get('/v2/user/likes', %s) """ % ({})) self.trackar.clear() self.client.likes({"limit": 10}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.get('/v2/user/likes', %s) """ % ({"limit": 10})) def following_test(self): self.client.following() assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.get('/v2/user/following', %s) """ % ({})) self.trackar.clear() self.client.following({"limit": 10}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.get('/v2/user/following', %s) """ % ({"limit": 10})) def follow_test(self): self.client.follow({"url": "toqoz.tumblr.com"}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.post('/v2/user/follow', %s) """ % ({"url": "toqoz.tumblr.com"})) def unfollow_test(self): self.client.unfollow({"url": "toqoz.tumblr.com"}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.post('/v2/user/unfollow', %s) """ % ({"url": "toqoz.tumblr.com"})) def info_user_test(self): self.client.info_user({}) assert_same_trace(self.trackar, """\ Called pyblr.Pyblr.get('/v2/user/info', %s) """ % ({})) def parse_params_test(self): assert_equals(self.client.parse_params(self.params), self.parsed_params) def APIError_test(self): self.assert_not_raise(pyblr.APIError, lambda: self.client.parse_response(self.create_response("200", "OK"))) self.assert_not_raise(pyblr.APIError, lambda: self.client.parse_response(self.create_response("300", "Found"))) assert_raises(pyblr.APIError, lambda: self.client.parse_response(self.create_response("401", "Not Authorized"))) assert_raises(pyblr.APIError, lambda: self.client.parse_response(self.create_response("404", "Not Found")))
def setUp(self): self.tt = TraceTracker() mock('utils.get_aa_sequence', tracker=self.tt, returns="FAKESEQ")
def setUp(self): self.tt = TraceTracker() self.hmmpfam_return_vals = [] mock('utils.run_hmmpfam2', tracker=self.tt, returns=self.hmmpfam_return_vals)
def setUp(self): self.trace_tracker = TraceTracker() self.hmmpfam_return_vals = [] mock('subprocessing.run_hmmpfam2', tracker=self.trace_tracker, returns=self.hmmpfam_return_vals)
def setUp(self): self.trace_tracker = TraceTracker() mock('logging.debug', tracker=self.trace_tracker, returns=None)
class TestMediaMosaResource(unittest.TestCase): """Tests the generic functionality of a MediaMosaResource. This is done using the Asset object as concrete implementation. """ def setUp(self): self.api = MediaMosaAPI('http://video.example.com') self.tt = TraceTracker() mock('self.api.session', tracker=self.tt) self.response = Mock('requests.Response') self.response.status_code = 200 self.api.session.get.mock_returns = self.response self.item_dict = { u'provider_id': '', u'is_unappropriate': u'FALSE', u'videotimestampmodified': u'2012-07-05 11:34:35', u'app_id': u'2', u'is_favorite': u'FALSE', u'has_streamable_mediafiles': u'TRUE', u'viewed': u'4', u'asset_id': u'g1QkoSmSeHdWfGkMKlOlldLn', u'ega_still_url': '', u'granted': u'TRUE', u'played': u'1', u'mediafile_duration': u'00:00:52.20', # u'videotimestamp': u'2012-07-05 11:34:01', # cleared it for partial u'vpx_still_url': u'http://filvideod.ugent.be/media/17/Z/Z14cWALWKmfTRjTUKhhQQLv2.jpeg', u'owner_id': u'krkeppen', u'is_empty_asset': u'FALSE', u'play_restriction_end': '', u'asset_property_is_hidden': u'FALSE', u'dublin_core': {u'publisher': u'Kristof Keppens', u'rights': u'Kristof Keppens', u'description': u'test', u'language': u'nl', u'creator': u'Kristof Keppens', u'format': u'streaming video', u'coverage_spatial': '', u'date': '', u'relation': '', u'source': u'ugent', u'contributor': u', ', u'title': u'test sintel 2', u'identifier': '', u'type': u'video', u'coverage_temporal': '', u'subject': u'test'}, u'reference_id': '', u'isprivate': u'TRUE', u'qualified_dublin_core': {u'isformatof': '', u'description_abstract': '', u'license': '', u'created': '', u'issued': '', u'rightsholder': '', u'hasformat': '', u'title_alternative': '', u'format_medium': '', u'format_extent': '', u'isreferencedby': ''}, u'mediafile_container_type': u'matroska;webm', u'is_unappropiate': u'FALSE', u'is_external': u'FALSE', u'is_protected': u'FALSE', u'play_restriction_start': '', u'group_id': ''} # _mmmeta.state def test_create_empty_asset(self): """Tests if an empty asset can be created""" a = Asset('g1QkoSmSeHdWfGkMKlOlldLn') self.assertEqual(a._mmmeta.state, MediaMosaResource.STATE.EMPTY) def test_create_partial_asset(self): """Tests if a partially pre-filled asset can be created""" a = Asset.fromdict(self.item_dict) self.assertEqual(a._mmmeta.state, MediaMosaResource.STATE.PARTIAL) def test_create_full_asset(self): """Tests if an fully pre-filled asset can be created""" a = Asset.fromdict(self.item_dict, full=True) self.assertEqual(a._mmmeta.state, MediaMosaResource.STATE.FULL) # _mmmeta.api def test_create_connected_asset(self): """Tests if a connected asset can be created""" a = Asset('g1QkoSmSeHdWfGkMKlOlldLn', api=self.api) self.assertTrue(a.is_connected()) def test_create_unconnected_asset(self): """Tests if an unconnected asset can be created""" a = Asset('g1QkoSmSeHdWfGkMKlOlldLn') self.assertFalse(a.is_connected()) # accessing supplied data def test_can_access_asset_data(self): """Tests if pre-filled data can be accessed""" a = Asset.fromdict(self.item_dict) self.assertEquals(a.asset_id, 'g1QkoSmSeHdWfGkMKlOlldLn') self.assertIsInstance(a.is_favorite, bool) self.assertIsInstance(a.videotimestampmodified, datetime.datetime) self.assertRaises(Exception, a.some_unexisting_attribute) self.assertEqual(a._mmmeta.state, MediaMosaResource.STATE.PARTIAL) # accessing unsupplied data def test_accessing_empty_asset(self): """Tests if an empty asset will automatically fill itself if queried""" # setup self.response.content = open('tests/data/get_asset_id_response.xml')\ .read() # test asset = Asset('g1QkoSmSeHdWfGkMKlOlldLn', api=self.api) # validate self.assertIsInstance(asset.is_favorite, bool) self.assertNotEquals(self.tt.dump(), '') self.tt.clear() self.assertIsInstance(asset.videotimestamp, datetime.datetime) self.assertEquals(self.tt.dump(), '') self.assertRaises(Exception, asset.some_unexisting_attribute) self.assertEqual(asset._mmmeta.state, MediaMosaResource.STATE.FULL) def test_accessing_partial_asset(self): """Tests if a partial asset will automatically fill itself if queried""" # setup self.response.content = open('tests/data/get_asset_id_response.xml')\ .read() # test asset = Asset.fromdict(self.item_dict, api=self.api, full=False) # validate self.assertIsInstance(asset.is_favorite, bool) self.assertEquals(self.tt.dump(), '') self.assertIsInstance(asset.videotimestamp, datetime.datetime) self.assertNotEquals(self.tt.dump(), '') self.assertRaises(Exception, asset.some_unexisting_attribute) self.assertEqual(asset._mmmeta.state, MediaMosaResource.STATE.FULL)
class TestLoginFunctions(unittest.TestCase): def setUp(self): self.url = 'http://video.example.com' self.username = '******' self.app_id = 5 self.secret = 'test_secret' # mock requests library self.tt = TraceTracker() self.api = MediaMosaAPI(self.url) mock('self.api.session', tracker=self.tt) self.response = Mock('requests.Response') self.response.status_code = 200 self.api.session.get.mock_returns = self.response self.api.session.post.mock_returns = self.response def test_get_absolute_rui(self): uri = '/a/relative/url' self.assertEquals(self.api._get_absolute_uri(uri), self.url + uri) def test_internal_get_call(self): # setup uri = '/login' self.response.content = open( 'tests/data/login_challenge_response.xml').read() # test self.api._get(uri) # validate self.assertTrue( self.tt.check("Called " + "self.api.session.get('http://video.example.com/login', params={})")) def test_internal_post_call(self): # setup uri = '/login' self.response.content = open( 'tests/data/login_challenge_response.xml').read() # test self.api._post(uri) # validate self.assertTrue( self.tt.check("Called " + "self.api.session.post('http://video.example.com/login', data={})")) def test_login_get_challenge(self): # setup self.api.username = self.username self.response.content = open( 'tests/data/login_challenge_response.xml').read() # test challenge = self.api._login_challenge() # validate self.assertEquals(challenge, "92dc06bbb703f14354fdfbede9b62ff9") def test_login_get_failed_challenge(self): # setup self.api.username = self.username self.response.content = open( 'tests/data/login_challenge_invalid_account_response.xml').read() # validate self.assertRaises(ApiException, self.api._login_challenge) def test_login_send_challenge_response(self): # setup self.api.username = self.username self.api.secret = self.secret self.response.content = open( 'tests/data/login_challenge_response_response.xml').read() # test success = self.api._login_response("92dc06bbb703f14354fdfbede9b62ff9") # validate self.assertEquals(success, True) def test_login_send_challenge_failed_response(self): # setup self.api.username = self.username self.api.secret = self.secret self.response.content = open( 'tests/data/login_invalid_challenge_response_response.xml').read() # validate self.assertRaises(ApiException, self.api._login_response, ("92dc06bbb703f14354fdfbede9b62ff9")) def test_successful_authentication(self): # setup mock('self.api._login_challenge', returns='xxx', tracker=self.tt) mock('self.api._login_response', returns=True, tracker=self.tt) # test success = self.api.authenticate(self.username, self.secret) # validate self.assertEquals(success, True) def test_failed_authentication(self): # setup mock('self.api._login_challenge', returns='xxx', tracker=self.tt) mock('self.api._login_response', returns=False, tracker=self.tt) # test success = self.api.authenticate(self.username, self.secret) # validate self.assertEquals(success, False)
class TestObswatch(unittest.TestCase): # nose knows about setUpClass, but python 2.6's unittest doesn't # @classmethod # def setUpClass(cls): def setUp(self): repo = Mock('repo') repo.name = 'standard' repo.arch = 'x86_64' package = Mock('package') package.project = 'openSUSE:11.3' package.name = 'osc' self.build = obswatch.Build(package=package, repo=repo, interested={'geeko':'*****@*****.**'}) self.package = package self.tt = TraceTracker() obswatch.SLEEP_TIME = 0 def tearDown(self): minimock.restore() self.tt.clear() def test_get_latest_packages(self): mock('obswatch.http_GET', tracker=self.tt, returns=StringIO('''<?xml version="1.0" encoding="UTF-8"?> <latest_added> <package created="2010-09-09T14:03:06+02:00" name="antivir" project="home:varkoly:branches:openSUSE:11.3:NonFree"/> <project created="2010-09-09T14:03:05+02:00" name="home:varkoly:branches:openSUSE:11.3:NonFree"/> <package created="2010-09-09T13:50:37+02:00" name="test9" project="home:enzokiel:test"/> <package created="2010-09-09T13:12:54+02:00" name="kernel-bfs-source" project="home:jingtw"/> <package created="2010-09-09T13:12:08+02:00" name="getdata" project="home:christiantrippe:branches:KDE:Distro:Factory"/> <package created="2010-09-09T13:05:13+02:00" name="perl-String-CRC32" project="home:seife:byd"/> <package created="2010-09-09T13:05:04+02:00" name="autogen" project="home:psmt:branches:Base:System"/> </latest_added>''')) result = obswatch.get_latest_packages(7) assert_same_trace(self.tt,"""Called obswatch.http_GET( '%sstatistics/latest_updated?limit=7')""" % obswatch.APIURL) for p in result: self.assertTrue(isinstance(p, obswatch.Package)) self.assertEqual(result[0].name, 'antivir') self.assertEqual(len(result), 6) # second one is a project def test_get_user_email(self): mock('obswatch.http_GET', tracker=self.tt, returns=StringIO('''<person> <login>Geeko</login> <email>[email protected]</email> <realname>Geeko Chameleon</realname> <watchlist/> </person>''')) result = obswatch.get_user_email('Geeko') assert_same_trace(self.tt, """Called obswatch.http_GET( '%sperson/Geeko')""" % obswatch.APIURL) self.assertEqual(result, '*****@*****.**') def test_users_from_url(self): mock('obswatch.http_GET', tracker=self.tt, returns=StringIO('''<?xml version="1.0" encoding="UTF-8"?> <project name="superkde" created="2005-01-01T00:00:02+01:00" updated="2007-01-19T10:44:45+01:00"> <title>SuperKDE</title> <description>SuperKDE is a heavily tuned version of KDE.</description> <link project="openSUSE:11.2:Update" /> <link project="openSUSE:11.2" /> <person role="maintainer" userid="Geeko"/> <person role="maintainer" userid="BrownGeeko"/> <group role="reviewer" groupid="release_team"/> <build> <disable /> </build> <repository name="kde4:factory" rebuild="transitive"> <path project="kde4" repository="factory"/> <arch>i386</arch> <arch>x86_64</arch> </repository> </project>''')) mock('obswatch.get_user_email', returns='*****@*****.**') result = obswatch.get_users_from_url('%ssource/superkde/_meta' % obswatch.APIURL) assert_same_trace(self.tt, """Called obswatch.http_GET( '%ssource/superkde/_meta')""" % obswatch.APIURL) self.assertEqual(len(result), 2) self.assertEqual(result['Geeko'], '*****@*****.**') self.assertEqual(result['BrownGeeko'], '*****@*****.**') def test_get_builds(self): mock('osc.core.http_GET', tracker=self.tt, returns=StringIO('''<?xml version="1.0" encoding="UTF-8"?> <project name="superkde" created="2005-01-01T00:00:02+01:00" updated="2007-01-19T10:44:45+01:00"> <title>SuperKDE</title> <description>SuperKDE is a heavily tuned version of KDE.</description> <link project="openSUSE:11.2:Update" /> <link project="openSUSE:11.2" /> <person role="maintainer" userid="ernie"/> <group role="reviewer" groupid="release_team"/> <build> <disable /> </build> <useforbuild> <disable /> </useforbuild> <repository name="kde4:factory" rebuild="transitive"> <path project="kde4" repository="factory"/> <arch>i386</arch> <arch>x86_64</arch> </repository> <repository name="suselinux-9.3"> <path project="suselinux-9.3" repository="standard"/> <arch>i386</arch> </repository> <repository name="gnomespecial" rebuild="local"> <path project="gnome3" repository="suselinux-9.3"/> <path project="suselinux-9.3" repository="standard"/> <arch>i386</arch> </repository> </project>''')) # source/superkde/_meta # gets called by osc.core.get_repos_of_project mock('obswatch.get_interested', returns={'Geeko': '*****@*****.**'}) superkde = Mock('package') superkde.name = 'superkde' superkde.project = 'superkde' superkde.created = '2007-01-19T10:44:45+01:00' result = obswatch.get_builds(superkde) assert_same_trace(self.tt, """Called osc.core.http_GET( '%ssource/superkde/_meta')""" % obswatch.APIURL) def test_build_get_remote_status(self): mock('obswatch.http_GET', tracker=self.tt, returns=StringIO('''<status package="osc" code="disabled"> <details></details> </status>''')) code = self.build.get_remote_status() assert_same_trace(self.tt, """Called obswatch.http_GET( '%sbuild/openSUSE:11.3/standard/x86_64/osc/_status')""" % obswatch.APIURL) self.assertEqual(code, 'disabled') def test_process_same_status(self): self.build.get_remote_status = lambda : self.build.status result = obswatch.process_build(self.build) self.assertTrue(result) def test_process_intermediate(self): self.build.get_remote_status = lambda : 'building' result = obswatch.process_build(self.build) self.assertTrue(result) self.assertEqual(self.build.status, 'building') def test_process_other(self): self.build.get_remote_status = lambda : 'excluded' result = obswatch.process_build(self.build) self.assertFalse(result) def test_process_unknown(self): self.build.get_remote_status = lambda : 'infundibulated' self.assertRaises(Exception, obswatch.process_build, self.build) def test_process_final_not_succeeded(self): self.build.get_remote_status = lambda : 'failed' result = obswatch.process_build(self.build) self.assertFalse(result) def test_final_succeeded(self): self.build.get_remote_status = lambda : 'succeeded' mock('obswatch.Build.get_binaries', returns={'foo':'bar'}) mock('obswatch.send_email', tracker=self.tt) result = obswatch.process_build(self.build) self.assertFalse(result) expected_output = """Called obswatch.send_email( 'geeko', '*****@*****.**', <obswatch.Build instance at ...>, {'foo': 'bar'})""" assert_same_trace(self.tt, expected_output) def test_interested(self): mock('obswatch.get_users_from_url', returns_func=lambda url: {url: url}) result = obswatch.get_interested(self.package) # both the project and package page should be checked for users self.assertEqual(result, {'https://api.opensuse.org/source/openSUSE:11.3/_meta': 'https://api.opensuse.org/source/openSUSE:11.3/_meta', 'https://api.opensuse.org/source/openSUSE:11.3/osc/_meta': 'https://api.opensuse.org/source/openSUSE:11.3/osc/_meta'}) def test_send_email(self): mock('smtplib.SMTP', returns=Mock('smtp_connection', tracker=self.tt), tracker=self.tt) obswatch.send_email('geeko', '*****@*****.**', 'yourpackage', {'rpm1': 'http://opensuse.org/rpm1', 'rpm2': 'http://opensuse.org/rpm2'}) expected_output = """Called smtplib.SMTP('localhost') Called smtp_connection.sendmail( '*****@*****.**', ['*****@*****.**'], 'To: [email protected]\\nFrom: [email protected]\\nSubject: (osc) build succeeded: yourpackage\\n\\nThe package yourpackage has finished building and can now be downloaded from:\\nrpm1 - http://opensuse.org/rpm1\\nrpm2 - http://opensuse.org/rpm2') Called smtp_connection.quit() """ assert_same_trace(self.tt, expected_output)