def test_get_events(self): """Getting event test.""" package_members = self.prepare_package_members() db.create_package(package_members['escrow'][0], package_members['launcher'][0], package_members['recipient'][0], 50000000, 100000000, time.time(), None, None, None, None) new_package_members = self.prepare_package_members() db.create_package(new_package_members['escrow'][0], new_package_members['launcher'][0], new_package_members['recipient'][0], 50000000, 100000000, time.time(), None, None, None, None) for user in new_package_members: db.add_event(new_package_members['escrow'][0], user[0], 'new event', None) events = db.get_package_events(package_members['escrow'][0]) self.assertEqual( len(events), 1, "expected 1 event for package: '{}', but '{}' got instead".format( package_members['escrow'][0], len(events))) events = db.get_package_events(new_package_members['escrow'][0]) self.assertEqual( len(events), 5, "expected 5 events for package: '{}', but '{}' got instead".format( package_members['escrow'][0], len(events)))
def test_get_escrow_events(self): """Getting escrow events test.""" packages_members = [self.prepare_package_members() for _ in range(3)] for members in packages_members: db.create_package(members['escrow'][0], members['launcher'][0], members['recipient'][0], '+490857461783', '+4904597863891', 50000000, 100000000, time.time(), 'Package description', '12.970686,77.595590', '41.156193,-8.637541', 'India Bengaluru', 'Spain Porto', '12.970686,77.595590', None) for members in packages_members: events = db.get_package_events(members['escrow'][0]) self.assertEqual(len(events), 1, "1 event expected for escrow: {}, but {} got instead".format( members['escrow'][0], len(events))) for index, members in enumerate(packages_members): for _ in range(index): db.add_event(members['courier'][0], 'new event', '12.970686,77.595590', members['escrow'][0]) for index, members in enumerate(packages_members): events = db.get_package_events(members['escrow'][0]) self.assertEqual(len(events), index+1, "{} event expected for escrow: {}, but {} got instead".format( index + 1, members['escrow'][0], len(events)))
def test_get_events(self): """Getting event test.""" package_members = self.prepare_package_members() db.create_package( package_members['escrow'][0], package_members['launcher'][0], package_members['recipient'][0], '+490857461783', '+4904597863891', 50000000, 100000000, time.time(), 'Package description', '12.970686,77.595590', '41.156193,-8.637541', 'India Bengaluru', 'Spain Porto', '12.970686,77.595590', None) new_package_members = self.prepare_package_members() db.create_package( new_package_members['escrow'][0], new_package_members['launcher'][0], new_package_members['recipient'][0], '+490857461783', '+4904597863891', 50000000, 100000000, time.time(), 'Package description', '12.970686,77.595590', '41.156193,-8.637541', 'India Bengaluru', 'Spain Porto', '12.970686,77.595590', None) for user in new_package_members: db.add_event(new_package_members[user][0], 'new event', '12.970686,77.595590', new_package_members['escrow'][0]) events = db.get_package_events(package_members['escrow'][0]) self.assertEqual(len(events), 1, "expected 1 event for package: '{}', but '{}' got instead".format( package_members['escrow'][0], len(events))) events = db.get_package_events(new_package_members['escrow'][0]) self.assertEqual(len(events), 5, "expected 5 events for package: '{}', but '{}' got instead".format( package_members['escrow'][0], len(events)))
def test_get_escrow_events(self): """Getting escrow events test.""" packages_members = [self.prepare_package_members() for _ in range(3)] for members in packages_members: db.create_package(members['escrow'][0], members['launcher'][0], members['recipient'][0], 50000000, 100000000, time.time(), None, None, None, None) for members in packages_members: events = db.get_package_events(members['escrow'][0]) self.assertEqual( len(events), 1, "1 event expected for escrow: {}, but {} got instead".format( members['escrow'][0], len(events))) for index, members in enumerate(packages_members): for _ in range(index): db.add_event(members['escrow'][0], members['courier'][0], 'couriered', None) for index, members in enumerate(packages_members): events = db.get_package_events(members['escrow'][0]) self.assertEqual( len(events), index + 1, "{} event expected for escrow: {}, but {} got instead".format( index + 1, members['escrow'][0], len(events)))
def test_add_event(self): """Adding event test.""" package_members = self.prepare_package_members() db.create_package( package_members['escrow'][0], package_members['launcher'][0], package_members['recipient'][0], '+490857461783', '+4904597863891', 50000000, 100000000, time.time(), 'Package description', '12.970686,77.595590', '41.156193,-8.637541', 'India Bengaluru', 'Spain Porto', '12.970686,77.595590', None) db.add_event(package_members['courier'][0], 'couriered', '12.970686,77.595590', package_members['escrow'][0]) events = db.get_package_events(package_members['escrow'][0]) self.assertEqual(len(events), 2, "2 events expected, but {} got instead".format(len(events))) couriered_event = next((event for event in events if event['event_type'] == 'couriered'), None) self.assertIsNotNone(couriered_event, "expected event with event_type: 'couriered', None got instead") self.assertEqual( couriered_event['user_pubkey'], package_members['courier'][0], "expected event with user_pubkey: {}, but {} got instead".format( package_members['courier'][0], couriered_event['user_pubkey']))
def test_add_event(self): """Adding event test.""" package_members = self.prepare_package_members() db.create_package(package_members['escrow'][0], package_members['launcher'][0], package_members['recipient'][0], 50000000, 100000000, time.time(), None, None, None, None) db.add_event(package_members['escrow'][0], package_members['courier'][0], 'couriered', None) events = db.get_package_events(package_members['escrow'][0]) self.assertEqual( len(events), 2, "2 events expected, but {} got instead".format(len(events))) couriered_event = next( (event for event in events if event['event_type'] == 'couriered'), None) self.assertIsNotNone( couriered_event, "expected event with event_type: 'couriered', None got instead") self.assertEqual( couriered_event['user_pubkey'], package_members['courier'][0], "expected event with user_pubkey: {}, but {} got instead".format( package_members['courier'][0], couriered_event['user_pubkey']))
def test_create_package(self): """Creating package test.""" package_members = self.prepare_package_members() db.create_package(package_members['escrow'][0], package_members['launcher'][0], package_members['recipient'][0], 50000000, 100000000, time.time(), None, None, None, None) events = db.get_package_events(package_members['escrow'][0]) packages = db.get_packages(package_members['launcher'][0]) self.assertEqual(len(packages), 1, '') self.assertEqual(len(events), 1, '') self.assertEqual( packages[0]['escrow_pubkey'], package_members['escrow'][0], "stored escrow_pubkey is: {}, but package was creating with: {}". format(packages[0]['escrow_pubkey'], package_members['escrow'][0])) self.assertEqual( packages[0]['launcher_pubkey'], package_members['launcher'][0], "stored launcher_pubkey is: {}, but package was creating with: {}". format(packages[0]['launcher_pubkey'], package_members['launcher'][0])) self.assertEqual( packages[0]['recipient_pubkey'], package_members['recipient'][0], "stored recipient_pubkey is: {}, but package was creating with: {}" .format(packages[0]['recipient_pubkey'], package_members['recipient'][0])) self.assertEqual( events[0]['event_type'], 'launched', "created event '{}', but must be 'launched'".format( events[0]['event_type'])) self.assertEqual( packages[0]['launch_date'], events[0]['timestamp'], "package has launch date {}, but was launched at {}".format( packages[0]['launch_date'], events[0]['timestamp'])) self.assertEqual( events[0]['user_pubkey'], package_members['launcher'][0], "created event for user: {}, but must be for: {}".format( events[0]['user_pubkey'], package_members['launcher'][0]))
def test_create_package(self): """Creating package test.""" package_members = self.prepare_package_members() db.create_package( package_members['escrow'][0], package_members['launcher'][0], package_members['recipient'][0], '+490857461783', '+4904597863891', 50000000, 100000000, time.time(), 'Package description', '12.970686,77.595590', '41.156193,-8.637541', 'India Bengaluru', 'Spain Porto', '12.970686,77.595590', None) events = db.get_package_events(package_members['escrow'][0]) packages = db.get_packages(package_members['launcher'][0]) self.assertEqual(len(packages), 1, "should be 1 created package, {} got instead".format(len(packages))) self.assertEqual(len(events), 1, "created package should contain 1 event, {} got instead".format(len(events))) self.assertEqual( packages[0]['escrow_pubkey'], package_members['escrow'][0], "stored escrow_pubkey is: {}, but package was creating with: {}".format( packages[0]['escrow_pubkey'], package_members['escrow'][0])) self.assertEqual( packages[0]['launcher_pubkey'], package_members['launcher'][0], "stored launcher_pubkey is: {}, but package was creating with: {}".format( packages[0]['launcher_pubkey'], package_members['launcher'][0])) self.assertEqual( packages[0]['recipient_pubkey'], package_members['recipient'][0], "stored recipient_pubkey is: {}, but package was creating with: {}".format( packages[0]['recipient_pubkey'], package_members['recipient'][0])) self.assertEqual( events[0]['event_type'], 'launched', "created event '{}', but must be 'launched'".format( events[0]['event_type'])) self.assertEqual( packages[0]['launch_date'], events[0]['timestamp'], "package has launch date {}, but was launched at {}".format( packages[0]['launch_date'], events[0]['timestamp'])) self.assertEqual( events[0]['user_pubkey'], package_members['launcher'][0], "created event for user: {}, but must be for: {}".format( events[0]['user_pubkey'], package_members['launcher'][0]))