Example #1
0
    def test_sync_from_creation(self):
        properties = _arbitrary_session_properties()
        couch_session = XFormsSession(**properties)
        couch_session.save()
        sql_session = SQLXFormsSession.objects.get(couch_id=couch_session._id)
        for prop, value in properties.items():
            self.assertEqual(getattr(sql_session, prop), value)

        # make sure we didn't do any excess saves
        self.assertTrue(XFormsSession.get_db().get_rev(couch_session._id).startswith('1-'))
Example #2
0
    def test_sync_from_update(self):
        properties = _arbitrary_session_properties()
        couch_session = XFormsSession(**properties)
        couch_session.save()
        sql_session = SQLXFormsSession.objects.get(couch_id=couch_session._id)
        for prop, value in properties.items():
            self.assertEqual(getattr(sql_session, prop), value)

        previous_count = SQLXFormsSession.objects.count()
        updated_properties = _arbitrary_session_properties()
        for attr, val in updated_properties.items():
            couch_session[attr] = val
        couch_session.save()

        # make sure nothing new was created
        self.assertEqual(previous_count, SQLXFormsSession.objects.count())
        # check updated props in the sql model
        sql_session = SQLXFormsSession.objects.get(pk=sql_session.pk)
        for prop, value in updated_properties.items():
            self.assertEqual(getattr(sql_session, prop), value)
Example #3
0
 def test_get_single_open_session(self):
     properties = _arbitrary_session_properties(
         end_time=None,
         session_type=XFORMS_SESSION_SMS,
     )
     couch_session = XFormsSession(**properties)
     couch_session.save()
     (mult, session) = get_single_open_session_or_close_multiple(
         couch_session.domain, couch_session.connection_id
     )
     self.assertEqual(False, mult)
     self.assertEqual(couch_session._id, session._id)
     [couch_session_back] = XFormsSession.get_all_open_sms_sessions(
         couch_session.domain, couch_session.connection_id
     )
     [sql_session] = SQLXFormsSession.get_all_open_sms_sessions(
         couch_session.domain, couch_session.connection_id
     )
     self.assertEqual(couch_session._id, couch_session_back._id)
     self.assertEqual(couch_session._id, sql_session.couch_id)
Example #4
0
def _make_session(**kwargs):
    properties = _arbitrary_session_properties(**kwargs)
    couch_session = XFormsSession(**properties)
    couch_session.save()
    return couch_session