Example #1
0
 def test_body(self):
     loader.set_instance(mock_loader.SettableLoader(body_responses={
         'peer/first_dataset': 'dataframe standin'
     }))
     ds = dataset.Dataset(GET_OBJ)
     self.assertIsNone(ds.body_component)
     ds.body
     self.assertEqual(ds.body_component, 'dataframe standin')
Example #2
0
 def test_dont_populate_twice(self):
     loader.set_instance(mock_loader.NullLoader())
     ds = dataset.Dataset(GET_OBJ)
     self.assertTrue(ds._is_populated)
     self.assertTrue(hasattr(ds, 'meta_component'))
     # Ensure that `get` is not called when accessing `meta`, which would
     # cause the NullLoader to raise an error.
     ds.meta
Example #3
0
 def test_init_from_list(self):
     # Ensure loader is never used
     loader.set_instance(mock_loader.NullLoader())
     ds = dataset.Dataset(LIST_OBJ)
     self.assertEqual(ds.username, 'peer')
     self.assertEqual(ds.name, 'first_dataset')
     self.assertEqual(ds.profile_id, 'QmProfileID')
     self.assertEqual(ds.path, '/ipfs/QmPath')
     self.assertFalse(ds._is_populated)
Example #4
0
 def test_populate(self):
     loader.set_instance(mock_loader.SettableLoader(get_responses={
         'peer/first_dataset': GET_OBJ
     }))
     ds = dataset.Dataset(LIST_OBJ)
     self.assertFalse(ds._is_populated)
     self.assertFalse(hasattr(ds, 'meta_component'))
     ds.meta
     self.assertTrue(ds._is_populated)
     self.assertTrue(hasattr(ds, 'meta_component'))
     self.assertEqual(ds.meta.description, 'meta.description')
Example #5
0
    def test_init_from_get(self):
        # Ensure loader is never used
        loader.set_instance(mock_loader.NullLoader())
        ds = dataset.Dataset(GET_OBJ)
        self.assertEqual(ds.username, 'peer')
        self.assertEqual(ds.name, 'first_dataset')
        self.assertEqual(ds.path, '/ipfs/QmPath')

        self.assertEqual(ds.body_path_value, "/ipfs/QmBodyPath")
        self.assertEqual(ds.previous_path_value, "/ipfs/QmPreviousPath")

        # Checking a subset of the possible fields for brevity
        self.assertIsInstance(ds.commit_component, dataset.Commit)
        self.assertEqual(ds.commit_component.author, {"id": "QmCommitAuthorId"})
        self.assertEqual(ds.commit_component.message, "commit.message")
        self.assertEqual(ds.commit_component.timestamp,
                         "2020-01-02T03:04:05.124963898Z")

        self.assertIsInstance(ds.meta_component, dataset.Meta)
        self.assertEqual(ds.meta_component.description, 'meta.description')
        self.assertEqual(ds.meta_component.keywords,
                         ['meta.keyword1', 'meta.keyword2'])

        self.assertIsInstance(ds.readme_component, dataset.Readme)
        self.assertEqual(ds.readme_component.script.strip(), "TEST README")

        self.assertIsInstance(ds.structure_component, dataset.Structure)
        self.assertEqual(ds.structure_component.entries, 3)
        self.assertEqual(ds.structure_component.format, 'csv')
        self.assertEqual(ds.structure_component.schema, {
            "items": {
                "items": [
                    {"title": "field1", "type": "string"},
                    {"title": "field2", "type": "integer"},
                ],
                "type": "array"
            },
            "type": "array"
        })

        self.assertIsNone(ds.body_component)
        self.assertTrue(ds._is_populated)
Example #6
0
 def setUp(self):
     loader.set_instance(mock_loader.MockLoader())