Exemplo n.º 1
0
 def setUp(self):
     super(FormExportTest, self).setUp()
     self.app_id = 'kasdlfkjsldfkjsdlkjf'
     self.domain_name = 'form-export-test'
     self.domain = create_domain(self.domain_name)
     self.username = '******'
     self.couch_user = CommCareUser.create(self.domain_name,
                                           self.username,
                                           password='******')
     self.couch_user.save()
     self.client = Client()
     self.client.login(username=self.couch_user.username, password='******')
     self.url = reverse("receiver_post_with_app_id",
                        args=[self.domain_name, self.app_id])
     self.custom_export = FormExportSchema.wrap({
         'type':
         'form',
         'app_id':
         self.app_id,
         'default_format':
         Format.JSON,
         'index':
         json.dumps([self.domain_name, XMLNS]),
         'tables': [{
             'index': '#',
             'display': 'Export',
             'columns': [{
                 'index': 'form.name',
                 'display': 'Name'
             }],
         }]
     })
Exemplo n.º 2
0
 def setUpClass(cls):
     cls.client = Client()
     cls.client.login(username="******",
                      password="******")
     cls.unique_id = random_string()
     cls.project_id = create_multiple_unique_id_project(
         cls.client, cls.unique_id)
     cls.client.set_authorization('*****@*****.**',
                                  'tester150411',
                                  method="Digest")
     cls.register_people_one(cls.client)
Exemplo n.º 3
0
    def testOtaRestore(self, password=None):
        client = Client()

        client.set_authorization(self.couch_user.username,
                                 password if password else self.password,
                                 method='Digest')

        resp = client.get('/a/%s/phone/restore' % self.domain, follow=True)
        self.assertEqual(resp.status_code, 200)
        self.assertTrue(
            resp.content.count("Successfully restored account %s!" %
                               self.username) > 0)
Exemplo n.º 4
0
    def test_pages(self):
        """
        Confirm that all the groups/locations/users appear on the correct pages
        """
        client = Client()
        client.login(username=self.username, password=self.password)

        # expected_id_sets is a list of sets.
        # expected_id_sets is constructed such that
        # For option with index x yielded by the view:
        #   the option's id should be in expected_ids[x]
        expected_id_sets = [{"user_location"}, {"user_parent_location"}]

        for i in self.groups:
            expected_id_sets.append(self.group_ids)
        for i in self.locations:
            expected_id_sets.append(self.location_ids)
        for i in self.users:
            expected_id_sets.append(self.user_ids)

        page_size = 3  # using a small number because more pages will hopefully be more likely to reveal bugs
        expected_num_pages = int(
            math.ceil(len(expected_id_sets) / float(page_size)))
        for i in range(expected_num_pages):
            page = i + 1
            response = client.get(reverse(CallCenterOwnerOptionsView.url_name,
                                          args=[self.domain.name]),
                                  data={
                                      "page": page,
                                      "page_limit": page_size,
                                      "q": ""
                                  })
            response_json = json.loads(response.content)
            self.assertEqual(response_json['total'], len(expected_id_sets))

            for item_index, item in enumerate(response_json['results']):
                id_ = item['id']
                option_index = ((page - 1) * page_size) + item_index
                self.assertTrue(
                    id_ in expected_id_sets[option_index],
                    "Unexpected item {} at index {}.".format(
                        item, option_index))
Exemplo n.º 5
0
    def test_SMS_API_Users_not_shown_on_user_list_page(self):
        client = Client()
        client.login(username=DEFAULT_TEST_USER,
                     password=DEFAULT_TEST_PASSWORD)
        request = HttpRequest()
        request.method = 'GET'
        request.user = User.objects.get(username="******")

        with patch('datawinners.accountmanagement.views.User') as user_class:
            with patch('datawinners.accountmanagement.views.RequestContext'
                       ) as context:
                with patch(
                        "datawinners.accountmanagement.views.render_to_response"
                ) as render_response_patch:
                    objects = Mock()
                    type(user_class).objects = PropertyMock(
                        return_value=objects)
                    users(request)
                    objects.exclude.assert_called_once_with(
                        groups__name__in=['Data Senders', 'SMS API Users'])