import unittest

from datetime import datetime

from changeset import Changeset
from bug import Bug
from flypaper import FlyPaper


class TestFlyPaper(unittest.TestCase):
    def setUp(self):
        self.fp = FlyPaper(None, None, datetime(2011, 1, 1, 0, 0, 0), False)

    def test_matching_bugs_with_changesets(self):
        #create two bugs
        bug1id = 'bug1'
        bug1 = Bug(bug1id)
        self.fp._buglist.add(bug1)

        bug2id = 'bug2'
        bug2 = Bug(bug2id)
        self.fp._buglist.add(bug2)

        #only one bug is part of a changeset
        chg1 = Changeset('abc', datetime(2012, 1, 5, 8, 22, 0), bug1id)
        self.fp._changesets.add(chg1)

        self.fp._match_bugs_with_changesets()

        #verify that only that one bug is linked with a changeset
        self.assertEquals(set([chg1]), bug1.fixing_changesets)
        self.assertEquals(0, len(bug2.fixing_changesets))
        self.assertEquals(set([bug1]), chg1.bugs_fixed)

@@ -271,77 +271,44 @@
     
-def test_matching_bugs_with_changesets(self):%0A        #create two bug
+    #create a few bugs and changeset
 s%0A  
@@ -333,24 +333,29 @@
 g1'%0A        
+self.
 bug1 = Bug(b
@@ -390,16 +390,21 @@
 ist.add(
+self.
 bug1)%0A%0A 
@@ -430,24 +430,29 @@
 g2'%0A        
+self.
 bug2 = Bug(b
@@ -487,16 +487,21 @@
 ist.add(
+self.
 bug2)%0A%0A 
@@ -552,16 +552,21 @@
         
+self.
 chg1 = C
@@ -657,15 +657,70 @@
 add(
+self.
 chg1)%0A%0A
+    def test_matching_bugs_with_changesets(self):%0A
     
@@ -863,16 +863,21 @@
 et(%5B
+self.
 chg1%5D), 
 bug1
@@ -872,16 +872,21 @@
 chg1%5D), 
+self.
 bug1.fix
@@ -934,16 +934,21 @@
 (0, len(
+self.
 bug2.fix
@@ -999,16 +999,21 @@
 et(%5B
+self.
 bug1%5D), 
 chg1
@@ -1008,16 +1008,21 @@
 bug1%5D), 
+self.
 chg1.bug
@@ -1030,8 +1030,323 @@
 _fixed)%0A
+%0A    def test_building_buggy_file_list(self):%0A        self.chg1.add_modified_file('file1')%0A        self.chg1.bugs_fixed.add(self.bug1)%0A        self.fp._build_buggy_file_list()%0A        self.assertEquals(1, len(self.fp._buggy_file_list._filenames))%0A        self.assertIn('file1', self.fp._buggy_file_list._filenames)%0A

add test around building list of buggy files