Beispiel #1
0
 def test_init_arg_exception_obj(self):
     class Tester(object):
         def __init__(self, id=None, bad_test="test"):
             self.id = id
             self.bad_test = bad_test
     obj = Tester()
     with self.assertRaises(AttributeError):
         StateDocument(obj)
Beispiel #2
0
 def test_setters_none(self):
     doc = StateDocument()
     doc.id = None
     doc.content_type = None
     doc.content = None
     doc.etag = None
     doc.timestamp = None
     doc.agent = None
     doc.activity = None
     doc.registration = None
     self.assertIsNone(doc.id)
     self.assertIsNone(doc.content_type)
     self.assertIsNone(doc.content)
     self.assertIsNone(doc.etag)
     self.assertIsNone(doc.timestamp)
     self.assertIsNone(doc.agent)
     self.assertIsNone(doc.activity)
     self.assertIsNone(doc.registration)
 def test_init_partial(self):
     doc = StateDocument(id="test", content_type="test type")
     self.assertEqual(doc.id, "test")
     self.assertEqual(doc.content_type, "test type")
     self.assertTrue(hasattr(doc, "content"))
     self.assertTrue(hasattr(doc, "etag"))
     self.assertTrue(hasattr(doc, "timestamp"))
     self.assertTrue(hasattr(doc, "agent"))
     self.assertTrue(hasattr(doc, "activity"))
     self.assertTrue(hasattr(doc, "registration"))
Beispiel #4
0
 def test_setters(self):
     doc = StateDocument()
     doc.id = "test"
     doc.content_type = "test type"
     doc.content = bytearray("test bytearray", "utf-8")
     doc.etag = "test etag"
     doc.timestamp = "2014-06-23T15:25:00-05:00"
     doc.agent = self.agent
     doc.activity = self.activity
     doc.registration = "test registration"
     self.assertEqual(doc.id, "test")
     self.assertEqual(doc.content_type, "test type")
     self.assertEqual(doc.content, bytearray("test bytearray", "utf-8"))
     self.assertEqual(doc.etag, "test etag")
     central = pytz.timezone("US/Central")  # UTC -0500
     dt = central.localize(datetime(2014, 6, 23, 15, 25))
     self.assertEqual(doc.timestamp, dt)
     self.assertEqual(doc.agent, self.agent)
     self.assertEqual(doc.activity, self.activity)
     self.assertEqual(doc.registration, "test registration")
    def test_setters_none(self):
        doc = StateDocument()
        doc.id = None
        doc.content_type = None
        doc.content = None
        doc.etag = None
        doc.timestamp = None
        doc.agent = None
        doc.activity = None
        doc.registration = None

        self.assertIsNone(doc.id)
        self.assertIsNone(doc.content_type)
        self.assertIsNone(doc.content)
        self.assertIsNone(doc.etag)
        self.assertIsNone(doc.timestamp)
        self.assertIsNone(doc.agent)
        self.assertIsNone(doc.activity)
        self.assertIsNone(doc.registration)
    def test_setters(self):
        doc = StateDocument()
        doc.id = "test"
        doc.content_type = "test type"
        doc.content = bytearray("test bytearray", "utf-8")
        doc.etag = "test etag"
        doc.timestamp = "2014-06-23T15:25:00-05:00"
        doc.agent = self.agent
        doc.activity = self.activity
        doc.registration = "test registration"

        self.assertEqual(doc.id, "test")
        self.assertEqual(doc.content_type, "test type")
        self.assertEqual(doc.content, bytearray("test bytearray", "utf-8"))
        self.assertEqual(doc.etag, "test etag")

        central = pytz.timezone("US/Central")   # UTC -0500
        dt = central.localize(datetime(2014, 6, 23, 15, 25))
        self.assertEqual(doc.timestamp, dt)
        self.assertEqual(doc.agent, self.agent)
        self.assertEqual(doc.activity, self.activity)
        self.assertEqual(doc.registration, "test registration")
 def test_init_empty(self):
     doc = StateDocument()
     self.assertIsInstance(doc, StateDocument)
     self.assertTrue(hasattr(doc, "id"))
     self.assertIsNone(doc.id)
     self.assertTrue(hasattr(doc, "content_type"))
     self.assertIsNone(doc.content_type)
     self.assertTrue(hasattr(doc, "content"))
     self.assertIsNone(doc.content)
     self.assertTrue(hasattr(doc, "etag"))
     self.assertIsNone(doc.etag)
     self.assertTrue(hasattr(doc, "timestamp"))
     self.assertIsNone(doc.timestamp)
     self.assertTrue(hasattr(doc, "activity"))
     self.assertIsNone(doc.activity)
     self.assertTrue(hasattr(doc, "agent"))
     self.assertIsNone(doc.agent)
     self.assertTrue(hasattr(doc, "registration"))
     self.assertIsNone(doc.registration)
 def test_init_arg_exception_dict(self):
     d = {"bad_test": "test", "id": "ok"}
     with self.assertRaises(AttributeError):
         StateDocument(d)
 def test_init_kwarg_exception(self):
     with self.assertRaises(AttributeError):
         StateDocument(bad_test="test")
    def test_activity_setter(self):
        doc = StateDocument()
        doc.activity = {"id": "http://tincanapi.com/TinCanPython/Test/Unit/0"}

        self.assertEqual(doc.activity.id,
                         "http://tincanapi.com/TinCanPython/Test/Unit/0")
 def test_agent_setter(self):
     doc = StateDocument()
     doc.agent = {"mbox": "mailto:[email protected]"}
     self.assertIsInstance(doc.agent, Agent)
     self.assertEqual(doc.agent.mbox, self.agent.mbox)
Beispiel #12
0
    "verb": verb,
    "activity": object,
    "related_activities": True,
    "related_agents": True,
    "limit": 2,
}

print "querying statements..."
response = lrs.query_statements(query)

if not response:
    raise ValueError("statements could not be queried")
print "...done"

# now we will explore saving a document, e.g. a state document
print "constructing a state document..."
state_document = StateDocument(
    activity=object,
    agent=actor,
    id='stateDoc',
    content=bytearray('stateDocValue', encoding='utf-8'),
)
print "...done"

print "saving state document..."
response = lrs.save_state(state_document)

if not response.success:
    raise ValueError("could not save state document")
print "...done"
    def test_activity_setter(self):
        doc = StateDocument()
        doc.activity = {"id": "http://tincanapi.com/TinCanPython/Test/Unit/0"}

        self.assertEquals(doc.activity.id, "http://tincanapi.com/TinCanPython/Test/Unit/0")
 def test_agent_setter(self):
     doc = StateDocument()
     doc.agent = {"mbox": "mailto:[email protected]"}
     self.assertIsInstance(doc.agent, Agent)
     self.assertEqual(doc.agent.mbox, self.agent.mbox)