class TestQueryRpmCommand(unittest.TestCase):
  
    def setUp(self):
        self.output = StringIO()
        self.http_client_mock = HttpClientMock()
        self.command = QueryRpmCommand(self.output)
        self.command.httpClient = self.http_client_mock
        
        files = '[{"repo":"production", "filename":"a-a-a-12.2-15.noarch.rpm"},' + \
        '{"repo":"production", "filename":"a-a-a-12.3-15.noarch.rpm"},' + \
        '{"repo":"production", "filename":"a-a-b-12.2-15.noarch.rpm"},' + \
        '{"repo":"production", "filename":"b-a-a-12.2-15.noarch.rpm"},' + \
        '{"repo":"production", "filename":"b-a-b-12.2-15.noarch.rpm"}]'
        self.http_client_mock.files_for('production', 'noarch', files)
    
    def test_find_rpms(self):
        self.command.doRun(self._create_args('a-a', 'production', 'noarch'))
        
        self.assertEquals(
            'a-a-a-12.2-15.noarch.rpm\na-a-a-12.3-15.noarch.rpm\na-a-b-12.2-15.noarch.rpm\nb-a-a-12.2-15.noarch.rpm\n',
            self.output.getvalue())
    
    def test_sort_descending(self):
        self.command.doRun(self._create_args('a-a-a', 'production', 'noarch', 'desc'))
      
        self.assertEquals(
            'a-a-a-12.3-15.noarch.rpm\na-a-a-12.2-15.noarch.rpm\n',
            self.output.getvalue())
    
    def _create_args(self, rpm_name, repository, arch, sort=''):
        args = ArgumentMock(rpm_name, repository, arch, sort)
        return args
class TestQueryRpmCommand(unittest.TestCase):
    def setUp(self):
        self.output = StringIO()
        self.http_client_mock = HttpClientMock()
        self.command = QueryRpmCommand(self.output)
        self.command.httpClient = self.http_client_mock

        files = '[{"repo":"production", "filename":"a-a-a-12.2-15.noarch.rpm"},' + \
        '{"repo":"production", "filename":"a-a-a-12.3-15.noarch.rpm"},' + \
        '{"repo":"production", "filename":"a-a-b-12.2-15.noarch.rpm"},' + \
        '{"repo":"production", "filename":"b-a-a-12.2-15.noarch.rpm"},' + \
        '{"repo":"production", "filename":"b-a-b-12.2-15.noarch.rpm"}]'
        self.http_client_mock.files_for('production', 'noarch', files)

    def test_find_rpms(self):
        self.command.doRun(self._create_args('a-a', 'production', 'noarch'))

        self.assertEquals(
            'a-a-a-12.2-15.noarch.rpm\na-a-a-12.3-15.noarch.rpm\na-a-b-12.2-15.noarch.rpm\nb-a-a-12.2-15.noarch.rpm\n',
            self.output.getvalue())

    def test_sort_descending(self):
        self.command.doRun(
            self._create_args('a-a-a', 'production', 'noarch', 'desc'))

        self.assertEquals(
            'a-a-a-12.3-15.noarch.rpm\na-a-a-12.2-15.noarch.rpm\n',
            self.output.getvalue())

    def _create_args(self, rpm_name, repository, arch, sort=''):
        args = ArgumentMock(rpm_name, repository, arch, sort)
        return args
    def setUp(self):
        self.output = StringIO()
        self.http_client_mock = HttpClientMock()
        self.command = QueryRpmCommand(self.output)
        self.command.httpClient = self.http_client_mock

        files = '[{"repo":"production", "filename":"a-a-a-12.2-15.noarch.rpm"},' + \
        '{"repo":"production", "filename":"a-a-a-12.3-15.noarch.rpm"},' + \
        '{"repo":"production", "filename":"a-a-b-12.2-15.noarch.rpm"},' + \
        '{"repo":"production", "filename":"b-a-a-12.2-15.noarch.rpm"},' + \
        '{"repo":"production", "filename":"b-a-b-12.2-15.noarch.rpm"}]'
        self.http_client_mock.files_for('production', 'noarch', files)
 def setUp(self):
     self.output = StringIO()
     self.http_client_mock = HttpClientMock()
     self.command = QueryRpmCommand(self.output)
     self.command.httpClient = self.http_client_mock
     
     files = '[{"repo":"production", "filename":"a-a-a-12.2-15.noarch.rpm"},' + \
     '{"repo":"production", "filename":"a-a-a-12.3-15.noarch.rpm"},' + \
     '{"repo":"production", "filename":"a-a-b-12.2-15.noarch.rpm"},' + \
     '{"repo":"production", "filename":"b-a-a-12.2-15.noarch.rpm"},' + \
     '{"repo":"production", "filename":"b-a-b-12.2-15.noarch.rpm"}]'
     self.http_client_mock.files_for('production', 'noarch', files)