Exemple #1
0
    def test_push_append_mode(self):
        asyncio.run(self.csv_outlet._push(self.records, self.update))

        self.assertTrue(os.path.exists(self.attempt_filepath),
                        'File should exist')

        with open(self.attempt_filepath, 'r') as f:
            self.assertEqual(f.read(), self.target)

        os.remove(self.attempt_filepath)
Exemple #2
0
    def test_push_write_mode(self):

        for record in self.records:
            record.metadata = {CsvOutlet.FILE_MODE: 'w'}

        asyncio.run(self.csv_outlet._push(self.records, self.update))

        self.assertTrue(os.path.exists(self.attempt_filepath),
                        'File should exist')

        with open(self.attempt_filepath, 'r') as f:
            self.assertEqual(
                f.read(), 'foo,baz\nbar,qux\n',
                'Each write should have overridden the previous.')

        os.remove(self.attempt_filepath)
Exemple #3
0
    def test_push_custom_files(self):
        self.records[0].metadata = {CsvOutlet.CSV_FILE: self.custom_filepath}

        asyncio.run(self.csv_outlet._push(self.records, self.update))

        self.assertTrue(os.path.exists(self.attempt_filepath),
                        'File should exist')
        self.assertTrue(os.path.exists(self.custom_filepath),
                        'File should exist')

        with open(self.attempt_filepath, 'r') as f:
            self.assertEqual(f.read(), 'foo,baz\nbar,qux\nbar,qux\nbar,qux\n',
                             'Should miss one record')

        with open(self.custom_filepath, 'r') as f:
            self.assertEqual(f.read(), 'foo,baz\nbar,qux\n',
                             'Should contain the one record')

        os.remove(self.attempt_filepath)
        os.remove(self.custom_filepath)
Exemple #4
0
    def test_push_custom_files(self):
        self.records[0].metadata = {FileOutlet.FILEPATH: self.custom_filepath}

        asyncio.run(self.file_outlet._push(self.records, self.update))

        self.assertTrue(os.path.exists(self.attempt_filepath),
                        'File should exist')
        self.assertTrue(os.path.exists(self.custom_filepath),
                        'File should exist')

        with open(self.attempt_filepath, 'r') as f:
            self.assertEqual(f.read(), 'test\ntest\ntest\n',
                             'Should miss one record')

        with open(self.custom_filepath, 'r') as f:
            self.assertEqual(f.read(), 'test\n',
                             'Should contain the one record')

        os.remove(self.attempt_filepath)
        os.remove(self.custom_filepath)
Exemple #5
0
    def test_push_skip_update(self, stdout):
        self.print_outlet.skip_update = True

        asyncio.run(self.print_outlet._push([self.record], self.update))

        self.assertEqual(stdout.getvalue(), 'TestRecord(test)\n')
Exemple #6
0
    def test_push_only_payload(self, stdout):
        self.print_outlet.only_payload = True

        asyncio.run(self.print_outlet._push([self.record], self.update))

        self.assertEqual(stdout.getvalue(), 'TestUpdate() test\n')