def test_logs_deserialization_errors(self):
     loader = SchemaLoader(supervisor_schema)
     copy_row = copy.copy(self.sample_row)
     copy_row['super_email'] = 'not a valid email'
     loader.slice_and_add(copy_row)
     with self.assertLogs( current_app.logger, level='ERROR' ) as cm:
         loader.save_models_or_report_errors()
 def test_slicing_data(self):
     loader = SchemaLoader(supervisor_schema)
     copy_row = copy.copy(self.sample_row)
     # add a row
     index = loader.slice_and_add( self.sample_row )
     self.assertEqual(index, 0)
     self.assertNotIn('permit_number', loader.raw_data[0])
     # editing unused fields shouldn't matter
     copy_row['inspector_id'] = 'LAKSJDHFL'
     index = loader.slice_and_add( copy_row )
     self.assertEqual(index, 0)
 def test_adding_rows(self):
     # can be created with no schema
     loader = SchemaLoader(None)
     # add a row
     index = loader.add( self.sample_row )
     self.assertEqual(index, 0)
     # add another row
     index = loader.add( self.random_rows[0] )
     self.assertEqual(index, 1)
     self.assertEqual( len(loader.raw_data), 2 )
     # adding the same row returns the same index
     index = loader.add( self.sample_row )
     self.assertEqual(index, 0)
Exemplo n.º 4
0
class TestSchemaLoader(TestCase):

    def setUp(self):
        self.datum = { "a": 1, "b": 2, "c": 3, "d": 4 }
        self.datum2 = { "a": 1, "b": 2  }
        self.data = [self.datum, self.datum2]
        self.loader = SchemaLoader(FakeModelSchema())

    def test_slice(self):
        sliced = self.loader._slice(self.datum)
        self.assertSetEqual(set(['a','b','c']), set(sliced.keys()))

    def test_slice_and_add_data(self):
        self.assertEquals(self.loader.slice_and_add(self.datum), 0)
        self.assertEquals(self.loader.slice_and_add(self.datum2), 1)
        self.assertEquals(self.loader.slice_and_add(self.datum), 0)

    def test_slice_and_add_empty(self):
        self.assertEquals(self.loader.slice_and_add({}), 0)

    def test_slice_and_add_multiple(self):
        for ix, d in enumerate(self.data):
            self.assertEqual(self.loader.slice_and_add(d), ix)
 def test_logs_successful_deserialization(self):
     loader = SchemaLoader(supervisor_schema)
     loader.slice_and_add(self.sample_row)
     with self.assertLogs( current_app.logger, level='INFO' ) as cm:
         loader.save_models_or_report_errors()
Exemplo n.º 6
0
 def setUp(self):
     self.datum = { "a": 1, "b": 2, "c": 3, "d": 4 }
     self.datum2 = { "a": 1, "b": 2  }
     self.data = [self.datum, self.datum2]
     self.loader = SchemaLoader(FakeModelSchema())