def test_nominal_case(self): file_statuses = [ FileStatus("/foo/bar/qux", "drwx------", 0, "simon.dolle", "staff", 0, datetime.date(2016, 4, 21), "bar"), FileStatus("/foo/qux", "-rwxrwxr-x", 0, "simon", "root", 0, datetime.date(2016, 9, 12), "qux") ] expected_result = ( "drwx------ - simon.dolle staff 0 2016-00-21 00:00 /foo/bar/qux\n" "-rwxrwxr-x - simon root 0 2016-00-12 00:00 /foo/qux " ) self.assertEqual(expected_result, get_file_statuses_pretty_print(file_statuses))
def test_nominal_case(self): hls_lister_mock = mock.MagicMock() hls_lister_mock.list_status.return_value = (0, [ FileStatus("/Users/simon/Documents", "drwx------+", 8, "simon", "staff", 272, datetime.date(2015, 11, 20), "Documents"), FileStatus("/Users/simon/Dropbox", "drwx------+", 8, "simon", "staff", 272, datetime.date(2015, 11, 20), "Dropbox"), FileStatus("/Users/simon/Music", "drwx------+", 8, "simon", "staff", 272, datetime.date(2015, 11, 20), "Music"), ]) completer = SimpleCompleter(hls_lister_mock) actual_result = completer.get_completions("/Users/simon/D") expected_result = ["/Users/simon/Documents/", "/Users/simon/Dropbox/"] self.assertEquals(expected_result, actual_result)
def test_parse(self): parser = LsParser() lines = ( "foo bar\n" "drwx------+ 8 simon staff 272 27 dec 2015 /Users/simon/Music\n" "drwx------+ 8 simon staff 272 17 nov 2014 /Users/simon/Documents\n" ) expected_result = [ FileStatus("/Users/simon/Music", "drwx------+", 8, "simon", "staff", 272, datetime.date(2015, 12, 27)), FileStatus("/Users/simon/Documents", "drwx------+", 8, "simon", "staff", 272, datetime.date(2014, 11, 17)) ] self.assertEqual(expected_result, parser.parse(lines))
def test_str(self): fileStatus = FileStatus("/Users/simon/Music", "drwx------+", 8, "simon", "staff", 272, datetime.datetime(2015, 12, 27, 12, 10)) self.assertEquals( "drwx------+ - simon staff 272 2015-10-27 12:10 /Users/simon/Music", str(fileStatus))
def test_french_month(self): parser = LsParser() line = "drwx------+ 8 simon staff 272 27 jui 2015 /Users/simon/Personal Documents" self.assertEquals( FileStatus("/Users/simon/Personal Documents", "drwx------+", 8, "simon", "staff", 272, datetime.date(2015, 6, 27)), parser.parse_line(line))
def test_space_in_name(self): parser = LsParser() line = "drwx------+ 8 simon staff 272 27 dec 2015 /Users/simon/Personal Documents" self.assertEquals( FileStatus("/Users/simon/Personal Documents", "drwx------+", 8, "simon", "staff", 272, datetime.date(2015, 12, 27)), parser.parse_line(line))
def test_file_case(self): parser = LsParser() line = "-rwx------+ 8 simon staff 272 27 dec 2015 /Users/simon/Music" self.assertEquals( FileStatus("/Users/simon/Music", "-rwx------+", 8, "simon", "staff", 272, datetime.date(2015, 12, 27)), parser.parse_line(line))
def test_parse(self): input = '''{"FileStatuses": {"FileStatus": [ {"pathSuffix": "bar", "type": "DIRECTORY", "length": 0, "owner": "simon", "group": "staff", "permission": "700", "accessTime": 0, "modificationTime": 1461236412807, "blockSize": 0, "replication": 0}, {"pathSuffix": "qux", "type": "FILE", "length": 0, "owner": "simon", "group": "staff", "permission": "775", "accessTime": 0, "modificationTime": 1473691319065, "blockSize": 0, "replication": 0}]}}''' parser = WebHdfsParser("/foo") expected_result = [ FileStatus("/foo/bar", "drwx------", 0, "simon", "staff", 0, datetime.datetime(2016, 4, 21, 11, 0), "bar"), FileStatus("/foo/qux", "-rwxrwxr-x", 0, "simon", "staff", 0, datetime.datetime(2016, 9, 12, 14, 41), "qux") ] self.assertEqual(expected_result, parser.parse(input))
def test_current_year(self): parser = LsParser() line = "drwx------+ 8 simon staff 272 27 jui 12:15 /Users/simon/Personal Documents" self.assertEquals( FileStatus("/Users/simon/Personal Documents", "drwx------+", 8, "simon", "staff", 272, datetime.date(datetime.datetime.now().year, 6, 27)), parser.parse_line(line))
def test_root_only(self): hls_lister_mock = mock.MagicMock() hls_lister_mock.list_status.return_value = (0, [ FileStatus("/Users", "drwx------+", 8, "simon", "staff", 272, datetime.date(2015, 11, 20)) ]) completer = SimpleCompleter(hls_lister_mock) actual_result = completer.get_completions("/") expected_result = ["/Users/"] self.assertEquals(expected_result, actual_result)
def test_nominal_case(self, popen_mock): process_mock = mock.MagicMock() process_mock.communicate.return_value = self.status_list, None process_mock.returncode = 0 popen_mock.return_value = process_mock lister = WebHdfsLister("server", "*****@*****.**") self.assertEqual((0, [ FileStatus("/foo/bar", "drwx------", 0, "simon", "staff", 0, datetime.datetime(2016, 4, 21, 11, 0), "bar"), FileStatus("/foo/qux", "-rwxrwxr-x", 0, "simon", "staff", 0, datetime.datetime(2016, 9, 12, 14, 41), "qux") ]), lister.list_status("/foo")) devnull = open(os.devnull, "w") popen_mock.assert_called_once_with([ 'curl', '--negotiate', '-L', '-u:[email protected]', 'server/foo?op=LISTSTATUS' ], stdout=mock.ANY, stderr=mock.ANY)
def test_nominal_case(self, popen_mock): process_mock = mock.MagicMock() process_mock.communicate.return_value = "drwx------+ 8 simon staff 272 27 dec 2015 /Users/simon/Music", None process_mock.returncode = 0 popen_mock.return_value = process_mock lister = HlsHdfs() self.assertEqual((0, [ FileStatus("/Users/simon/Music", "drwx------+", 8, "simon", "staff", 272, datetime.date(2015, 12, 27)) ]), lister.hls("/Users/simon/")) popen_mock.assert_called_once_with( ['hdfs', 'dfs', '-ls', '/Users/simon/'], stdout=subprocess.PIPE)