def test_create_message_with_model_closed(self): with self.settings(RESTCLIENTS_NWS_DAO_CLASS= 'restclients.dao_implementation.nws.File'): course_available_event = CourseAvailableEvent() course_available_event.event_id = "blah" course_available_event.last_modified = "2012-12-23T09:00:00" course_available_event.space_available = 0 course_available_event.quarter = "winter" course_available_event.year = 2012 course_available_event.curriculum_abbr = "cse" course_available_event.course_number = "100" course_available_event.section_id = "aa" course_available_event.sln = "12345" course_available_event.notification_msg_0 = " NO" message = Message() message.message_type = "uw_student_courseavailable" message.content = course_available_event.json_data() self.assertEquals(message.content['Event']['Section']['SectionID'], 'AA') self.assertEquals( message.content['Event']['Section']['Course'] ['CurriculumAbbreviation'], 'CSE') self.assertEquals(message.content['Event']['NotificationMsg0'], ' NO') nws = NWS() response_status = nws.create_new_message(message) self.assertEquals(response_status, 200)
def test_create_message_with_json(self): with self.settings(RESTCLIENTS_NWS_DAO_CLASS= 'restclients.dao_implementation.nws.File'): json = { "Event": { "EventID": "blah", "Href": "", "LastModified": "2012-12-23T09:00:00", "Section": { "Course": { "CourseNumber": "100", "CurriculumAbbreviation": "cse", "Quarter": "winter", "Year": 2012 }, "Href": "", "SLN": "12345", "SectionID": "aa" }, "SpaceAvailable": 1 } } message = Message() message.message_type = "uw_student_courseavailable" message.content = json nws = NWS() response_status = nws.create_new_message(message) self.assertEquals(response_status, 200)
def test_create_message_with_model_closed(self): with self.settings( RESTCLIENTS_NWS_DAO_CLASS='restclients.dao_implementation.nws.File'): course_available_event = CourseAvailableEvent() course_available_event.event_id = "blah" course_available_event.last_modified = "2012-12-23T09:00:00" course_available_event.space_available = 0 course_available_event.quarter = "winter" course_available_event.year = 2012 course_available_event.curriculum_abbr = "cse" course_available_event.course_number = "100" course_available_event.section_id = "aa" course_available_event.sln = "12345" course_available_event.notification_msg_0 = " NO" message = Message() message.message_type = "uw_student_courseavailable" message.content = course_available_event.json_data() self.assertEquals(message.content['Event']['Section']['SectionID'], 'AA') self.assertEquals(message.content['Event']['Section']['Course']['CurriculumAbbreviation'], 'CSE') self.assertEquals(message.content['Event']['NotificationMsg0'], ' NO') nws = NWS() response_status = nws.create_new_message(message) self.assertEquals(response_status, 200)
def test_create_message_with_json(self): with self.settings( RESTCLIENTS_NWS_DAO_CLASS='restclients.dao_implementation.nws.File'): json = { "Event": { "EventID":"blah", "Href":"", "LastModified":"2012-12-23T09:00:00", "Section": { "Course": { "CourseNumber":"100", "CurriculumAbbreviation":"cse", "Quarter":"winter", "Year":2012 }, "Href":"", "SLN":"12345", "SectionID":"aa" }, "SpaceAvailable":1 } } message = Message() message.message_type = "uw_student_courseavailable" message.content = json nws = NWS() response_status = nws.create_new_message(message) self.assertEquals(response_status, 200)
def test_unmarshall_valid_view_model_to_consume(self): serializer = Serializer() expected = serializer.deserialize( Message(), ExampleMessage().get_file_content_as_string(to_consume=True)) actual = serializer.deserialize( Message(), Serializer().serialize(ExampleMessage().create(to_consume=True), partial=True)) self.assertEqual(expected, actual)
def test_unmarshall_then_marshall_with_two_messages(self): first = ExampleMessage().create(to_consume=False) second = ExampleMessage().create_alternative(to_consume=False) serializer = Serializer() first_serialized = serializer.serialize(first) second_serialized = serializer.serialize(second) first_deserialized = serializer.deserialize(Message(), first_serialized, force_consume=True) second_deserialized = serializer.deserialize(Message(), second_serialized, force_consume=True) self.assertEqual(first, first_deserialized) self.assertEqual(second, second_deserialized)
def _create_message_live_with_model(self): with self.settings(RESTCLIENTS_NWS_DAO_CLASS= 'restclients.dao_implementation.nws.Live'): course_available_event = CourseAvailableEvent() course_available_event.event_id = "blah" course_available_event.last_modified = "2012-12-23T09:00:00" course_available_event.status = "open" course_available_event.space_available = 1 course_available_event.quarter = "autumn" course_available_event.year = 2012 course_available_event.curriculum_abbr = "ling" course_available_event.course_number = "200" course_available_event.section_id = "ac" course_available_event.sln = "16116" message = Message() message.message_type = "uw_student_courseavailable" message.content = course_available_event.json_data() nws = NWS() response_status = nws.create_new_message(message) self.assertEquals(response_status, 200)
def _create_message_live_with_model(self): with self.settings( RESTCLIENTS_NWS_DAO_CLASS='restclients.dao_implementation.nws.Live'): course_available_event = CourseAvailableEvent() course_available_event.event_id = "blah" course_available_event.last_modified = "2012-12-23T09:00:00" course_available_event.status = "open" course_available_event.space_available = 1 course_available_event.quarter = "autumn" course_available_event.year = 2012 course_available_event.curriculum_abbr = "ling" course_available_event.course_number = "200" course_available_event.section_id = "ac" course_available_event.sln = "16116" message = Message() message.message_type = "uw_student_courseavailable" message.content = course_available_event.json_data() nws = NWS() response_status = nws.create_new_message(message) self.assertEquals(response_status, 200)
def create_from_file(self, partial=False, to_consume=True, invalid=False, alternate=False, no_id=False, sent=False): data = self.get_file_content_as_string(partial=partial, to_consume=to_consume, invalid=invalid, alternate=alternate, sent=sent) message = Message() Serializer().deserialize(message, data) return message
def create_alternative(self, to_consume=True, directive=None): channel_view_model = ExampleChannel().create_alternative(to_consume) message = Message() message.message_id = 'b779df7b-d6f6-4afb-8165-8dbe6232119b' if not to_consume: message.message_uri = '/notification/v1/message/b779df7b-d6f6-4afb-8165-8dbe6232119b' message.message_type = 'uw_student_courseavailable1' message.direction = 'outbound' message.destination_type = 'channel' message.destination_id = 'b779df7b-d6f6-4afb-8165-8dbe6232119f' message.source_id = 'ASD234232DS2' message.subject = 'A DIFFERENT SUBJECT' message.body = 'Section is CLOSED for: FLUENCY IN INFORMATION TECHNOLOGY' message.short = 'Section is CLOSED for: 2012,autumn,cse,100,w' message.created = parser.parse('2012-11-13T21:49:07.162630+00:00').astimezone(tz.tzutc()) message.last_modified = parser.parse('2012-11-13T21:49:07.162630+00:00').astimezone(tz.tzutc()) if not to_consume: message.recipients = 1 receipt_view_models = list() receipt_view_models.append(ExampleReceipt().create(to_consume=to_consume)) message.receipts = ReceiptList() message.receipts.view_models = receipt_view_models message.created = '2012-11-13 21:49:07.162630+00:00' message.last_modified = '2012-11-13 21:49:07.162630+00:00' else: message.receipts = None return message
def create(self, to_consume=True, sent=True, child=False): channel_view_model = ExampleChannel().create(to_consume=to_consume) message = Message() message.message_id = 'aa53f5b8-f7f9-4eae-9d8b-b92717d4b670' if not to_consume: message.message_uri = '/notification/v1/message/aa53f5b8-f7f9-4eae-9d8b-b92717d4b670' message.message_type = 'uw_student_courseavailable1' message.direction = 'outbound' message.destination_type = 'channel' message.destination_id = 'b779df7b-d6f6-4afb-8165-8dbe6232119f' message.source_id = 'ASD234232DS1' message.subject = 'FLUENCY IN INFORMATION TECHNOLOGY' message.body = 'Section is OPEN for: FLUENCY IN INFORMATION TECHNOLOGY' message.short = 'Section is OPEN for: 2012,autumn,cse,100,w' message.created = parser.parse('2012-11-13T21:49:07.162630+00:00').astimezone(tz.tzutc()) message.last_modified = parser.parse('2012-11-13T21:49:07.162630+00:00').astimezone(tz.tzutc()) if not to_consume: if not child: receipt_view_models = list() receipt_view_models.append(ExampleReceipt().create(to_consume=to_consume, sent=sent, child=True)) message.receipts = ReceiptList() message.receipts.view_models = receipt_view_models message.created = '2012-11-13 21:49:07.162630+00:00' message.last_modified = '2012-11-13 21:49:07.162630+00:00' else: message.receipts = None return message
def create_alternative(self, to_consume=True, directive=None): channel_view_model = ExampleChannel().create_alternative(to_consume) message = Message() message.message_id = 'b779df7b-d6f6-4afb-8165-8dbe6232119b' if not to_consume: message.message_uri = '/notification/v1/message/b779df7b-d6f6-4afb-8165-8dbe6232119b' message.message_type = 'uw_student_courseavailable1' message.direction = 'outbound' message.destination_type = 'channel' message.destination_id = 'b779df7b-d6f6-4afb-8165-8dbe6232119f' message.source_id = 'ASD234232DS2' message.subject = 'A DIFFERENT SUBJECT' message.body = 'Section is CLOSED for: FLUENCY IN INFORMATION TECHNOLOGY' message.short = 'Section is CLOSED for: 2012,autumn,cse,100,w' message.created = parser.parse( '2012-11-13T21:49:07.162630+00:00').astimezone(tz.tzutc()) message.last_modified = parser.parse( '2012-11-13T21:49:07.162630+00:00').astimezone(tz.tzutc()) if not to_consume: message.recipients = 1 receipt_view_models = list() receipt_view_models.append( ExampleReceipt().create(to_consume=to_consume)) message.receipts = ReceiptList() message.receipts.view_models = receipt_view_models message.created = '2012-11-13 21:49:07.162630+00:00' message.last_modified = '2012-11-13 21:49:07.162630+00:00' else: message.receipts = None return message
def create(self, to_consume=True, sent=True, child=False): channel_view_model = ExampleChannel().create(to_consume=to_consume) message = Message() message.message_id = 'aa53f5b8-f7f9-4eae-9d8b-b92717d4b670' if not to_consume: message.message_uri = '/notification/v1/message/aa53f5b8-f7f9-4eae-9d8b-b92717d4b670' message.message_type = 'uw_student_courseavailable1' message.direction = 'outbound' message.destination_type = 'channel' message.destination_id = 'b779df7b-d6f6-4afb-8165-8dbe6232119f' message.source_id = 'ASD234232DS1' message.subject = 'FLUENCY IN INFORMATION TECHNOLOGY' message.body = 'Section is OPEN for: FLUENCY IN INFORMATION TECHNOLOGY' message.short = 'Section is OPEN for: 2012,autumn,cse,100,w' message.created = parser.parse( '2012-11-13T21:49:07.162630+00:00').astimezone(tz.tzutc()) message.last_modified = parser.parse( '2012-11-13T21:49:07.162630+00:00').astimezone(tz.tzutc()) if not to_consume: if not child: receipt_view_models = list() receipt_view_models.append(ExampleReceipt().create( to_consume=to_consume, sent=sent, child=True)) message.receipts = ReceiptList() message.receipts.view_models = receipt_view_models message.created = '2012-11-13 21:49:07.162630+00:00' message.last_modified = '2012-11-13 21:49:07.162630+00:00' else: message.receipts = None return message