Ejemplo n.º 1
0
 def test_write_exists(self):
   f = feed.Feed()
   data = [entities.Agency(**self.agency_expect)]
   outfile = test_outfile()
   f.write(outfile, data, sortkey='agency_id')
   with self.assertRaises(IOError):
     f.write(outfile, data, sortkey='agency_id')
   os.unlink(outfile)
Ejemplo n.º 2
0
class TestUtil(unittest.TestCase):
    testdata = [
        entities.Agency(agency_name='Foo', agency_id='1'),
        entities.Agency(agency_name='Bar', agency_id='2'),
        entities.Agency(agency_name='Baz', agency_id='2'),
    ]

    def test_filtany_name(self):
        data = util.filtany(self.testdata, name='Foo')
        assert len(data) == 1
        data = util.filtany(self.testdata, name='Bar')
        assert len(data) == 1
        data = util.filtany(self.testdata, name='Baz')
        assert len(data) == 1

    def test_filtany_id(self):
        data = util.filtany(self.testdata, id='1')
        assert len(data) == 1
        data = util.filtany(self.testdata, id='2')
        assert len(data) == 2

    def test_filtfirst_name(self):
        data = util.filtfirst(self.testdata, name='Foo')
        assert data.name() == 'Foo'

    def test_filtfirst_id(self):
        data = util.filtfirst(self.testdata, id='1')
        assert data.id() == '1'

    def test_filtfirst_empty(self):
        with self.assertRaises(ValueError):
            util.filtfirst(self.testdata, name='Asdf')
        with self.assertRaises(ValueError):
            util.filtfirst(self.testdata, id='0')

    def test_example_feed(self):
        expect = util.example_feed()
        assert os.path.exists(expect)
Ejemplo n.º 3
0
 def test_write(self):
   f = feed.Feed()
   data = [entities.Agency(**self.agency_expect)]
   outfile = test_outfile()
   f.write(outfile, data, sortkey='agency_id')
   # Check the output...
   with open(outfile) as csvfile:
     reader = csv.reader(csvfile)
     headers = reader.next()
     assert len(self.agency_expect.keys()) == len(headers)
     for i in headers:
       assert i in self.agency_expect
     rows = []
     for i in reader:
       rows.append(i)
     assert len(rows) == 1
     row = rows[0]
     for k,v in zip(headers, row):
       assert self.agency_expect[k] == v
   # Delete temp file
   os.unlink(outfile)
Ejemplo n.º 4
0
 def test_id(self):
     agency = entities.Agency(**self.expect)
     assert agency.id() == self.expect['agency_id']
Ejemplo n.º 5
0
 def test_name(self):
     agency = entities.Agency(**self.expect)
     assert agency.name() == self.expect['agency_name']