Exemplo n.º 1
0
 def test_single_select_on_db_field(self):
     TestModelForm = modelform_factory(TestModel)
     form = TestModelForm()
     model = TestModel()
     form = TestModelForm({"multivaluefield": [1,2]}, instance=model)
     self.assertTrue(form.is_valid(), msg=MultiSelectFieldTest.pretty_field_errors(form))
     self.assertEquals(model.multivaluefield, [u'1',u'2'])
Exemplo n.º 2
0
    def test_path_or_resource(self):
        c = Client()
        obj = TestModel()
        obj.test = 'TESTING'
        obj.save()

        resource = resources1.Test_1_1_Resource()

        list_path = resource.get_resource_list_uri()
        object_path = resource.get_resource_uri(obj)

        result = c._path_or_resource(list_path)
        expected = list_path
        self.assertEqual(
            result, expected,
            "Bare path.\nResult:%s\nExpected:%s" % (result, expected))

        result = c._path_or_resource(list_path, obj)
        expected = list_path
        self.assertEqual(
            result, expected,
            "Bare path w/obj.\nResult:%s\nExpected:%s" % (result, expected))

        result = c._path_or_resource(resource)
        expected = list_path
        self.assertEqual(
            result, expected,
            "Empty resource.\nResult:%s\nExpected:%s" % (result, expected))

        result = c._path_or_resource(resource, obj)
        expected = object_path
        self.assertEqual(
            result, expected,
            "Populated resource.\nResult:%s\nExpected:%s" % (result, expected))
Exemplo n.º 3
0
 def test_save_multivaluefield_with_empty_and_null(self):
     model = TestModel()
     model.multivaluefield = ["1"]
     model.save()
     self.assertEquals(model.multivaluefield, [u"1"])
     self.assertEquals(model.blank_multivaluefield, [])
     self.assertEquals(model.null_multivaluefield, [])
Exemplo n.º 4
0
 def setUp(self):
     self.testbed = testbed.Testbed()
     self.testbed.activate()
     self.testbed.init_datastore_v3_stub()
     self.testbed.init_memcache_stub()
     model = TestModel(key_name='test_key_name')
     self.setup_key = pdb.put(model,
                              _storage=['local', 'memcache', 'datastore'])
     self.cache_key = str(self.setup_key)
Exemplo n.º 5
0
    def test_cascaded_cache_refresh(self):
        e1 = TestModel()
        k1 = db.put(e1)
        #Memcache refresh from datastore
        pdb.get(k1, _storage=['memcache', 'datastore'])
        e2 = pdb.get(k1, _storage='memcache')
        self.assertEqual(e1.key(), e2.key())

        #Local refresh from datastore
        pdb.get(k1, _storage=['local', 'datastore'])
        e2 = pdb.get(k1, _storage='local')
        self.assertEqual(e1.key(), e2.key())

        #Local refresh from memcache
        e3 = TestModel(key_name='memcache_model')
        k3 = pdb.put(e3, _storage='memcache')
        pdb.get(k3, _storage=['local', 'memcache'])
        e4 = pdb.get(k3, _storage='local')
        self.assertEqual(e3.key(), e4.key())
Exemplo n.º 6
0
 def setUp(self):
     self.testbed = testbed.Testbed()
     self.testbed.activate()
     self.testbed.init_datastore_v3_stub()
     self.testbed.init_memcache_stub()
     model = TestModel(key_name='test_model', name='test')
     self.setup_key = db.put(model)
     cache_key = str(self.setup_key)
     cachepy.set(cache_key, model)
     memcache.set(cache_key, _serialize(model))
Exemplo n.º 7
0
async def make_new_test(new_test: TestSchemaCreate):
    """
    valid, msg = validate(new_mood)

    if not valid:
        return HTTPException(status_code=422, detail=msg)
    """

    new_mood_model = TestModel(**new_test.__dict__)
    await new_mood_model.save()

    return new_test
Exemplo n.º 8
0
def generate_queries():
    u1 = User.objects.filter()

    new_name = str(random.randint(0, 2000000))
    if u1:
        u1.update(first_name=new_name)
    else:
        u1 = User(username=new_name)
        u1.save()

    u1 = User.objects.filter(username=new_name)
    if u1:
        u1 = u1[0]
        u1.first_name = new_name + 'hello'
        u1.save()

    users = [User(username=get_random_text()) for i in xrange(100)]
    for user in users:
        user.save()
        sleep(5)
        u = User.objects.filter(username=user.username)
        if u.exists():
            username = u[0].username + 'dfas'
            sleep(3)
            u.update(username=username)
    t = TestModel.objects.filter(user=u1)
    t = list(t)

    for i in xrange(100):
        t = TestModel.objects.filter()
        t = list(t)

    for i in xrange(len(users)):
        random_user = random.choice(users)
        t = TestModel(user=random_user)
        t.save()
        sleep(5)

    for i in xrange(100):
        k = TestModel.objects.select_related('user')
        k = list(k)
    tm = TestModel.objects.all()
    for t in tm:
        t.delete()
        sleep(5)
Exemplo n.º 9
0
    def test_result_type(self):
        single_result = pdb.get(self.setup_key)
        self.assertTrue(isinstance(single_result, db.Model))

        dict_result = pdb.get(self.setup_key, _result_type='dict')
        self.assertTrue(isinstance(dict_result, dict))
        self.assertEqual(dict_result.keys()[0], str(self.setup_key))
        self.assertEqual(dict_result.values()[0].name, 'test')

        name_dict_result = pdb.get(self.setup_key, _result_type='name_dict')
        self.assertTrue(isinstance(name_dict_result, dict))
        self.assertEqual(name_dict_result.keys()[0], self.setup_key.name())
        self.assertEqual(name_dict_result.values()[0].name, 'test')

        #Check for integer based key
        e1 = TestModel(name='integer_test')
        k1 = pdb.put(e1)
        name_dict_result = pdb.get(k1, _result_type='name_dict')
        self.assertTrue(isinstance(name_dict_result, dict))
        self.assertEqual(name_dict_result.keys()[0], str(k1.id()))
        self.assertEqual(name_dict_result.values()[0].name, 'integer_test')
Exemplo n.º 10
0
 def test_lazy(self):
     tm = TestModel()
     tm.save()
Exemplo n.º 11
0
Arquivo: run.py Projeto: hcji/PB-Net
    signal_max = 500
    
opt=Config()
ref = pickle.load(open('./utils/reference_peaks_dat.pkl', 'rb'))
test_input = pickle.load(open('./test_input.pkl', 'rb'))

# Pre-saved sequential PB-Net predictions on test input
#test_preds = pickle.load(open('./test_preds.pkl', 'rb'))

# Pre-saved reference-based PB-Net predictions on test input
#test_preds_ref = pickle.load(open('./test_preds_ref.pkl', 'rb'))

### sequential PB-Net predictions ###
net = TestModel(input_dim=384,
                hidden_dim_lstm=128,
                hidden_dim_attention=32,
                n_lstm_layers=2,
                n_attention_heads=8,
                gpu=opt.gpu)
trainer = Trainer(net, opt, MatchLoss(), featurize=True)
trainer.load('./model-seq.pth')
preds = trainer.predict(test_input)

### reference-based PB-Net predictions ###
net = ReferenceModel(input_dim=384,
                     hidden_dim_lstm=128,
                     hidden_dim_attention=32,
                     n_lstm_layers=2,
                     n_attention_heads=8,
                     gpu=opt.gpu)
trainer = ReferenceTrainer(net, opt, MatchLossRaw(), featurize=True)
test_inputs = [test_input, ref]
Exemplo n.º 12
0
 def test_put_memcache(self):
     model = TestModel(key_name='test_key_name', name='test')
     key = pdb.put(model, _storage='memcache')
     entity = _deserialize(memcache.get(str(key)))
     self.assertEqual('test', entity.name)
Exemplo n.º 13
0
 def test_put_db(self):
     model = TestModel(key_name='test_key_name', name='test')
     key = pdb.put(model, _storage='datastore')
     self.assertEqual('test', db.get(key).name)
Exemplo n.º 14
0
 def test_put_local(self):
     model = TestModel(key_name='test_key_name', name='test')
     key = pdb.put(model, _storage='local')
     entity = cachepy.get(str(key))
     self.assertEqual('test', entity.name)