Пример #1
0
 def test_get_editColumnOrder(self):
     addColsToSilo(self.silo, ['a', 'b', 'c', 'd', 'e', 'f'])
     hideSiloColumns(self.silo, ['b', 'e'])
     self.silo.rows_to_hide = json.dumps([
         {
             "logic": "BLANKCHAR",
             "operation": "",
             "number": "",
             "conditional": "---",
         },
         {
             "logic": "AND",
             "operation": "empty",
             "number": "",
             "conditional": ["a", "b"],
         },
         {
             "logic": "OR",
             "operation": "empty",
             "number": "",
             "conditional": ["c", "d"],
         }
     ])
     self.silo.save()
     request = self.factory.get(self.url)
     request.user = self.user
     request._dont_enforce_csrf_checks = True
     response = addColumnFilter(request, self.silo.pk)
     self.assertEqual(response.status_code, 200)
Пример #2
0
 def test_post_editColumnOrder(self):
     addColsToSilo(self.silo, ['a', 'b', 'c', 'd', 'e', 'f'])
     hideSiloColumns(self.silo, ['b', 'e'])
     cols_ordered = ['c', 'f', 'a', 'd']
     response = self.client.post('/edit_column_order/%s/' %
                                 str(self.silo.pk),
                                 data={'columns': cols_ordered})
     self.assertEqual(response.status_code, 302)
     self.assertEqual(getSiloColumnNames(self.silo.pk),
                      ['c', 'f', 'a', 'd'])
     response = self.client.post('/edit_column_order/0/',
                                 data={'columns': cols_ordered})
     self.assertEqual(response.status_code, 302)
Пример #3
0
def getCommCareCaseData(domain, auth, auth_header, total_cases, silo, read):
    """
    Use fetch and request CommCareData to store all of the case data

    domain -- the domain name used for a commcare project
    auth -- the authorization required
    auth_header -- True = use Header, False = use Digest authorization
    total_cases -- total cases to get
    silo - silo to put the data into
    read -- read that the data is apart of
    """

    RECORDS_PER_REQUEST = 100
    base_url = "https://www.commcarehq.org/a/"+ domain\
                +"/api/v0.5/case/?format=JSON&limit="+str(RECORDS_PER_REQUEST)

    data_raw = fetchCommCareData(base_url, auth, auth_header,\
                    0, total_cases, RECORDS_PER_REQUEST, silo.id, read.id)
    data_collects = data_raw.apply_async()
    data_retrieval = [v.get() for v in data_collects]
    columns = set()
    for data in data_retrieval:
        columns = columns.union(data)
    #correct the columns
    for column in columns:
        if "." in column:
            columns.remove(column)
            columns.add(column.replace(".", "_"))
        if "$" in column:
            columns.remove(column)
            columns.add(column.replace("$", "USD"))
    try:
        columns.remove("")
    except KeyError as e:
        pass
    try:
        columns.remove("silo_id")
    except KeyError as e:
        pass
    try:
        columns.remove("read_id")
    except KeyError as e:
        pass
    try:
        columns.remove("id")
        columns.add("user_assigned_id")
    except KeyError as e:
        pass
    try:
        columns.remove("_id")
        columns.add("user_assigned_id")
    except KeyError as e:
        pass
    try:
        columns.remove("edit_date")
        columns.add("editted_date")
    except KeyError as e:
        pass
    try:
        columns.remove("create_date")
        columns.add("created_date")
    except KeyError as e:
        pass

    #add new columns to the list of current columns this is slower because
    #order has to be maintained (2n instead of n)
    addColsToSilo(silo, columns)
    hideSiloColumns(silo, ["case_id"])

    return (messages.SUCCESS, "CommCare cases imported successfully", columns)