Repository: mozmeao/basket

Issue:
Additional Common Voice fields (2 day streak & Last Active date)
There are 2 new fields that we need ported over from Common Voice into SFDC. The fields are: 

2 day streak / boolean (cv_two_day_streak__c)
Common Voice Last Active Date (date) (cv_last_active_dt__c)

Please work with Desiree and Gregor w/ the Common Voice team to get these data values tested in the ADVO SFDC Sandbox, then moved to Production. 


Discussion:

Resolving patch:
diff --git a/basket/news/backends/sfdc.py b/basket/news/backends/sfdc.py
--- a/basket/news/backends/sfdc.py
+++ b/basket/news/backends/sfdc.py
@@ -67,6 +67,8 @@ def cast_lower(value):
     'cv_created_at': 'cv_created_at__c',
     'cv_goal_reached_at': 'cv_goal_reached_at__c',
     'cv_first_contribution_date': 'cv_first_contr_dt__c',
+    'cv_two_day_streak': 'cv_two_day_streak__c',
+    'cv_last_active_date': 'cv_last_active_dt__c',
 }
 INV_FIELD_MAP = {v: k for k, v in FIELD_MAP.items()}
 FIELD_DEFAULTS = {
diff --git a/basket/news/forms.py b/basket/news/forms.py
--- a/basket/news/forms.py
+++ b/basket/news/forms.py
@@ -78,6 +78,10 @@ class CommonVoiceForm(forms.Form):
     first_contribution_date = forms.CharField(required=False,
                                               max_length=20,
                                               validators=[validate_datetime_str])
+    last_active_date = forms.CharField(required=False,
+                                       max_length=20,
+                                       validators=[validate_datetime_str])
+    two_day_streak = forms.NullBooleanField()
 
 
 class SubscribeForm(forms.Form):
diff --git a/basket/news/views.py b/basket/news/views.py
--- a/basket/news/views.py
+++ b/basket/news/views.py
@@ -290,7 +290,7 @@ def common_voice_goals(request):
     form = CommonVoiceForm(request.POST)
     if form.is_valid():
         # don't send empty values and use ISO formatted date strings
-        data = {k: v for k, v in form.cleaned_data.items() if v}
+        data = {k: v for k, v in form.cleaned_data.items() if not (v == '' or v is None)}
         record_common_voice_goals.delay(data)
         return HttpResponseJSON({'status': 'ok'})
     else:


Test patch:
diff --git a/basket/news/tests/test_views.py b/basket/news/tests/test_views.py
--- a/basket/news/tests/test_views.py
+++ b/basket/news/tests/test_views.py
@@ -1114,6 +1114,27 @@ def test_valid_submission(self):
         data = json.loads(resp.content)
         self.assertEqual('ok', data['status'])
 
+    def test_valid_submission_with_boolean(self):
+        self.has_valid_api_key.return_value = True
+        req = self.rf.post('/', {
+            'email': 'dude@example.com',
+            'days_interval': '1',
+            'created_at': '2019-04-07T12:42:34Z',
+            'last_active_date': '2019-04-17T12:42:34Z',
+            'two_day_streak': 'True',
+        })
+        resp = views.common_voice_goals(req)
+        self.record_common_voice_goals.delay.assert_called_with({
+            'email': 'dude@example.com',
+            'days_interval': 1,
+            'created_at': '2019-04-07T12:42:34Z',
+            'last_active_date': '2019-04-17T12:42:34Z',
+            'two_day_streak': True,
+        })
+        self.assertEqual(resp.status_code, 200, resp.content)
+        data = json.loads(resp.content)
+        self.assertEqual('ok', data['status'])
+
     def test_invalid_date(self):
         self.has_valid_api_key.return_value = True
         req = self.rf.post('/', {