Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Commit

Permalink
make notification fixture download from s3
Browse files Browse the repository at this point in the history
  • Loading branch information
localhuman committed Jan 17, 2018
1 parent e995257 commit 3dda7ee
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 18 deletions.
4 changes: 1 addition & 3 deletions fixtures/.gitignore
Expand Up @@ -6,6 +6,4 @@
!testwallet3.db3
!withdraw_wallet.db3
!withdraw_wallet2.db3
!797966.txt
!test_notifications
!test_notifications/*
!797966.txt
9 changes: 0 additions & 9 deletions fixtures/test_notifications/.gitignore

This file was deleted.

Binary file removed fixtures/test_notifications/000007.ldb
Binary file not shown.
Binary file removed fixtures/test_notifications/000012.ldb
Binary file not shown.
Binary file removed fixtures/test_notifications/000103.ldb
Binary file not shown.
1 change: 0 additions & 1 deletion fixtures/test_notifications/CURRENT

This file was deleted.

Empty file removed fixtures/test_notifications/LOCK
Empty file.
Binary file removed fixtures/test_notifications/MANIFEST-000107
Binary file not shown.
38 changes: 33 additions & 5 deletions neo/Implementations/Notifications/REST/test_notification_server.py
@@ -1,11 +1,13 @@
from unittest import TestCase
from neo.Settings import settings
from neo.SmartContract.SmartContractEvent import SmartContractEvent, NotifyEvent
from neocore.UInt160 import UInt160
from neocore.UInt256 import UInt256
from uuid import uuid1
import shutil
import json
import os
import requests
import tarfile
import logzero
import shutil

from neo.Implementations.Notifications.REST.NotificationServer import NotificationServer

from neo.Implementations.Notifications.LevelDB.NotificationDB import NotificationDB
Expand All @@ -14,6 +16,10 @@

class NotificationDBTestCase(TestCase):

FIXTURE_REMOTE_LOC = 'https://s3.us-east-2.amazonaws.com/cityofzion/fixtures/notif_fixture.tar.gz'
FIXTURE_FILENAME = './Chains/notif_fixture.tar.gz'
NOTIFICATION_DB_NAME = 'fixtures/test_notifications'

contract_hash = UInt160(data=bytearray(b'\x11\xc4\xd1\xf4\xfb\xa6\x19\xf2b\x88p\xd3n:\x97s\xe8tp['))
event_tx = '042e4168cb2d563714d3f35ff76b7efc6c7d428360c97b6b45a18b5b1a4faa40'

Expand All @@ -25,13 +31,35 @@ class NotificationDBTestCase(TestCase):
@classmethod
def setUpClass(cls):

settings.NOTIFICATION_DB_PATH = 'fixtures/test_notifications'
if not os.path.exists(cls.FIXTURE_FILENAME):
logzero.logger.info(
"downloading fixture notification database from %s. this may take a while" % cls.FIXTURE_REMOTE_LOC)

response = requests.get(cls.FIXTURE_REMOTE_LOC, stream=True)

response.raise_for_status()
with open(cls.FIXTURE_FILENAME, 'wb+') as handle:
for block in response.iter_content(1024):
handle.write(block)

try:
tar = tarfile.open(cls.FIXTURE_FILENAME)
tar.extractall()
tar.close()
except Exception as e:
raise Exception("Could not extract tar file - %s. You may want need to remove the fixtures file %s manually to fix this." % (e, cls.FIXTURE_FILENAME))

if not os.path.exists(cls.NOTIFICATION_DB_NAME):
raise Exception("Error downloading fixtures")

settings.NOTIFICATION_DB_PATH = cls.NOTIFICATION_DB_NAME
ndb = NotificationDB.instance()
ndb.start()

@classmethod
def tearDownClass(cls):
NotificationDB.instance().close()
shutil.rmtree(cls.NOTIFICATION_DB_NAME)

def setUp(self):
self.app = NotificationServer()
Expand Down

0 comments on commit 3dda7ee

Please sign in to comment.