Jason R. Coombs avatar Jason R. Coombs committed af80b05

Added set_label and clear_label to Cards

Comments (0)

Files changed (2)

         return Member(self, 'me')
 
 
-
 class Closable(object):
     """
     Mixin for Trello objects for which you're allowed to PUT to <id>/closed.
         self._conn.delete(path)
 
 
+class Labeled(object):
+    """
+    Mixin for Trello objects which have labels.
+    """
+
+    _valid_label_colors = [
+        'green',
+        'yellow',
+        'orange',
+        'red',
+        'purple',
+        'blue',
+    ]
+
+    def set_label(self, color):
+        self._do_label(color, self._conn.post)
+    def clear_label(self, color):
+        self._do_label(color, self._conn.delete)
+
+    def _do_label(self, color, method):
+        color = color.lower()
+        if color not in self._valid_label_colors:
+            raise ValueError("invalid color")
+        path = self._prefix + self._id + '/labels'
+        method(path)
+
+
 class Field(object):
     """
     A simple field on a Trello object.  Maps the attribute to a key in the
     members = SubList('Member')
 
 
-class Card(LazyTrello, Closable, Deletable):
+class Card(LazyTrello, Closable, Deletable, Labeled):
 
     _prefix = '/cards/'
 
     checklists = ListField('idChecklists','Checklist')
     members = ListField('idMembers', 'Member')
 
-
 class Checklist(LazyTrello):
 
     _prefix = '/checklists/'
 import json
 import urlparse
 
+import trollop
 from trollop import TrelloConnection
 
 
                 'Fake List from Fake Board 2')
 
 class ChecklistItemTests(TrollopTestCase):
-    
-    data = { '/1/checklists/fakeCheckListId/checkItems/': 
+
+    data = { '/1/checklists/fakeCheckListId/checkItems/':
             [
                 {   'id':   'fakeCheckItem1',
                     'name': 'fake Check Item 1',
         assert(checklist.checkItems[0].name == 'fake Check Item 1')
         assert(checklist.checkItems[0].type == 'check')
         assert(checklist.checkItems[1].pos  == 123457)
+
+class TestLabeled(object):
+    def test_Cards_are_labeled(self):
+        """
+        Cards should have set_label and clear_label methods.
+        """
+        assert hasattr(trollop.Card, 'set_label')
+        assert hasattr(trollop.Card, 'clear_label')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.