aboutsummaryrefslogtreecommitdiffstats
path: root/api/tests/test_models.py
blob: 8d41c23e34b6909abbf687b6163fb3bd6370aac6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from datetime import datetime

from django.test import SimpleTestCase

from ..models import (
    DeletedMessage, DocumentationLink,
    Member, Message,
    MessageDeletionContext, ModelReprMixin,
    OffTopicChannelName, Role,
    SnakeFact, SnakeIdiom,
    SnakeName, SpecialSnake,
    Tag
)


class SimpleClass(ModelReprMixin):
    def __init__(self, is_what):
        self.the_cake = is_what


class ReprMixinTests(SimpleTestCase):
    def setUp(self):
        self.klass = SimpleClass('is a lie')

    def test_shows_attributes(self):
        expected = "<SimpleClass(the_cake='is a lie')>"
        self.assertEqual(repr(self.klass), expected)


class StringDunderMethodTests(SimpleTestCase):
    def setUp(self):
        self.objects = (
            DeletedMessage(
                id=45,
                author=Member(
                    id=444, name='bill',
                    discriminator=5, avatar_hash=None
                ),
                channel_id=666,
                content="wooey",
                deletion_context=MessageDeletionContext(
                    actor=Member(
                        id=5555, name='shawn',
                        discriminator=555, avatar_hash=None
                    ),
                    creation=datetime.utcnow()
                ),
                embeds=[]
            ),
            DocumentationLink(
                'test', 'http://example.com', 'http://example.com'
            ),
            OffTopicChannelName(name='bob-the-builders-playground'),
            SnakeFact(fact='snakes are cute'),
            SnakeIdiom(idiom='snake snacks'),
            SnakeName(name='python', scientific='3'),
            SpecialSnake(
                name='Pythagoras Pythonista',
                info='The only python snake that is born a triangle'
            ),
            Role(
                id=5, name='test role',
                colour=0x5, permissions=0
            ),
            Message(
                id=45,
                author=Member(
                    id=444, name='bill',
                    discriminator=5, avatar_hash=None
                ),
                channel_id=666,
                content="wooey",
                embeds=[]
            ),
            MessageDeletionContext(
                actor=Member(
                    id=5555, name='shawn',
                    discriminator=555, avatar_hash=None
                ),
                creation=datetime.utcnow()
            ),
            Member(
                id=5, name='bob',
                discriminator=1, avatar_hash=None
            ),
            Tag(
                title='bob',
                embed={'content': "the builder"}
            )
        )

    def test_returns_string(self):
        for instance in self.objects:
            self.assertIsInstance(str(instance), str)