def test_export_documents(self): try: shutil.rmtree('/tmp/test_repo3') shutil.rmtree('/tmp/exported_documents') except OSError as error: pass for test_file in ['part1.pdf', 'part2.pdf', 'data.doc']: file_to_path = reduce(os.path.join, [SAMPLE_DIR_PATH, 'importable', test_file]) file_from_path = reduce(os.path.join, [ SAMPLE_DIR_PATH, 'importable', 'export_files_for_test', test_file ]) if not os.path.exists(file_to_path): copy2(file_from_path, file_to_path) repository = Repository('Empty', '/tmp/test_repo3') alice = User('Alice', 'Smith', date(1980, 10, 10), '*****@*****.**', '****') bob = User('Bob', 'Marker', date(1970, 11, 11), '*****@*****.**', '****') alice_id = repository._user_manager.add_user(alice) bob_id = repository._user_manager.add_user(bob) first_document = Document( 'Some important doc', 'Contains various documentations', alice_id, [ SAMPLE_DIR_PATH + '/importable/part1.pdf', SAMPLE_DIR_PATH + '/importable/part2.pdf' ], 'pdf') first_document.make_public() first_document.change_state('pending') first_document.change_state('accepted') second_document = Document('Data report', 'Figures and graphs mainly', bob_id, [SAMPLE_DIR_PATH + '/importable/data.doc'], 'doc') second_document.make_public() second_document.change_state('pending') second_document.change_state('accepted') first_id = repository._document_manager.add_document(first_document) second_id = repository._document_manager.add_document(second_document) repository.export_documents([first_id, second_id], '/tmp/exported_documents') self.assertTrue(os.path.exists('/tmp/exported_documents/part1.pdf')) self.assertTrue(os.path.exists('/tmp/exported_documents/part2.pdf')) self.assertTrue(os.path.exists('/tmp/exported_documents/data.doc')) self.assertTrue(os.path.exists('/tmp/exported_documents/1.edd')) self.assertTrue(os.path.exists('/tmp/exported_documents/2.edd')) with open('/tmp/exported_documents/1.edd') as edd_file: lines = edd_file.readlines() self.assertIn('[document]\n', lines) self.assertIn('title=Some important doc\n', lines) self.assertIn('description=Contains various documentations\n', lines) self.assertIn('author=Alice Smith\n', lines) self.assertIn("files=['part1.pdf', 'part2.pdf']\n", lines) self.assertIn('doc_format=pdf\n', lines) with open('/tmp/exported_documents/2.edd') as edd_file: lines = edd_file.readlines() self.assertIn('[document]\n', lines) self.assertIn('title=Data report\n', lines) self.assertIn('description=Figures and graphs mainly\n', lines) self.assertIn('author=Bob Marker\n', lines) self.assertIn("files=['data.doc']\n", lines) self.assertIn('doc_format=doc\n', lines) shutil.rmtree('/tmp/exported_documents') shutil.rmtree('/tmp/test_repo3')
def test_invalid_reject(self): document = Document('title1', 'desc1', 1, ['1.pdf', '2.pdf'], 'pdf') with self.assertRaises(ValueError): document.change_state('rejected')
def test_invalid_new_state(self): document = Document('title1', 'desc1', 1, ['1.pdf', '2.pdf'], 'pdf') document.change_state('pending') with self.assertRaises(ValueError): document.change_state('new')
def test_reject_document(self): document = Document('title1', 'desc1', 1, ['1.pdf', '2.pdf'], 'pdf') document.change_state('pending') document.change_state('rejected') self.assertEqual(document.state, 'rejected')