Exemplo n.º 1
0
Arquivo: cli.py Projeto: pdc/dozup
def main(argv):
    parser = create_parser()
    options = parser.parse_args(argv)

    queue = DozupQueue(options.data_dir)
    poster = DozupPoster(options.url)

    errors = []
    for task in queue.iter_tasks():
        is_ok = poster.post(task.name, task.input)
        if not is_ok:
            task.push_back()
            errors += poster.errors

    return errors
Exemplo n.º 2
0
class PosterTestMixin(unittest.TestCase):
    status_code = 202
    endpoint_uri = "http://example.com/drop/"
    content_type = "application/json"
    content = json.dumps({"status": "OK"})

    def setUp(self):
        super(PosterTestMixin, self).setUp()
        self.dir_path = tempfile.mkdtemp(".test", "DozupQueueTests.")
        self.poster = DozupPoster("http://example.com/drop/")

    def tearDown(self):
        shutil.rmtree(self.dir_path)
        super(PosterTestMixin, self).tearDown()

    def given_server_endpoint(self, content=None, content_type=None):
        httpretty.register_uri(
            httpretty.POST,
            self.endpoint_uri,
            status=self.status_code,
            content_type=(content_type or self.content_type),
            body=(content or self.content),
        )

    def when_posting(self, file_name="name_of_file.txt", file_content=b"content of file"):
        strm = io.BytesIO(file_content)
        self.result = self.poster.post(file_name, strm)

    def then_error_should_be(self, expected):
        self.assertFalse(self.result)
        self.assertEqual(DozupError(self.status_code, expected), self.poster.errors[-1])
Exemplo n.º 3
0
 def setUp(self):
     super(PosterTestMixin, self).setUp()
     self.dir_path = tempfile.mkdtemp(".test", "DozupQueueTests.")
     self.poster = DozupPoster("http://example.com/drop/")