Пример #1
0
 def handle(self, *args, **kwargs):
     url = kwargs.get('url')
     username = kwargs.get('username')
     password = kwargs.get('password')
     to = kwargs.get('to')
     user = User.objects.get(username=to)
     bc = BriefcaseClient(username=username, password=password,
                          user=user, url=url)
     bc.push()
Пример #2
0
 def handle(self, *args, **kwargs):
     url = kwargs.get('url')
     username = kwargs.get('username')
     password = kwargs.get('password')
     to = kwargs.get('to')
     user = User.objects.get(username=to)
     bc = BriefcaseClient(username=username, password=password,
                          user=user, url=url)
     bc.download_xforms(include_instances=True)
Пример #3
0
 def handle(self, *args, **kwargs):
     url = kwargs.get('url')
     username = kwargs.get('username')
     password = kwargs.get('password')
     to = kwargs.get('to')
     user = User.objects.get(username=to)
     bc = BriefcaseClient(username=username, password=password,
                          user=user, url=url)
     bc.download_xforms(include_instances=True)
Пример #4
0
 def handle(self, *args, **options):
     url = options.get('url')
     username = options.get('username')
     password = options.get('password')
     to = options.get('to')
     user = User.objects.get(username=to)
     bc = BriefcaseClient(username=username,
                          password=password,
                          user=user,
                          url=url)
     bc.push()
Пример #5
0
 def handle(self, *args, **kwargs):
     url = kwargs.get('url')
     username = kwargs.get('username')
     password = kwargs.get('password')
     to = kwargs.get('to')
     if username is None or password is None or to is None or url is None:
         self.stderr.write(
             'pull_form_aggregate -u username -p password --to=username'
             ' --url=aggregate_server_url')
     else:
         user = User.objects.get(username=to)
         bc = BriefcaseClient(
             username=username, password=password, user=user, url=url)
         bc.download_xforms(include_instances=True)
Пример #6
0
 def setUp(self):
     TestBase.setUp(self)
     self._publish_transportation_form()
     self._submit_transport_instance_w_attachment()
     src = os.path.join(self.this_directory, "fixtures", "transportation",
                        "screenshot.png")
     uf = UploadedFile(file=open(src, 'rb'), content_type='image/png')
     count = MetaData.objects.count()
     MetaData.media_upload(self.xform, uf)
     self.assertEqual(MetaData.objects.count(), count + 1)
     url = urljoin(
         self.base_url,
         reverse(profile, kwargs={'username': self.user.username}))
     self._logout()
     self._create_user_and_login('deno', 'deno')
     self.bc = BriefcaseClient(username='******',
                               password='******',
                               url=url,
                               user=self.user)
Пример #7
0
 def setUp(self):
     TestBase.setUp(self)
     self._publish_transportation_form()
     self._submit_transport_instance_w_attachment()
     src = os.path.join(self.this_directory, "fixtures",
                        "transportation", "screenshot.png")
     uf = UploadedFile(file=open(src), content_type='image/png')
     count = MetaData.objects.count()
     MetaData.media_upload(self.xform, uf)
     self.assertEqual(MetaData.objects.count(), count + 1)
     url = urljoin(
         self.base_url,
         reverse(profile, kwargs={'username': self.user.username})
     )
     self._logout()
     self._create_user_and_login('deno', 'deno')
     self.bc = BriefcaseClient(
         username='******', password='******',
         url=url,
         user=self.user
     )
Пример #8
0
class TestBriefcaseClient(TestBase):

    def setUp(self):
        TestBase.setUp(self)
        self._publish_transportation_form()
        self._submit_transport_instance_w_attachment()
        src = os.path.join(self.this_directory, "fixtures",
                           "transportation", "screenshot.png")
        uf = UploadedFile(file=open(src), content_type='image/png')
        count = MetaData.objects.count()
        MetaData.media_upload(self.xform, uf)
        self.assertEqual(MetaData.objects.count(), count + 1)
        url = urljoin(
            self.base_url,
            reverse(profile, kwargs={'username': self.user.username})
        )
        self._logout()
        self._create_user_and_login('deno', 'deno')
        self.bc = BriefcaseClient(
            username='******', password='******',
            url=url,
            user=self.user
        )

    def test_download_xform_xml(self):
        """
        Download xform via briefcase api
        """
        with HTTMock(form_list_xml):
            self.bc.download_xforms()
        forms_folder_path = os.path.join(
            'deno', 'briefcase', 'forms', self.xform.id_string)
        self.assertTrue(storage.exists(forms_folder_path))
        forms_path = os.path.join(forms_folder_path,
                                  '%s.xml' % self.xform.id_string)
        self.assertTrue(storage.exists(forms_path))
        form_media_path = os.path.join(forms_folder_path, 'form-media')
        self.assertTrue(storage.exists(form_media_path))
        media_path = os.path.join(form_media_path, 'screenshot.png')
        self.assertTrue(storage.exists(media_path))

        """
        Download instance xml
        """
        with HTTMock(instances_xml):
            self.bc.download_instances(self.xform.id_string)
        instance_folder_path = os.path.join(
            'deno', 'briefcase', 'forms', self.xform.id_string, 'instances')
        self.assertTrue(storage.exists(instance_folder_path))
        instance = Instance.objects.all()[0]
        instance_path = os.path.join(
            instance_folder_path, 'uuid%s' % instance.uuid, 'submission.xml')
        self.assertTrue(storage.exists(instance_path))
        media_file = "1335783522563.jpg"
        media_path = os.path.join(
            instance_folder_path, 'uuid%s' % instance.uuid, media_file)
        self.assertTrue(storage.exists(media_path))

    def test_push(self):
        with HTTMock(form_list_xml):
            self.bc.download_xforms()
        with HTTMock(instances_xml):
            self.bc.download_instances(self.xform.id_string)
        XForm.objects.all().delete()
        xforms = XForm.objects.filter(
            user=self.user, id_string=self.xform.id_string)
        self.assertTrue(xforms.count() == 0)
        instances = Instance.objects.filter(
            user=self.user, xform__id_string=self.xform.id_string)
        self.assertTrue(instances.count() == 0)
        self.bc.push()
        xforms = XForm.objects.filter(
            user=self.user, id_string=self.xform.id_string)
        self.assertTrue(xforms.count() == 1)
        instances = Instance.objects.filter(
            user=self.user, xform__id_string=self.xform.id_string)
        self.assertTrue(instances.count() == 1)

    def tearDown(self):
        # remove media files
        for username in ['bob', 'deno']:
            if storage.exists(username):
                shutil.rmtree(storage.path(username))
Пример #9
0
class TestBriefcaseClient(TestBase):
    def setUp(self):
        TestBase.setUp(self)
        self._publish_transportation_form()
        self._submit_transport_instance_w_attachment()
        src = os.path.join(self.this_directory, "fixtures", "transportation",
                           "screenshot.png")
        uf = UploadedFile(file=open(src, 'rb'), content_type='image/png')
        count = MetaData.objects.count()
        MetaData.media_upload(self.xform, uf)
        self.assertEqual(MetaData.objects.count(), count + 1)
        url = urljoin(
            self.base_url,
            reverse(profile, kwargs={'username': self.user.username}))
        self._logout()
        self._create_user_and_login('deno', 'deno')
        self.bc = BriefcaseClient(username='******',
                                  password='******',
                                  url=url,
                                  user=self.user)

    def test_download_xform_xml(self):
        """
        Download xform via briefcase api
        """
        with HTTMock(form_list_xml):
            self.bc.download_xforms()

        is_local = storage.__class__.__name__ == 'FileSystemStorage'

        forms_folder_path = os.path.join('deno', 'briefcase', 'forms',
                                         self.xform.id_string)
        forms_path = os.path.join(forms_folder_path,
                                  '%s.xml' % self.xform.id_string)
        form_media_path = os.path.join(forms_folder_path, 'form-media')
        media_path = os.path.join(form_media_path, 'screenshot.png')

        if is_local:
            does_root_folder_exist = storage.exists(forms_folder_path)
            does_media_folder_exist = storage.exists(form_media_path)
        else:
            # `django-storage.exists()` does not work with folders on AWS
            sub_folders, files = storage.listdir(forms_folder_path)
            does_root_folder_exist = bool(sub_folders or files)
            does_media_folder_exist = 'form-media' in sub_folders

        self.assertTrue(does_root_folder_exist)
        self.assertTrue(storage.exists(forms_path))
        self.assertTrue(does_media_folder_exist)
        self.assertTrue(storage.exists(media_path))
        """
        Download instance xml
        """
        with HTTMock(instances_xml):
            self.bc.download_instances(self.xform.id_string)

        instance_folder_path = os.path.join(forms_folder_path, 'instances')
        if is_local:
            does_instances_folder_exist = storage.exists(instance_folder_path)
        else:
            sub_folders, _ = storage.listdir(forms_folder_path)
            does_instances_folder_exist = 'instances' in sub_folders

        self.assertTrue(does_instances_folder_exist)

        instance = Instance.objects.all()[0]
        instance_path = os.path.join(instance_folder_path,
                                     'uuid%s' % instance.uuid,
                                     'submission.xml')
        self.assertTrue(storage.exists(instance_path))
        media_file = "1335783522563.jpg"
        media_path = os.path.join(instance_folder_path,
                                  'uuid%s' % instance.uuid, media_file)
        self.assertTrue(storage.exists(media_path))

    def test_push(self):
        with HTTMock(form_list_xml):
            self.bc.download_xforms()
        with HTTMock(instances_xml):
            self.bc.download_instances(self.xform.id_string)
        XForm.objects.all().delete()
        xforms = XForm.objects.filter(user=self.user,
                                      id_string=self.xform.id_string)
        self.assertTrue(xforms.count() == 0)
        instances = Instance.objects.filter(
            xform__user=self.user, xform__id_string=self.xform.id_string)
        self.assertTrue(instances.count() == 0)
        self.bc.push()
        xforms = XForm.objects.filter(user=self.user,
                                      id_string=self.xform.id_string)
        self.assertTrue(xforms.count() == 1)
        instances = Instance.objects.filter(
            xform__user=self.user, xform__id_string=self.xform.id_string)
        self.assertTrue(instances.count() == 1)

    def tearDown(self):
        # remove media files
        for username in ['bob', 'deno']:
            delete_user_storage(username)