2011-05-10 02:14:48 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# django-pyvows extensions
|
|
|
|
# https://github.com/rafaelcaricio/django-pyvows
|
|
|
|
|
|
|
|
# Licensed under the MIT license:
|
|
|
|
# http://www.opensource.org/licenses/mit-license
|
|
|
|
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
|
|
|
|
|
|
|
|
from pyvows import Vows, expect
|
|
|
|
from django_pyvows.context import DjangoContext
|
|
|
|
|
2011-08-18 21:44:43 +00:00
|
|
|
DjangoContext.start_environment("sandbox.settings")
|
2011-05-10 02:14:48 +00:00
|
|
|
|
2011-08-25 21:19:24 +00:00
|
|
|
from django.db import models
|
2011-05-10 02:14:48 +00:00
|
|
|
from sandbox.main.models import StringModel
|
|
|
|
|
|
|
|
@Vows.batch
|
2011-08-18 14:28:51 +00:00
|
|
|
class ModelVows(DjangoContext):
|
2011-05-10 02:14:48 +00:00
|
|
|
|
|
|
|
class MainModel(DjangoContext):
|
|
|
|
|
|
|
|
def topic(self):
|
2011-08-18 21:44:43 +00:00
|
|
|
return self.model(StringModel)
|
2011-05-10 02:14:48 +00:00
|
|
|
|
|
|
|
def should_be_cruddable_when_model_only_has_a_string(self, topic):
|
|
|
|
expect(topic).to_be_cruddable()
|
|
|
|
|
2011-05-10 02:28:05 +00:00
|
|
|
def should_be_cruddable_when_string_passed(self, topic):
|
|
|
|
expect(topic).to_be_cruddable({
|
|
|
|
'name': 'something'
|
|
|
|
})
|
|
|
|
|
2011-08-26 14:06:54 +00:00
|
|
|
def should_be_possible_to_use_the_assertion_in_model_instance(self, topic):
|
|
|
|
expect(topic).to_have_field('name')
|
|
|
|
|
2011-08-25 21:19:24 +00:00
|
|
|
def should_have_a_method_to_call(self, topic):
|
|
|
|
expect(hasattr(topic, '__call__')).to_be_true()
|
|
|
|
|
|
|
|
class WhenICreateANewInstance(DjangoContext):
|
|
|
|
|
|
|
|
def topic(self, model):
|
|
|
|
return model()
|
|
|
|
|
|
|
|
def should_be_an_instance_of_django_model_class(self, topic):
|
|
|
|
expect(isinstance(topic, models.Model)).to_be_true()
|
|
|
|
|
2011-08-25 22:34:52 +00:00
|
|
|
def should_have_a_name_field(self, topic):
|
|
|
|
expect(topic).to_have_field('name')
|
|
|
|
|
|
|
|
def should_have_a_name_field_as_charfield(self, topic):
|
|
|
|
expect(topic).to_have_field('name', models.CharField)
|
|
|
|
|
|
|
|
def should_have_a_name_field_as_charfield_and_max_length_100(self, topic):
|
|
|
|
expect(topic).to_have_field('name', models.CharField, max_length=100)
|
|
|
|
|
2011-08-29 22:11:44 +00:00
|
|
|
class AdminModel(DjangoContext):
|
|
|
|
|
|
|
|
def should_be_registred_in_admin(self, topic):
|
|
|
|
expect(topic).to_be_in_admin()
|
|
|
|
|
|
|
|
class StringModelInAdminOptions(DjangoContext):
|
|
|
|
|
|
|
|
def topic(self, model):
|
|
|
|
return model.admin
|
|
|
|
|
|
|
|
def should_be_listed_by_name(self, topic):
|
|
|
|
expect('name' in topic.list_display).to_be_true()
|
2011-05-10 02:14:48 +00:00
|
|
|
|