Пример #1
0
 def test_get(self):
     """Test get method functionality"""
     new_state = State(name="Astate")
     new_state.save()
     check = models.storage.get(State, new_state.id)
     self.assertEqual(new_state.id, check.id)
     new_state.delete()
Пример #2
0
    def test_get_success(self):
        """ test for successful object retrival """
        storage = FileStorage()
        new_state = State()
        new_city = City()
        new_state.save()
        new_city.save()

        found_city = storage.get(City, new_city.id)
        found_state = storage.get(State, new_state.id)
        wrong_city = storage.get(City, "1234")
        wrong_state = storage.get(State, "12345")
        self.assertEqual(found_state, new_state)
        self.assertIs(found_state, new_state)
        self.assertIsInstance(found_state, State)
        self.assertNotEqual(found_state, None)
        self.assertIsNot(found_state, None)

        self.assertEqual(found_city, new_city)
        self.assertIs(found_city, new_city)
        self.assertIsInstance(found_city, City)
        self.assertNotEqual(found_city, None)
        self.assertIsNot(found_city, None)
        new_state.delete()
        new_city.delete()
 def test_get(self):
     """ tests get """
     ob = State(name="Alahama")
     ob.save()
     returnob = models.storage.get(State, ob.id)
     self.assertEqual(ob.id, returnob.id)
     ob.delete()
 def test_count(self):
     """ tests object count """
     ogcount = models.storage.count()
     ob = State(name="ferkingjern")
     ob.save()
     othercount = models.storage.count()
     self.assertEqual(othercount, ogcount + 1)
     ob.delete()
    def test_get(self):
        """Test that the get properly gets objects"""
        obj = State(name="Test")
        obj.save()
        got_obj = models.storage.get('State', obj.id)
        self.assertIs(obj, got_obj)

        obj.delete()
Пример #6
0
 def test_count(self):
     """Test count method functionality"""
     count = models.storage.count()
     new_state = State(name="Astate")
     new_state.save()
     new_count = models.storage.count()
     self.assertEqual(count + 1, new_count)
     new_state.delete()
Пример #7
0
 def test_get(self):
     """ Tests DBStorage get method """
     new_state = State()
     new_state.id = '1234'
     new_state.save()
     expected = new_state
     actual = models.storage.get(State, '1234')
     self.assertEqual(expected, actual)
     new_state.delete()
     models.storage.save()
Пример #8
0
 def test_count(self):
     """Test that count returns proper number of objects"""
     # test count of all objects
     fs = models.storage.all()
     self.assertEqual(models.storage.count(), len(fs))
     # test count one class
     fs_state = models.storage.all(State)
     self.assertEqual(models.storage.count(State), len(fs_state))
     # test for count increment
     state1 = State()
     state1.name = "Oklahoma"
     state1.save()
     self.assertEqual(models.storage.count(State), len(fs_state) + 1)
     state1.delete()
Пример #9
0
 def test_count(self):
     """Test if count method counts number of objects in storage"""
     counter = models.storage.count()
     new_state = State(name="California")
     new_state.save()
     self.assertNotEqual(models.storage.count(State), 0)
     self.assertEqual(storage.count(Amenity), 1)
     new_amenity = Amenity(name="Smoking allowed")
     new_amenity.save()
     self.assertNotEqual(models.storage.count(Amenity), 0)
     self.assertIsInstance(models.storage.count(), int)
     self.assertIsInstance(models.storage.count(Amenity), int)
     self.assertNotEqual(models.storage.count(Amenity), None)
     new_state.delete()
     new_amenity.delete()
Пример #10
0
    def test_get(self):
        """Test that all get """
        state = State()
        state.name = "Oklahoma"
        state.save()

        # Test valid input
        valid = models.storage.get(State, state.id)
        self.assertIs(valid, state)
        # Test ids are the same
        self.assertEqual(state.id, valid.id)
        # Test invalid id
        self.assertIs(models.storage.get(State, "bad_id_12345"), None)
        # Test invalid class
        bad_clss = None
        self.assertIs(models.storage.get(bad_clss, id), None)
        state.delete()
Пример #11
0
 def test_count(self):
     """""Test if count method counts number of objects in storage"""
     storage = FileStorage()
     count = storage.count()
     count_u = storage.count(User)
     count_s = storage.count(State)
     new_state = State(name='CT')
     new_state.save()
     new_user = User(email="*****@*****.**", password="******")
     new_user.save()
     self.assertEqual(storage.count(), count + 2)
     self.assertNotEqual(storage.count(User), count_u)
     self.assertIsInstance(storage.count(), int)
     self.assertNotEqual(storage.count(State), count_s)
     self.assertIsInstance(storage.count(State), int)
     self.assertNotEqual(storage.count(), None)
     self.assertEqual(storage.count(), storage.count(None))
     new_user.delete()
     new_state.delete()
Пример #12
0
    def test_get(self):
        """Test that get returns the object requested or None"""
        state = State()
        state.name = "Oklahoma"
        state.save()

        # test valid input
        valid = models.storage.get(State, state.id)
        self.assertIs(valid, state)
        # test ids are equal
        self.assertEqual(state.id, valid.id)
        # test bad id
        bad_id = models.storage.get(State, "bad_id_1234")
        self.assertIs(bad_id, None)
        # test for obj that is not one of the classes
        """
        bad_obj = models.storage.get(bad_obj, state.id)
        self.assertIs(bad_obj, None)
        """
        state.delete()
Пример #13
0
 def test_count(self):
     """Test that count returns objects or given class or or all objects"""
     state1 = State()
     state1.name = "Oklahoma"
     state1.save()
     state2 = State()
     state2.name = "Texas"
     state2.save()
     # valid test case, when cls is give and when not given
     self.assertEqual(models.storage.count(State), 2)
     self.assertEqual(models.storage.count(), 2)
     # delete one state obj
     state2.delete()
     self.assertEqual(models.storage.count(State), 1)
     self.assertEqual(models.storage.count(), 1)
     """
     # add a test for obj that is not one of the classes?
     not_obj = None
     self.assertEqual(models.storage.count(not_obj),
                      "** class doesn't exist **")
     """
     state1.delete()
Пример #14
0
    def test_get(self):
        """"Test if methods retieves objects"""
        state = State(name="Alabama")
        state.save()
        found_state = models.storage.get(State, state.id)
        wrong_state = models.storage.get(State, "70")
        self.assertIs(found_state, state)
        self.assertEqual(found_state, state)
        self.assertIsInstance(found_state, State)
        self.assertEqual(wrong_state, None)
        self.assertNotEqual(found_state, None)

        new_user = User(email="*****@*****.**", password="******")
        new_user.save()
        found_user = models.storage.get(User, new_user.id)
        wrong_user = models.storage.get(User, "77")
        self.assertEqual(found_user, new_user)
        self.assertIs(found_user, new_user)
        self.assertIsInstance(found_user, User)
        self.assertIsNone(wrong_user)
        self.assertNotEqual(found_user, None)
        state.delete()
        new_user.delete()
Пример #15
0
    async def studyProgram(self, ctx, active: typing.Optional[str]):
        if active:
            active = active.lower()

        # in general we does not care whether a message was already send or not

        # post message with content
        if active == 'start':
            guild_study_course_message = State.get(
                'guild_study_course_message')

            if guild_study_course_message:
                # create output embed
                embed = discord.Embed(
                    colour=discord.Colour.red(),
                    title=f'Es existiert bereits eine Nachricht, welche die Verteilung der Studiengänge behandelt.'
                )

                # send embed
                await ctx.send(ctx.author.mention, embed=embed)
                return

            if self.guild_study_course_channel_id > 0:
                guild_study_course_channel = self.bot.get_channel(
                    self.guild_study_course_channel_id
                )

                if guild_study_course_channel:
                    command_message = await guild_study_course_channel.send(
                        'Hallo @everyone,\n' +
                        'Ab sofort könnt ihr euch eurem Studiengang zuordnen! Dies passiert indem du auf diese Nachricht reagierst.\n' +
                        'Die entsprechenden Buchstaben sind wie folgt zu verstehen:\n' +
                        ':regional_indicator_i: - Informatik\n' +
                        ':regional_indicator_w: - Wirtschaftsinformatik\n' +
                        ':regional_indicator_e: - Elektrotechnik\n' +
                        ':regional_indicator_m: - Media and Communications for Digital Business'
                    )
                    await command_message.add_reaction('🇮')
                    await command_message.add_reaction('🇼')
                    await command_message.add_reaction('🇪')
                    await command_message.add_reaction('🇲')
                    if command_message:
                        State.set('guild_study_course_message',
                                  command_message.id)

        if active == 'stopp':
            guild_study_course_message = State.get(
                'guild_study_course_message')

            if guild_study_course_message:
                channel = self.bot.get_channel(
                    self.guild_study_course_channel_id)
                msg = await channel.fetch_message(int(guild_study_course_message.value))
                if msg:
                    await msg.delete()
                State.delete('guild_study_course_message')
            else:
                embed = discord.Embed(
                    colour=discord.Colour.red(),
                    title=f'Es existiert keine Nachricht, welche die Verteilung der Studiengänge behandelt.'
                )
                # send embed
                await ctx.send(ctx.author.mention, embed=embed)
Пример #16
0
def state_delete(id, country):
    result = State.delete(id, country)
    if result:
        flash('State deleted successfully!!!')
    return redirect(url_for('state'))
Пример #17
0
    async def groupphase(self, ctx, type:  typing.Optional[str], groupamount: typing.Optional[int]):
        if type:
            type = type.lower()

        if type == 'start':
            # check if grouphase is already startet
            state_groupphase_isStarted = State.get('groupphase_isStarted')
            if (state_groupphase_isStarted and state_groupphase_isStarted.value == str(True)):

                # create output embed
                embed = discord.Embed(
                    colour=discord.Colour.red(),
                    title=f'Es läuft schon eine Gruppenphase! Beende erst die alte, bevor du eine neue startest.'
                )

                # send embed
                await ctx.send(ctx.author.mention, embed=embed)

            else:

                # check if guild_announcements_channel_id isset
                if self.guild_announcements_channel_id > 0:
                    guild_announcements_channel = self.bot.get_channel(
                        self.guild_announcements_channel_id)

                    # check if channel was found
                    if guild_announcements_channel:
                        announcement_message = await guild_announcements_channel.send('Hallo @everyone,\neine neue Gruppenphase wurde gerade gestartet! Wenn du mitmachen willst, reagiere einfach mit einem :white_check_mark: auf diese Nachricht!')
                        await announcement_message.add_reaction('✅')

                        # start groupphase
                        State.set('groupphase_isStarted', str(True))
                        State.set('groupphase_reaction_message',
                                  announcement_message.id)

                        # create output embed
                        embed = discord.Embed(
                            colour=discord.Colour.green(),
                            title=f'Die Gruppenphase wurde erfolgreich gestartet!'
                        )

                        # send embed
                        await ctx.send(ctx.author.mention, embed=embed)

                    else:
                        # create output embed
                        embed = discord.Embed(
                            colour=discord.Colour.red(),
                            title=f'Der Ankündigung-Kanal wurde nicht gefunden. Überprüfe in der `.env`-Datei den Parameter `GUILD_ANNOUNCEMENTS_CHANNEL`.'
                        )

                        # send embed
                        await ctx.send(ctx.author.mention, embed=embed)

                else:
                    # create output embed
                    embed = discord.Embed(
                        colour=discord.Colour.red(),
                        title=f'Bitte setze in der `.env`-Datei den Parameter `GUILD_ANNOUNCEMENTS_CHANNEL`.'
                    )

                    # send embed
                    await ctx.send(ctx.author.mention, embed=embed)

        elif type == 'stop':
            # check if grouphase is startet
            state_groupphase_isStarted = State.get('groupphase_isStarted')
            if (state_groupphase_isStarted and state_groupphase_isStarted.value == str(True)):

                # delete all groups
                for group in Group.all():
                    try:
                        await ctx.guild.get_role(group.role).delete()
                    except Exception:
                        pass

                    try:
                        await ctx.guild.get_channel(group.textChannel).delete()
                    except Exception:
                        pass

                    try:
                        await ctx.guild.get_channel(group.voiceChannel).delete()
                    except Exception:
                        pass

                    Group.delete(group.id)

                # delete groupphase user
                Groupphaseuser.deleteall()

                # delete groupphase
                State.delete('groupphase_isStarted')
                State.delete('groupphase_reaction_message')

                # create output embed
                embed = discord.Embed(
                    colour=discord.Colour.green(),
                    title=f'Die Gruppenphase wurde erfolgreich beendet!'
                )

                # send embed
                await ctx.send(ctx.author.mention, embed=embed)

            else:

                # create output embed
                embed = discord.Embed(
                    colour=discord.Colour.red(),
                    title=f'Es läuft keine Gruppenphase, die du beenden könntest!'
                )

                # send embed
                await ctx.send(ctx.author.mention, embed=embed)

        elif type in ['sort', 'inf', 'wi', 'et', 'mcd']:
            # check if grouphase is startet
            state_groupphase_isStarted = State.get('groupphase_isStarted')
            if (state_groupphase_isStarted and state_groupphase_isStarted.value == str(True)):

                # check if groupamount parameter isset
                if groupamount:
                    if groupamount < 2:
                        groupamount = 2
                    elif groupamount > 100:
                        groupamount = 100

                    # create output embed
                    embed = discord.Embed(
                        colour=discord.Colour.blue(),
                        title="Einteilung der Gruppenphase beginnt",
                    )

                    if type == 'sort':
                        members_total = len(Groupphaseuser.all())
                        embed.add_field(name='Teilnehmer',
                                        value=f'{members_total}', inline=False)
                    elif type == 'inf':
                        members_total = len(Groupphaseuser.inf())
                        embed.add_field(name='Teilnehmer (INF)',
                                        value=f'{members_total}', inline=False)
                    elif type == 'wi':
                        members_total = len(Groupphaseuser.wi())
                        embed.add_field(name='Teilnehmer (WI)',
                                        value=f'{members_total}', inline=False)
                    elif type == 'et':
                        members_total = len(Groupphaseuser.et())
                        embed.add_field(name='Teilnehmer (ET)',
                                        value=f'{members_total}', inline=False)
                    elif type == 'mcd':
                        members_total = len(Groupphaseuser.mcd())
                        embed.add_field(name='Teilnehmer (MCD)',
                                        value=f'{members_total}', inline=False)

                    embed.add_field(name='Gruppenanzahl',
                                    value=f'{groupamount}', inline=False)
                    embed.add_field(name='Max. Teilnehmer pro Gruppe',
                                    value=f'{math.ceil(members_total/groupamount)}', inline=False)

                    # send message
                    await ctx.send(ctx.author.mention, embed=embed)

                    for x in range(groupamount):
                        if type == 'sort':
                            groupname = 'Gruppe ' + str((x) + 1)
                        else:
                            groupname = type.upper() + '-Gruppe ' + str((x) + 1)

                        role = await ctx.guild.create_role(name=groupname, hoist=False)

                        if self.guild_tutor_sup_role != None:
                            overwrites = {
                                ctx.guild.default_role: discord.PermissionOverwrite(
                                    view_channel=False,
                                    read_messages=False,
                                    connect=False,
                                ),
                                role: discord.PermissionOverwrite(
                                    view_channel=True,
                                    read_messages=True,
                                    connect=True,
                                ),
                                self.guild_tutor_sup_role: discord.PermissionOverwrite(
                                    view_channel=True,
                                    read_messages=True,
                                    connect=True,
                                ),
                            }
                        else:
                            overwrites = {
                                ctx.guild.default_role: discord.PermissionOverwrite(
                                    view_channel=False,
                                    read_messages=False,
                                    connect=False,
                                ),
                                role: discord.PermissionOverwrite(
                                    view_channel=True,
                                    read_messages=True,
                                    connect=True,
                                )
                            }

                        voiceChannel = await ctx.guild.create_voice_channel(name=groupname, overwrites=overwrites)
                        textChannel = await ctx.guild.create_text_channel(name=groupname, overwrites=overwrites)

                        group = Group(groupname, role.id,
                                      voiceChannel.id, textChannel.id)
                        if type == 'inf':
                            group.course = "inf"
                        elif type == 'wi':
                            group.course = "wi"
                        elif type == 'et':
                            group.course = "et"
                        elif type == 'mcd':
                            group.course = "mcd"

                        db_session.add(group)
                        db_session.commit()

                    # create output embed
                    embed = discord.Embed(
                        colour=discord.Colour.green(),
                        title=f'Gruppen erfolgreich angelegt!'
                    )

                    # send embed
                    await ctx.send(ctx.author.mention, embed=embed)

                    # create output embed
                    embed = discord.Embed(
                        colour=discord.Colour.blue(),
                        title=f'Beginne mit der Einteilung der Teilnehmer.'
                    )

                    # send embed
                    await ctx.send(ctx.author.mention, embed=embed)

                    if type == 'sort':
                        groups = Group.all()
                        allWithoutGroups = Groupphaseuser.allWithoutGroup()
                    elif type == 'inf':
                        groups = Group.inf()
                        allWithoutGroups = Groupphaseuser.allWithoutGroupInf()
                    elif type == 'wi':
                        groups = Group.wi()
                        allWithoutGroups = Groupphaseuser.allWithoutGroupWi()
                    elif type == 'et':
                        groups = Group.et()
                        allWithoutGroups = Groupphaseuser.allWithoutGroupEt()
                    elif type == 'mcd':
                        groups = Group.mcd()
                        allWithoutGroups = Groupphaseuser.allWithoutGroupMcd()
                    else:
                        return

                    counter = 0

                    for user in allWithoutGroups:
                        if counter >= groupamount:
                            counter = 0

                        user.groupID = groups[counter].id
                        userDiscord = ctx.guild.get_member(user.id)
                        role = ctx.guild.get_role(groups[counter].role)
                        await userDiscord.add_roles(role)

                        counter += 1
                        db_session.commit()

                    # create output embed
                    embed = discord.Embed(
                        colour=discord.Colour.green(),
                        title=f'Teilnehmer erfolgreich eingeteilt!'
                    )

                    # send embed
                    await ctx.send(ctx.author.mention, embed=embed)

                else:

                    # create output embed
                    embed = discord.Embed(
                        colour=discord.Colour.red(),
                        title=f'Bitte füge noch den Parameter `groupamount` hinzu.'
                    )

                    # send embed
                    await ctx.send(ctx.author.mention, embed=embed)

            else:

                # create output embed
                embed = discord.Embed(
                    colour=discord.Colour.red(),
                    title=f'Es läuft keine Gruppenphase, die du einteilen könntest!'
                )

                # send embed
                await ctx.send(ctx.author.mention, embed=embed)

        else:

            # check if grouphase is startet
            state_groupphase_isStarted = State.get('groupphase_isStarted')
            if (state_groupphase_isStarted and state_groupphase_isStarted.value == str(True)):

                # create output embed
                embed = discord.Embed(
                    colour=discord.Colour.blue(),
                    title="Informationen zur Gruppenphase",
                )

                members_total = len(Groupphaseuser.all())

                embed.add_field(name='Teilnehmer',
                                value=f'{members_total}', inline=False)

                inf_total = len(Groupphaseuser.inf())

                embed.add_field(name='INF',
                                value=f'{inf_total}', inline=False)

                wi_total = len(Groupphaseuser.wi())

                embed.add_field(name='WI',
                                value=f'{wi_total}', inline=False)

                et_total = len(Groupphaseuser.et())

                embed.add_field(name='ET',
                                value=f'{et_total}', inline=False)

                mcd_total = len(Groupphaseuser.mcd())

                embed.add_field(name='MCD',
                                value=f'{mcd_total}', inline=False)

                # send message
                await ctx.send(ctx.author.mention, embed=embed)

            else:

                # create output embed
                embed = discord.Embed(
                    colour=discord.Colour.red(),
                    title=f'Es läuft keine Gruppenphase, über die du Informationen anfodern kannst!'
                )

                # send embed
                await ctx.send(ctx.author.mention, embed=embed)