Exemple #1
0
 def test_json_not_empty(self):
     """ Test case for ByteSequence.json_decode() method. """
     encoder = ObjectJsonEncoder()
     notempty_test_path = os.path.join(THIS_DIR, 'notempty')
     byte_seq = ByteSequence.from_file(notempty_test_path)
     json_string = encoder.default(byte_seq)
     test_byte_seq = ByteSequence.json_decode(json_string)
     self.assertNotEqual(
         test_byte_seq, self.def_inst,
         'Test from JSON should be equal to default instance')
Exemple #2
0
 def test_from_file(self):
     """ Test case for ByteSequence.from_file() method. """
     notempty_test_path = os.path.join(THIS_DIR, 'notempty')
     test_byte_seq = ByteSequence.from_file(notempty_test_path)
     self.assertNotEqual(
         test_byte_seq, self.def_inst,
         'Test from file should NOT be equal to default instance')
Exemple #3
0
 def test_json_empty(self):
     """ Test case for ByteSequence.json_decode() method. """
     encoder = ObjectJsonEncoder()
     json_string = encoder.default(self.def_inst)
     test_byte_seq = ByteSequence.json_decode(json_string)
     self.assertEqual(test_byte_seq, self.def_inst,
                      'Test from JSON should be equal to default instance')
Exemple #4
0
def test_add_bytesequence(session):  # pylint: disable-msg=W0621, W0613
    """ Set up default instance """
    corp_file_count = file_count(TEST_BYTES_ROOT)
    file_system_source = Source("BS Test", TEST_DESCRIPTION, SCHEMES['FILE'],
                                TEST_BYTES_ROOT)
    file_system_index = SourceIndex(file_system_source)
    file_system_index.put()
    file_system = FileSystem(file_system_source)
    for key in file_system.all_file_keys():
        assert key.size != 0
        assert not key.metadata['SHA1']
        _aug_key = file_system.get_file_metadata(key)
        assert _aug_key.metadata['SHA1'] != ByteSequence.EMPTY_SHA1
        _bytes = ByteSequence(_aug_key.metadata['SHA1'], int(key.size))
        _bytes.put()
    _byte_count = len(ByteSequence.all())
    assert _byte_count == corp_file_count
 def test_get_item(self):
     """ Test that blob retrieval from store works as expected. """
     self.populate_and_assert_blobstore()
     byte_sequence = self.blobstore.get_blob(ByteSequence.EMPTY_SHA1)
     assert byte_sequence == ByteSequence.default_instance(), \
     'Retrieved ByteSequence should equal default empty sequence'
     byte_sequence = self.blobstore.get_blob(NOT_EMPTY_SHA1)
     assert byte_sequence.sha1 == NOT_EMPTY_SHA1, \
     'Retrieved ByteSequence should equal notempty sequence'
 def test_add_item(self):
     """ Test for empty store properties adding item works properly. """
     self.blobstore.clear()
     assert self.blobstore.blob_count == 0, \
     'Reset BlobStore should have blob count 0'
     self.store_file('empty')
     byte_seq = ByteSequence.default_instance()
     assert self.blobstore.blob_count == 1, \
     'BlobStore should contain a single item'
     assert byte_seq.size == 0, \
     'Returned ByteSequence should have size 0'
     assert byte_seq.sha1 == ByteSequence.EMPTY_SHA1, \
     'Returned ByteSequence should have null stream SHA1 value'
Exemple #7
0
 def test_from_string(self):
     """ Test case for ByteSequence.from_string() method. """
     test_byte_seq = ByteSequence.from_string('notempty')
     self.assertNotEqual(
         test_byte_seq, self.def_inst,
         'Test from file should NOT be equal to default instance')
Exemple #8
0
 def test_from_file_no_file(self):
     """ Test case for ByteSequence.from_file() method with nonexistent file. """
     notempty_test_path = os.path.join(THIS_DIR, 'notexist')
     with self.assertRaises(IOError) as _:
         ByteSequence.from_file(notempty_test_path)
Exemple #9
0
 def setUp(self):
     """ Set up default instance """
     self.default_test = ByteSequence(ByteSequence.EMPTY_SHA1, 0)
     self.def_inst = ByteSequence.default_instance()