Пример #1
0
    def test_matches_dict_7(self):
        """
        Test allowed_types['components'] = [Entity]
        """

        e = Entity(self.p, title='Clean cat box', creator='Matt',
            components=[Entity(self.p, title='bogus component')],
            tags=['boring', 'chore'], priority=self.important)

        assert e.matches_dict(
            components='bogus component') == e, 'OH NOES'
Пример #2
0
class TestMatchesDict(unittest.TestCase):

    def setUp(self):

        self.p = Project(title="TestMatchesDict")

        self.important = Entity(self.p, title='Important!!!')

        Entity.allowed_types['priority'] = Entity

        Entity.allowed_types['components'] = [Entity]

        self.e = Entity(self.p, title='Clean cat box', creator='Matt',
            pscore=99, tags=['boring', 'chore'], priority=self.important)

    def test_matches_dict_1(self):
        """
        Verify matches_dict handles scalars and list comparisons.
        """

        assert self.e.matches_dict(creator='Matt') == self.e
        assert self.e.matches_dict(creator='Nobody') == None
        assert self.e.matches_dict(tags=['boring', 'chore']) == self.e
        assert self.e.matches_dict(tags='boring') == self.e
        assert self.e.matches_dict(tags='chore') == self.e
        assert self.e.matches_dict(creator=['Matt']) == self.e
        assert self.e.matches_dict(creator=['Matt', 'Nobody']) == self.e
        assert self.e.matches_dict(pscore=99) == self.e

        assert self.e.matches_dict(
            creator=['Matt', 'Nobody'],
            tags=['fun']) == None

        assert self.e.matches_dict(
            creator=['Matt', 'Nobody'],
            tags=['fun', 'boring']) == self.e

    def test_order_independence_of_query(self):
        """
        Test two attributes with lists as values.
        """

        assert not self.e.matches_dict(creator=['Matt'],
            title=['DO NOT MATCH'])

        assert not self.e.matches_dict(creator=['DO NOT MATCH'],
            title=['Clean cat box'])

    def test_order_independence_of_subquery(self):
        """
        Test two attributes with lists, and one of the lists has a title
        as an element.
        """

        assert not self.e.matches_dict(
            priority=[self.important.title], # this one matches
            tags=['DOES NOT MATCH'])         # but not this one.

    def test_matches_dict_2(self):
        """
        Verify we can match entities by using their UUID
        """

        assert self.e.matches_dict(priority=self.important) == self.e

        print("got %s" % self.e.matches_dict(priority=self.important.uuid))

        assert self.e.matches_dict(priority=self.important.uuid) == self.e

        frag = self.important.frag

        assert self.e.matches_dict(priority=frag) == self.e

    def test_matches_dict_3(self):
        """
        Verify we can match entities by using their title.
        """

        assert 'priority' in self.e.allowed_types

        print("self.e['priority'] is %(priority)s" % self.e)

        assert self.e.matches_dict(
            priority=self.important.title) == self.e, \
        "Lookup using title failed"

    def test_matches_dict_4(self):
        """
        Verify we can match with lists of titles.
        """

        print("self.e['priority'] is %(priority)s" % self.e)

        assert self.e.matches_dict(
            priority=[self.important.title]) == self.e, \
        "Lookup using list of titles failed"

    def test_matches_dict_5(self):
        """
        Verify we can match with lists of titles.
        """

        print('priority is %(priority)s' % self.e)

        print('what they really meant: %s'
            % self.e.what_they_really_mean('priority', ['bogus']))

        temp = self.e.matches_dict(priority=["bogus"])

        assert temp is None, "temp (%s) should be None!" % temp

    def test_matches_dict_6(self):
        """
        Verify we can match with lists of frags.
        """

        print("self.e['priority'] is %(priority)s" % self.e)

        assert self.e.matches_dict(
            priority=[self.important.frag]) == self.e, \
        "Lookup using list of frags failed"

    def test_matches_dict_7(self):
        """
        Test allowed_types['components'] = [Entity]
        """

        e = Entity(self.p, title='Clean cat box', creator='Matt',
            components=[Entity(self.p, title='bogus component')],
            tags=['boring', 'chore'], priority=self.important)

        assert e.matches_dict(
            components='bogus component') == e, 'OH NOES'