Beispiel #1
0
 def test__ne__equal(self):
     """common.Member.__ne__: The method should return False 
     when comparing two common.Member objects with the same 
     attribute values.
     """
     obj1 = com.Member('Spam', 'Eggs', 'D')
     obj2 = com.Member('Spam', 'Eggs', 'D')
     self.assertFalse(obj1 != obj2)
Beispiel #2
0
 def test__eq__equal(self):
     """common.Member.__eq__: The function should return True 
     when comparing two common.Member objects with the same 
     attribute values.
     """
     obj1 = com.Member('Spam', 'Eggs', 'D', 'Senate', 'IL')
     obj2 = com.Member('Spam', 'Eggs', 'D', 'Senate', 'IL')
     self.assertTrue(obj1 == obj2)
Beispiel #3
0
    def test_valid(self, mock__get, mock__parse_json):
        """unitedstates.members: The function should return a list 
        of common.Member objects representing the members of U.S. 
        Congress.
        """
        data = [
            [
                'Spam',
                'Eggs',
                'Democrat',
                'Senate',
                'IL',
            ],
            [
                'Bacon',
                'Baked Beans',
                'Independent',
                'Senate',
                'IL',
            ],
        ]
        us_json = [build_us_details(item) for item in data]
        expected = [com.Member(*args) for args in data]

        mock__get.return_value = json.dumps(us_json)
        mock__parse_json.return_value = us_json
        actual = us.members()

        self.assertEqual(expected, actual)
        mock__parse_json.assert_called_with(json.dumps(us_json))
Beispiel #4
0
    def test__from_json(self):
        """common.Member.from_json: Given a dictionary of 
        information from the @unitedstates project, the 
        method should return an instance of common.Members.
        """
        expected = com.Member('Spam', 'Eggs', 'Democrat', 'Senate', 'IL')

        data = {
            'name': {
                'first': 'Eggs',
                'last': 'Spam',
                'official_full': 'Spam Eggs',
            },
            'terms': [
                {
                    'type': 'sen',
                    'start': '1995-01-04',
                    'end': '2001-01-03',
                    'state': 'IL',
                    'class': 1,
                    'party': 'Democrat',
                },
                {
                    'type': 'sen',
                    'start': '2001-01-04',
                    'end': '2007-01-03',
                    'state': 'IL',
                    'class': 1,
                    'party': 'Democrat',
                },
            ]
        }
        actual = com.Member.from_json(data)

        self.assertEqual(expected, actual)
Beispiel #5
0
 def test_valid(self, mock__members, mock__build_matrix):
     """cli.members: The function should output a list of 
     the members of the U.S. Congress.
     """
     matrix = [
         [
             'Last Name',            # Member.last_name
             'First Name',           # Member.first_name
             'Party',                # Member.party
         ],
         ['Durbin', 'Dick', 'Democrat',],
         ['Duckworth', 'Tammy', 'Democrat',],
         ['Sanders', 'Benard', 'Independent',],
     ]
     tmp = '{:<20} {:<20} {}\n'
     lines = ['\n',]
     lines.append('LIST OF MEMBERS\n')
     lines.append('---------------\n')
     for line in [tmp.format(*args) for args in matrix]:
         lines.append(line)
     lines.append('---------------\n')
     lines.append('\n')
     expected = ''.join(lines)
     
     mock__members.return_value = [common.Member(*args) 
                                   for args in matrix[1:]]
     mock__build_matrix.return_value = matrix
     with capture() as (out, err):
         cli.members()
     actual = out.getvalue()
     
     self.assertEqual(expected, actual)
Beispiel #6
0
 def test__eq__notEqual(self):
     """common.Member.__eq__: The function should return False 
     when comparing two common.Member objects with different 
     attribute values.
     """
     obj = com.Member('Spam', 'Eggs', 'D')
     others = [
         com.Member('Spam', 'Eggs', 'R'),
         com.Member('Spam', 'Bacon', 'D'),
         com.Member('Baked Beans', 'Eggs', 'D'),
         com.Member('Spam', 'Ham', 'I'),
         com.Member('Tomato', 'Eggs', 'I'),
         com.Member('Dick', 'Durbin', 'D'),
         com.Member('Bernie', 'Sanders', 'I'),
         com.Member('Spam', 'Eggs', 'D', 'House'),
         com.Member('Spam', 'Eggs', 'D', None, 'IL'),
     ]
     for other in others:
         self.assertFalse(obj == other)
Beispiel #7
0
    def test__repr(self):
        """common.Member.__repr__: The method should return a 
        string representation of the object suitable for 
        troubleshooting.
        """
        expected = "Member('Spam', 'Eggs', 'D', 'House', 'IL')"

        mbr = com.Member('Spam', 'Eggs', 'D', 'House', 'IL')
        actual = mbr.__repr__()

        self.assertEqual(expected, actual)
Beispiel #8
0
    def test__eq__notMember(self):
        """common.Member.__eq__: The method should raise a 
        NotImplemented exception if asked to compare a 
        non-common.Member object.
        """
        expected = NotImplemented

        obj1 = com.Member('Spam', 'Eggs', 'D')
        obj2 = 3
        actual = obj1.__eq__(obj2)

        self.assertEqual(expected, actual)
Beispiel #9
0
    def test_init(self):
        """common.Member.__init__: The attributes of the class 
        should be populated with the given values when initialized. 
        """
        expected = ['Spam', 'Eggs', 'D', 'Senate', 'IL']

        obj = com.Member(*expected)
        actual = [
            obj.last_name,
            obj.first_name,
            obj.party,
            obj.chamber,
            obj.state,
        ]

        self.assertEqual(expected, actual)
Beispiel #10
0
    def test_valid(self):
        """common.build_member_matrix: Given a list of common.
        Member objects, return a list of rows suitable for 
        writing into a report.
        """
        expected = [
            [
                'Last Name',
                'First Name',
                'Party',
            ],
        ]
        expected.extend(build_args_list())

        mem_list = [com.Member(*args) for args in build_args_list()]
        actual = com.build_member_matrix(mem_list)

        self.assertEqual(expected, actual)