Repository: nylas/nylas-python

Issue:
Fix all xfail tests

Discussion:

Patch:
diff --git a/nylas/client/restful_models.py b/nylas/client/restful_models.py
index 93488a0..e73c100 100644
--- a/nylas/client/restful_models.py
+++ b/nylas/client/restful_models.py
@@ -179,11 +179,11 @@ class Folder(NylasAPIObject):
 
     @property
     def threads(self):
-        return self.child_collection({'in': self.id})
+        return self.child_collection(Thread, folder_id=self.id)
 
     @property
     def messages(self):
-        return self.child_collection({'in': self.id})
+        return self.child_collection(Message, folder_id=self.id)
 
 
 class Label(NylasAPIObject):
@@ -195,11 +195,11 @@ class Label(NylasAPIObject):
 
     @property
     def threads(self):
-        return self.child_collection({'in': self.id})
+        return self.child_collection(Thread, label_id=self.id)
 
     @property
     def messages(self):
-        return self.child_collection({'in': self.id})
+        return self.child_collection(Message, label_id=self.id)
 
 
 class Thread(NylasAPIObject):


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
index 05ac31b..a33ee02 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -199,10 +199,10 @@ def mock_label(api_url, account_id):
             "object": "label"
         }
     )
-    endpoint = re.compile(api_url + '/labels/anuep8pe5ugmxrucchrzba2o8')
+    url = api_url + '/labels/anuep8pe5ugmxrucchrzba2o8'
     responses.add(
         responses.GET,
-        endpoint,
+        url,
         content_type='application/json',
         status=200,
         body=response_body,
@@ -219,10 +219,10 @@ def mock_folder(api_url, account_id):
         "object": "folder"
         }
     response_body = json.dumps(folder)
-    endpoint = re.compile(api_url + '/folders/anuep8pe5ug3xrupchwzba2o8')
+    url = api_url + '/folders/anuep8pe5ug3xrupchwzba2o8'
     responses.add(
         responses.GET,
-        endpoint,
+        url,
         content_type='application/json',
         status=200,
         body=response_body,
@@ -236,7 +236,7 @@ def mock_folder(api_url, account_id):
 
     responses.add_callback(
         responses.PUT,
-        endpoint,
+        url,
         content_type='application/json',
         callback=request_callback,
     )
diff --git a/tests/test_folders.py b/tests/test_folders.py
index 50daf92..407c0d3 100644
--- a/tests/test_folders.py
+++ b/tests/test_folders.py
@@ -16,7 +16,6 @@ def test_get_change_folder(api_client):
 
 
 @responses.activate
-@pytest.mark.xfail
 @pytest.mark.usefixtures("mock_folder", "mock_threads")
 def test_folder_threads(api_client):
     folder = api_client.folders.find('anuep8pe5ug3xrupchwzba2o8')
@@ -26,7 +25,6 @@ def test_folder_threads(api_client):
 
 
 @responses.activate
-@pytest.mark.xfail
 @pytest.mark.usefixtures("mock_folder", "mock_messages")
 def test_folder_messages(api_client):
     folder = api_client.folders.find('anuep8pe5ug3xrupchwzba2o8')
diff --git a/tests/test_labels.py b/tests/test_labels.py
index 48acd86..74cf02e 100644
--- a/tests/test_labels.py
+++ b/tests/test_labels.py
@@ -1,6 +1,6 @@
 import pytest
 import responses
-from nylas.client.restful_models import Label
+from nylas.client.restful_models import Label, Thread, Message
 
 
 @responses.activate
@@ -19,3 +19,21 @@ def test_get_label(api_client):
     assert label is not None
     assert isinstance(label, Label)
     assert label.display_name == 'Important'
+
+
+@responses.activate
+@pytest.mark.usefixtures("mock_label", "mock_threads")
+def test_label_threads(api_client):
+    label = api_client.labels.find('anuep8pe5ugmxrucchrzba2o8')
+    assert label.threads
+    assert all(isinstance(thread, Thread)
+               for thread in label.threads)
+
+
+@responses.activate
+@pytest.mark.usefixtures("mock_label", "mock_messages")
+def test_label_messages(api_client):
+    label = api_client.labels.find('anuep8pe5ugmxrucchrzba2o8')
+    assert label.messages
+    assert all(isinstance(message, Message)
+               for message in label.messages)