Example #1
0
    def test_get_notes_view_is_working_properly(self):
        """testing if GET /api/entities/{id}/notes view is working properly
        """
        from stalker import db, Entity, Note
        test_entity = Entity(name='Test Entity')
        db.DBSession.add(test_entity)

        test_note1 = Note(description='This is a Test note 1')
        db.DBSession.add(test_note1)

        test_note2 = Note(description='This is a Test note 2')
        db.DBSession.add(test_note2)

        test_entity.notes = [test_note1, test_note2]
        db.DBSession.commit()

        response = self.test_app.get('/api/entities/%s/notes' % test_entity.id,
                                     status=200)

        self.assertEqual(
            sorted(response.json_body),
            sorted([{
                'id': test_note1.id,
                '$ref': '/api/notes/%s' % test_note1.id,
                'name': test_note1.name,
                'entity_type': test_note1.entity_type
            }, {
                'id': test_note2.id,
                '$ref': '/api/notes/%s' % test_note2.id,
                'name': test_note2.name,
                'entity_type': test_note2.entity_type
            }]))
Example #2
0
    def test_update_notes_is_working_properly_with_put(self):
        """testing if PUT: /api/entities/{id}/notes should raise 404
        """
        from stalker import db, Entity, Note
        test_entity = Entity(name='Test Entity')
        db.DBSession.add(test_entity)

        # Note 1
        test_note1 = Note(content='Note 1')
        db.DBSession.add(test_note1)

        # Note 2
        test_note2 = Note(content='Note 2')
        db.DBSession.add(test_note2)

        # Note 3
        test_note3 = Note(content='Note 3')
        db.DBSession.add(test_note3)

        # Note 4
        test_note4 = Note(content='Note 4')
        db.DBSession.add(test_note4)

        # Note 5
        test_note5 = Note(content='Note 5')
        db.DBSession.add(test_note5)

        test_entity.notes = [test_note1, test_note2, test_note3]
        db.DBSession.commit()

        self.test_app.put('/api/entities/%s/notes' % test_entity.id,
                          params={'note_id': [test_note4.id, test_note5.id]},
                          status=404)
Example #3
0
    def test_entity_notes_is_working_properly(self):
        """testing if get_notes is working properly
        """
        from stalker import db, Entity, Note
        test_entity = Entity(name='Test Entity')
        db.DBSession.add(test_entity)

        # Note 1
        test_note1 = Note(content='Note 1')
        db.DBSession.add(test_note1)

        # Note 2
        test_note2 = Note(content='Note 2')
        db.DBSession.add(test_note2)

        # Note 3
        test_note3 = Note(content='Note 3')
        db.DBSession.add(test_note3)

        # dummy Note 4
        test_note4 = Note(content='Note 4')
        db.DBSession.add(test_note4)

        test_entity.notes = [test_note1, test_note2, test_note3]
        db.DBSession.commit()

        from stalker_pyramid.testing import DummyRequest
        request = DummyRequest()
        request.matchdict['id'] = test_entity.id
        request.method = 'GET'

        entity_view = entity.EntityViews(request)
        response = entity_view.get_notes()

        self.assertEqual(
            sorted(response.json_body),
            sorted([
                {
                    'id': test_note1.id,
                    '$ref': '/api/notes/%s' % test_note1.id,
                    'name': test_note1.name,
                    'entity_type': 'Note'
                },
                {
                    'id': test_note2.id,
                    '$ref': '/api/notes/%s' % test_note2.id,
                    'name': test_note2.name,
                    'entity_type': 'Note'
                },
                {
                    'id': test_note3.id,
                    '$ref': '/api/notes/%s' % test_note3.id,
                    'name': test_note3.name,
                    'entity_type': 'Note'
                },
            ]))
Example #4
0
    def test_inequality(self):
        """testing inequality of two entities
        """
        # change the tags and test it again, expect False
        entity1 = Entity(**self.kwargs)
        entity2 = Entity(**self.kwargs)

        self.kwargs["name"] = "another entity"
        self.kwargs["tags"] = [self.test_tag3]
        self.kwargs["notes"] = []
        entity3 = Entity(**self.kwargs)

        self.assertFalse(entity1 != entity2)
        self.assertTrue(entity1 != entity3)
Example #5
0
    def test_equality(self):
        """testing equality of two entities
        """
        # create two entities with same parameters and check for equality
        entity1 = Entity(**self.kwargs)
        entity2 = Entity(**self.kwargs)

        self.kwargs["name"] = "another entity"
        self.kwargs["tags"] = [self.test_tag3]
        self.kwargs["notes"] = []
        entity3 = Entity(**self.kwargs)

        self.assertTrue(entity1 == entity2)
        self.assertFalse(entity1 == entity3)
Example #6
0
    def test_update_notes_is_working_properly_with_patch(self):
        """testing if update_notes is working properly when the request method
        is PATCH
        """
        from stalker import db, Entity, Note
        test_entity = Entity(name='Test Entity')
        db.DBSession.add(test_entity)

        # Note 1
        test_note1 = Note(content='Note 1')
        db.DBSession.add(test_note1)

        # Note 2
        test_note2 = Note(content='Note 2')
        db.DBSession.add(test_note2)

        # Note 3
        test_note3 = Note(content='Note 3')
        db.DBSession.add(test_note3)

        # Note 4
        test_note4 = Note(content='Note 4')
        db.DBSession.add(test_note4)

        # Note 5
        test_note5 = Note(content='Note 5')
        db.DBSession.add(test_note5)

        test_entity.notes = [test_note1, test_note2, test_note3]
        db.DBSession.commit()

        from stalker_pyramid.testing import DummyRequest, DummyMultiDict
        request = DummyRequest()
        request.matchdict['id'] = test_entity.id
        request.method = 'PATCH'

        # add the 4th and 5th notes
        request.params = DummyMultiDict()
        request.params['note_id'] = [test_note4.id, test_note5.id]
        request.POST = request.params

        entity_view = entity.EntityViews(request)
        entity_view.update_notes()

        test_entity = Entity.query.filter(Entity.id == test_entity.id).first()
        self.assertEqual(
            sorted(test_entity.notes),
            sorted(
                [test_note1, test_note2, test_note3, test_note4, test_note5]))
Example #7
0
    def test_inequality(self):
        """testing inequality of two entities
        """
        # change the tags and test it again, expect False
        import copy
        kwargs = copy.copy(self.kwargs)
        entity1 = Entity(**kwargs)
        entity2 = Entity(**kwargs)

        kwargs["name"] = "another entity"
        kwargs["tags"] = [self.test_tag3]
        kwargs["notes"] = []
        entity3 = Entity(**kwargs)

        assert not entity1 != entity2
        assert entity1 != entity3
Example #8
0
    def test_update_tags_is_working_properly_with_post(self):
        """testing if the update_tags() view is working properly when the
        request.method is POST
        """
        # create some tags
        from stalker import db, Tag
        t1 = Tag(name='tag1')
        t2 = Tag(name='tag2')
        t3 = Tag(name='tag3')
        db.DBSession.add_all([t1, t2, t3])

        from stalker import Entity
        test_entity = Entity(name='Test Entity')
        db.DBSession.add(test_entity)
        db.DBSession.commit()

        from stalker_pyramid.testing import DummyRequest, DummyMultiDict
        request = DummyRequest()
        request.matchdict['id'] = test_entity.id

        request.method = 'POST'
        request.params = DummyMultiDict()
        request.params['tag'] = ['tag1', 'tag2']
        request.POST = request.params

        entity_view = entity.EntityViews(request)
        entity_view.update_tags()

        # now query entity tags
        test_entity = Entity.query.filter(Entity.id == test_entity.id).first()

        self.assertEqual(sorted([t.name for t in test_entity.tags]),
                         sorted(['tag1', 'tag2']))
Example #9
0
    def setUp(self):
        """setting up some proper values
        """
        # create a user
        self.test_user = User(name="Test User",
                              login="******",
                              email="*****@*****.**",
                              password="******")

        # create some test Tag objects, not necessarily needed but create them
        self.test_tag1 = Tag(name="Test Tag 1")
        self.test_tag2 = Tag(name="Test Tag 1")  # make it equal to tag1
        self.test_tag3 = Tag(name="Test Tag 3")

        self.tags = [self.test_tag1, self.test_tag2]

        # create a couple of test Note objects
        self.test_note1 = Note(name="test note1", content="test note1")
        self.test_note2 = Note(name="test note2", content="test note2")
        self.test_note3 = Note(name="test note3", content="test note3")

        self.notes = [self.test_note1, self.test_note2]

        self.kwargs = {
            "name": "Test Entity",
            "description": "This is a test entity, and this is a proper \
            description for it",
            "created_by": self.test_user,
            "updated_by": self.test_user,
            "tags": self.tags,
            "notes": self.notes,
        }

        # create a proper SimpleEntity to use it later in the tests
        self.test_entity = Entity(**self.kwargs)
Example #10
0
 def test_notes_argument_is_set_to_None(self):
     """testing if the notes attribute will be set to an empty list when the
     notes argument is set to None
     """
     self.kwargs["notes"] = None
     new_entity = Entity(**self.kwargs)
     self.assertEqual(new_entity.notes, [])
Example #11
0
    def test_remove_tags_is_working_properly_with_non_existing_tags(self):
        """testing if the remove_tags() method is working properly
        """
        # create some tags
        from stalker import db, Tag
        t1 = Tag(name='tag1')
        t2 = Tag(name='tag2')
        t3 = Tag(name='tag3')

        from stalker import Entity
        test_entity = Entity(name='Test Entity', tags=[t1, t2])
        db.DBSession.add_all([t1, t2, t3, test_entity])
        db.DBSession.commit()

        from stalker_pyramid.testing import DummyRequest, DummyMultiDict
        request = DummyRequest()
        request.method = 'DELETE'
        request.matchdict['id'] = test_entity.id

        request.params = DummyMultiDict()
        request.params['tag'] = ['tag3']
        request.POST = request.params

        entity_view = entity.EntityViews(request)
        entity_view.remove_tags()

        # now query entity tags
        test_entity = Entity.query.filter(Entity.id == test_entity.id).first()

        response = [t.name for t in test_entity.tags]
        expected = ['tag1', 'tag2']
        self.assertEqual(sorted(response), sorted(expected))
Example #12
0
    def test_update_entity_is_working_properly_with_post(self):
        """testing if POST: /api/entities/{id} is working properly
        """
        from stalker import db, Entity, User
        test_user_1 = User(name='Test User 1',
                           login='******',
                           email='*****@*****.**',
                           password='******')
        db.DBSession.add(test_user_1)

        test_user_2 = User(name='Test User 2',
                           login='******',
                           email='*****@*****.**',
                           password='******')
        db.DBSession.add(test_user_2)

        test_entity = Entity(name='Test Entity', created_by=test_user_1)
        db.DBSession.add(test_entity)
        db.DBSession.commit()

        self.test_app.post('/api/entities/%s' % test_entity.id,
                           params={
                               'name': 'New Entity Name',
                               'description': 'New Description',
                               'updated_by_id': test_user_2.id
                           },
                           status=200)

        test_entity_db = Entity.query.get(test_entity.id)
        self.assertEqual(test_entity_db.name, 'New Entity Name')
        self.assertEqual(test_entity_db.description, 'New Description')
        self.assertEqual(test_entity_db.updated_by, test_user_2)
Example #13
0
 def test_tags_argument_being_omitted(self):
     """testing if nothing is raised when creating an entity without setting
     a tags argument
     """
     self.kwargs.pop("tags")
     # this should work without errors
     new_entity = Entity(**self.kwargs)
     self.assertTrue(isinstance(new_entity, Entity))
Example #14
0
    def test_equality(self):
        """testing equality of two entities
        """
        # create two entities with same parameters and check for equality
        import copy
        kwargs = copy.copy(self.kwargs)

        entity1 = Entity(**kwargs)
        entity2 = Entity(**kwargs)

        kwargs["name"] = "another entity"
        kwargs["tags"] = [self.test_tag3]
        kwargs["notes"] = []
        entity3 = Entity(**kwargs)

        assert entity1 == entity2
        assert not entity1 == entity3
Example #15
0
 def test_tags_argument_being_initialized_as_an_empty_list(self):
     """testing if nothing happens when tags argument an empty list
     """
     # this should work without errors
     self.kwargs.pop("tags")
     new_entity = Entity(**self.kwargs)
     expected_result = []
     self.assertEqual(new_entity.tags, expected_result)
Example #16
0
 def test_notes_argument_being_omitted(self):
     """testing if no error raised when omitted the notes argument
     """
     import copy
     kwargs = copy.copy(self.kwargs)
     kwargs.pop("notes")
     new_entity = Entity(**kwargs)
     assert isinstance(new_entity, Entity)
Example #17
0
 def test_notes_argument_is_set_to_None(self):
     """testing if the notes attribute will be set to an empty list when the
     notes argument is set to None
     """
     import copy
     kwargs = copy.copy(self.kwargs)
     kwargs["notes"] = None
     new_entity = Entity(**kwargs)
     assert new_entity.notes == []
Example #18
0
 def test_tags_argument_being_omitted(self):
     """testing if nothing is raised when creating an entity without setting
     a tags argument
     """
     import copy
     kwargs = copy.copy(self.kwargs)
     kwargs.pop("tags")
     # this should work without errors
     new_entity = Entity(**kwargs)
     assert isinstance(new_entity, Entity)
Example #19
0
 def test_tags_argument_being_initialized_as_an_empty_list(self):
     """testing if nothing happens when tags argument an empty list
     """
     # this should work without errors
     import copy
     kwargs = copy.copy(self.kwargs)
     kwargs.pop("tags")
     new_entity = Entity(**kwargs)
     expected_result = []
     assert new_entity.tags == expected_result
Example #20
0
    def test_tags_argument_set_to_something_other_than_a_list(self):
        """testing if a TypeError is going to be raised when initializing the
        tags with something other than a list
        """
        import copy
        kwargs = copy.copy(self.kwargs)
        kwargs["tags"] = ["a tag", 1243, 12.12]
        with pytest.raises(TypeError) as cm:
            Entity(**kwargs)

        assert str(cm.value) == \
            'Entity.tag should be a stalker.models.tag.Tag instance, not str'
Example #21
0
    def test_equality(self):
        """testing the equality of sequences
        """
        new_seq1 = Sequence(**self.kwargs)
        new_seq2 = Sequence(**self.kwargs)
        new_entity = Entity(**self.kwargs)

        self.kwargs["name"] = "a different sequence"
        new_seq3 = Sequence(**self.kwargs)

        self.assertTrue(new_seq1 == new_seq2)
        self.assertFalse(new_seq1 == new_seq3)
        self.assertFalse(new_seq1 == new_entity)
Example #22
0
    def test_notes_argument_set_to_something_other_than_a_list(self):
        """testing if a TypeError will be raised when setting the notes
        argument something other than a list
        """
        import copy
        kwargs = copy.copy(self.kwargs)
        kwargs['notes'] = ["a string note"]
        with pytest.raises(TypeError) as cm:
            Entity(**kwargs)

        assert str(cm.value) == \
            'Entity.note should be a stalker.models.note.Note instance, not ' \
            'str'
Example #23
0
    def test_update_notes_is_working_properly_with_patch(self):
        """testing if PATCH /api/entities/{id}/notes view is working properly
        """
        from stalker import db, Entity, Note
        test_entity = Entity(name='Test Entity')
        db.DBSession.add(test_entity)

        # Note 1
        test_note1 = Note(content='Note 1')
        db.DBSession.add(test_note1)

        # Note 2
        test_note2 = Note(content='Note 2')
        db.DBSession.add(test_note2)

        # Note 3
        test_note3 = Note(content='Note 3')
        db.DBSession.add(test_note3)

        # Note 4
        test_note4 = Note(content='Note 4')
        db.DBSession.add(test_note4)

        # Note 5
        test_note5 = Note(content='Note 5')
        db.DBSession.add(test_note5)

        test_entity.notes = [test_note1, test_note2, test_note3]
        db.DBSession.commit()

        self.test_app.patch('/api/entities/%s/notes' % test_entity.id,
                            params={'note_id': [test_note4.id, test_note5.id]},
                            status=200)

        test_entity = Entity.query.filter(Entity.id == test_entity.id).first()
        self.assertEqual(
            sorted(test_entity.notes),
            sorted(
                [test_note1, test_note2, test_note3, test_note4, test_note5]))
Example #24
0
    def setUp(self):
        """setup the test
        """
        self.kwargs = {
            'name': 'Complete',
            'description': 'use this when the object is complete',
            'code': 'CMPLT',
        }

        # create an entity object with same kwargs for __eq__ and __ne__ tests
        # (it should return False for __eq__ and True for __ne__ for same
        # kwargs)
        self.entity1 = Entity(**self.kwargs)
Example #25
0
    def test_inequality(self):
        """testing the inequality of scenes
        """
        new_seq1 = Scene(**self.kwargs)
        new_seq2 = Scene(**self.kwargs)
        new_entity = Entity(**self.kwargs)

        self.kwargs["name"] = "a different scene"
        new_seq3 = Scene(**self.kwargs)

        self.assertFalse(new_seq1 != new_seq2)
        self.assertTrue(new_seq1 != new_seq3)
        self.assertTrue(new_seq1 != new_entity)
Example #26
0
    def test_equality(self):
        """testing the equality of scenes
        """
        new_seq1 = Scene(**self.kwargs)
        new_seq2 = Scene(**self.kwargs)
        from stalker import Entity
        new_entity = Entity(**self.kwargs)

        self.kwargs["name"] = "a different scene"
        new_seq3 = Scene(**self.kwargs)

        self.assertTrue(new_seq1 == new_seq2)
        self.assertFalse(new_seq1 == new_seq3)
        self.assertFalse(new_seq1 == new_entity)
Example #27
0
    def test_equality(self):
        """testing the equality of sequences
        """
        from stalker import Entity, Sequence
        new_seq1 = Sequence(**self.kwargs)
        new_seq2 = Sequence(**self.kwargs)
        new_entity = Entity(**self.kwargs)

        self.kwargs["name"] = "a different sequence"
        new_seq3 = Sequence(**self.kwargs)

        assert new_seq1 == new_seq2
        assert not new_seq1 == new_seq3
        assert not new_seq1 == new_entity
Example #28
0
    def test_inequality(self):
        """testing the inequality of scenes
        """
        new_seq1 = Scene(**self.kwargs)
        new_seq2 = Scene(**self.kwargs)
        from stalker import Entity
        new_entity = Entity(**self.kwargs)

        self.kwargs["name"] = "a different scene"
        new_seq3 = Scene(**self.kwargs)

        assert not new_seq1 != new_seq2
        assert new_seq1 != new_seq3
        assert new_seq1 != new_entity
Example #29
0
    def test_inequality(self):
        """testing the inequality of sequences
        """
        from stalker import Entity, Sequence
        new_seq1 = Sequence(**self.kwargs)
        new_seq2 = Sequence(**self.kwargs)
        new_entity = Entity(**self.kwargs)

        self.kwargs["name"] = "a different sequence"
        new_seq3 = Sequence(**self.kwargs)

        self.assertFalse(new_seq1 != new_seq2)
        self.assertTrue(new_seq1 != new_seq3)
        self.assertTrue(new_seq1 != new_entity)
Example #30
0
    def setUp(self):
        """set up the test
        """
        self.kwargs = {
            "name": "test type",
            'code': 'test',
            "description": "this is a test type",
            "target_entity_type": "SimpleEntity"
        }

        self.test_type = Type(**self.kwargs)

        # create another Entity with the same name of the
        # test_type for __eq__ and __ne__ tests
        self.entity1 = Entity(**self.kwargs)