def test___stalker_version__attribute_is_automatically_set_to_the_current_Stalker_version( self): """testing if the __stalker_version__ is automatically set to the current version for the newly created SimpleEntities """ new_simple_entity = SimpleEntity(**self.kwargs) import stalker self.assertEqual(new_simple_entity.__stalker_version__, stalker.__version__) # update stalker.__version__ to a test value current_version = stalker.__version__ test_version = "test_version" stalker.__version__ = test_version # test if it is updated self.assertEqual(stalker.__version__, test_version) # create a new SimpleEntity and check if it is following the version new_simple_entity2 = SimpleEntity(**self.kwargs) self.assertEqual(new_simple_entity2.__stalker_version__, test_version) # restore the stalker.__version__ stalker.__version__ = current_version
def test_equality(self): """testing the equality of two simple entities """ # create two simple entities with same parameters and check for # equality se1 = SimpleEntity(**self.kwargs) se2 = SimpleEntity(**self.kwargs) self.kwargs["name"] = "a different simple entity" self.kwargs["description"] = "no description" se3 = SimpleEntity(**self.kwargs) assert se1 == se2 assert not se1 == se3
def test_inequality(self): """testing the inequality of two simple entities """ # create two simple entities with same parameters and check for # equality se1 = SimpleEntity(**self.kwargs) se2 = SimpleEntity(**self.kwargs) self.kwargs["name"] = "a different simple entity" self.kwargs["description"] = "no description" se3 = SimpleEntity(**self.kwargs) self.assertFalse(se1 != se2) self.assertTrue(se1 != se3)
def test_name_argument_is_empty_string(self): """testing if the name attribute will be set to an automatic value if the name argument is an empty string """ self.kwargs["name"] = "" new_simple_entity = SimpleEntity(**self.kwargs) assert new_simple_entity.name != ''
def test_name_argument_is_None(self): """testing if the name attribute will be automatically generated if the name argument is None """ self.kwargs["name"] = None new_simple_entity = SimpleEntity(**self.kwargs) assert new_simple_entity.name is not None
def test_html_class_argument_is_None(self): """testing if the html_class argument is set to None the html_class attribute will be an empty string """ self.kwargs['html_class'] = None se = SimpleEntity(**self.kwargs) assert se.html_class == ''
def test_html_style_argument_is_None(self): """testing if the html_style argument is set to None the html_style attribute will be an empty string """ self.kwargs['html_style'] = None se = SimpleEntity(**self.kwargs) self.assertEqual(se.html_style, '')
def test_html_style_argument_is_working_properly(self): """testing if the html_style argument value is correctly passed to the html_style attribute """ test_value = 'width: 100px; color: purple; background-color: black' self.kwargs['html_style'] = test_value se = SimpleEntity(**self.kwargs) assert se.html_style == test_value
def test_html_class_argument_is_working_properly(self): """testing if the html_class argument value is correctly passed to the html_class attribute """ test_value = 'purple' self.kwargs['html_class'] = test_value se = SimpleEntity(**self.kwargs) assert se.html_class == test_value
def test_generic_text_argument_None(self): """testing if generic_text property will be converted to an empty string if None is given as the generic_text argument """ self.kwargs["generic_text"] = None new_simple_entity = SimpleEntity(**self.kwargs) assert new_simple_entity.generic_text == ""
def test_description_argument_None(self): """testing if description property will be converted to an empty string if None is given as the description argument """ self.kwargs["description"] = None new_simple_entity = SimpleEntity(**self.kwargs) assert new_simple_entity.description == ""
def test_html_class_argument_is_skipped(self): """testing if the html_class argument is skipped the html_class attribute will be an empty string """ if 'html_class' in self.kwargs: self.kwargs.pop('html_class') se = SimpleEntity(**self.kwargs) assert se.html_class == ''
def test_html_style_argument_is_skipped(self): """testing if the html_style argument is skipped the html_style attribute will be an empty string """ if 'html_style' in self.kwargs: self.kwargs.pop('html_style') se = SimpleEntity(**self.kwargs) self.assertEqual(se.html_style, '')
def test_type_argument_accepts_only_Type_instances(self): """testing if a TypeError will be raised when the given type attribute is not instance of stalker.models.type.Type class """ test_values = [1, 1.2, "a type"] for test_value in test_values: self.kwargs["type"] = test_value with pytest.raises(TypeError): SimpleEntity(**self.kwargs)
def test_type_argument_accepts_Type_instances(self): """testing if no error will be raised when the type argument is given as a stalker.models.type.Type instance """ # test with a proper Type self.kwargs["type"] = self.test_type # no error is expected new_simple_entity = SimpleEntity(**self.kwargs) assert isinstance(new_simple_entity, SimpleEntity)
def test_updated_by_argument_empty(self): """testing if initializing updated_by with None causes it to be set to the same value with created_by argument """ self.kwargs["updated_by"] = None new_simple_entity = SimpleEntity(**self.kwargs) # now check if they are same assert new_simple_entity.created_by == new_simple_entity.updated_by
def test_generic_text_argument_is_not_a_string(self): """testing if a TypeError will be raised when the generic_text argument value is not a string """ self.kwargs['generic_text'] = {'a': 'generic_text'} with pytest.raises(TypeError) as cm: SimpleEntity(**self.kwargs) assert str(cm.value) == \ 'SimpleEntity.generic_text should be a string, not dict'
def test_description_argument_is_not_a_string(self): """testing if a TypeError will be raised when the description argument value is not a string """ self.kwargs['description'] = {'a': 'description'} with pytest.raises(TypeError) as cm: SimpleEntity(**self.kwargs) assert str(cm.value) == \ 'SimpleEntity.description should be a string, not dict'
def test_name_argument_is_not_a_string_instance_or_None(self): """testing if a TypeError will be raised when the name argument is not a string or None """ test_values = [12132, [1, "name"], {"a": "name"}] for test_value in test_values: self.kwargs["name"] = test_value with pytest.raises(TypeError) as cm: SimpleEntity(**self.kwargs)
def setUp(self): """setup the test """ self.kwargs = { "name": "a test tag", "description": "this is a test tag", } # create another SimpleEntity with kwargs for __eq__ and __ne__ tests self.simple_entity = SimpleEntity(**self.kwargs)
def test_thumbnail_argument_is_working_properly(self): """testing if the thumbnail argument value is passed to the thumbnail attribute correctly """ from stalker import Link thumb = Link(full_path='some path') self.kwargs['thumbnail'] = thumb new_simple_entity = SimpleEntity(**self.kwargs) assert new_simple_entity.thumbnail == thumb
def test_html_class_argument_is_not_a_string(self): """testing if a TypeError will be raised when the html_class argument is not a string """ self.kwargs['html_class'] = 123 with pytest.raises(TypeError) as cm: SimpleEntity(**self.kwargs) assert str(cm.value) == \ 'SimpleEntity.html_class should be a basestring instance, not int'
def test_generic_text_argument_is_not_a_string(self): """testing if a TypeError will be raised when the generic_text argument value is not a string """ self.kwargs['generic_text'] = {'a': 'generic_text'} with self.assertRaises(TypeError) as cm: SimpleEntity(**self.kwargs) self.assertEqual( str(cm.exception), 'SimpleEntity.generic_text should be a string, not dict')
def test_html_class_argument_is_not_a_string(self): """testing if a TypeError will be raised when the html_class argument is not a string """ self.kwargs['html_class'] = 123 with self.assertRaises(TypeError) as cm: SimpleEntity(**self.kwargs) self.assertEqual( str(cm.exception), 'SimpleEntity.html_class should be a basestring instance, not int')
def test_thumbnail_argument_is_not_a_Link_instance(self): """testing if a TypeError will be raised when the thumbnail argument is not a Link instance """ self.kwargs['thumbnail'] = 'not a Link' with pytest.raises(TypeError) as cm: SimpleEntity(**self.kwargs) assert str(cm.value) == \ 'SimpleEntity.thumbnail should be a stalker.models.link.Link ' \ 'instance, not str'
def test_thumbnail_argument_is_skipped(self): """testing if the thumbnail attribute will be None when the thumbnail argument is skipped """ try: self.kwargs.pop('thumbnail') except KeyError: pass new_simple_entity = SimpleEntity(**self.kwargs) assert new_simple_entity.thumbnail is None
def test_thumbnail_argument_is_not_a_Link_instance(self): """testing if a TypeError will be raised when the thumbnail argument is not a Link instance """ self.kwargs['thumbnail'] = 'not a Link' with self.assertRaises(TypeError) as cm: SimpleEntity(**self.kwargs) self.assertEqual( str(cm.exception), 'SimpleEntity.thumbnail should be a stalker.models.link.Link ' 'instance, not str')
def test_generic_data_attribute_can_hold_a_wide_variety_of_object_types( self): """testing if the generic_data attribute can hold any kind of object as a list """ new_simple_entity = SimpleEntity(**self.kwargs) from stalker import User test_user = User( name='email', login='******', email='*****@*****.**', password='******', ) from stalker import Department test_department = Department(name='department1') from stalker import Repository test_repo = Repository( name='Test Repository', code='TR', ) from stalker import Structure test_struct = Structure(name='Test Project Structure') from stalker import Project test_proj = Project( name='Test Project 1', code='tp1', repository=test_repo, structure=test_struct, ) new_simple_entity.generic_data.extend( [test_proj, test_struct, test_repo, test_department, test_user]) # now check if it is added to the database correctly del new_simple_entity new_simple_entity_db = SimpleEntity.query \ .filter_by(name=self.kwargs['name']) \ .first() assert test_proj in new_simple_entity_db.generic_data assert test_struct in new_simple_entity_db.generic_data assert test_repo in new_simple_entity_db.generic_data assert test_department in new_simple_entity_db.generic_data assert test_user in new_simple_entity_db.generic_data
def test_inequality(): """testing the inequality of two Tags """ kwargs = dict(name="a test tag", description="this is a test tag") simple_entity = SimpleEntity(**kwargs) a_tag_object1 = Tag(**kwargs) a_tag_object2 = Tag(**kwargs) kwargs["name"] = "a new test Tag" kwargs["description"] = "this is a new test Tag" a_tag_object3 = Tag(**kwargs) assert not a_tag_object1 != a_tag_object2 assert a_tag_object1 != a_tag_object3 assert a_tag_object1 != simple_entity
def test_date_created_is_before_date_updated(self): """testing if a ValueError is going to be raised when trying to set the date_updated to a time before date_created """ import datetime import pytz self.kwargs["date_created"] = \ datetime.datetime(2000, 1, 1, 1, 1, 1, tzinfo=pytz.utc) self.kwargs["date_updated"] = \ datetime.datetime(1990, 1, 1, 1, 1, 1, tzinfo=pytz.utc) # create a new entity with these dates # and expect a ValueError with pytest.raises(ValueError) as cm: SimpleEntity(**self.kwargs) assert str(cm.value) == \ "SimpleEntity.date_updated could not be set to a date before " \ "SimpleEntity.date_created, try setting the ``date_created`` " \ "first."
def __init__(self, **kwargs): SimpleEntity.__init__(self, **kwargs) ScheduleMixin.__init__(self, **kwargs)