Merged in test_dragon_bot (pull request #17)

Finally a testing framework, fixes #9

Approved-by: Tyler Hodapp <nightfire929@gmail.com>
This commit is contained in:
Luke Robles 2017-08-10 21:01:53 +00:00
commit e3a0ecdfdc
6 changed files with 42 additions and 19 deletions

View File

@ -1,12 +1,9 @@
FROM python:3.6.2-slim FROM python:3.6.2-slim
LABEL name="Dragon Bot"
RUN apt-get update && apt-get install curl -y &&\ RUN apt-get update && apt-get install curl -y &&\
curl -Lks get.docker.com | bash curl -Lks get.docker.com | bash
RUN pip install requests discord.py docker pybooru termcolor RUN pip install requests discord.py docker pybooru
ADD app /app ADD app /app
# Run this to test that the python compiles when we actually go live
RUN python /app/dragon-bot.py test
CMD python app/dragon-bot.py CMD python app/dragon-bot.py

14
Dockerfile-test-env Normal file
View File

@ -0,0 +1,14 @@
FROM python:3.6.2-slim
LABEL name="Dragon Bot Test environment"
RUN apt-get update && apt-get install curl -y &&\
curl -Lks get.docker.com | bash
RUN pip install requests discord.py docker pybooru pylint
ADD app /app
RUN echo "\nTesting your python code for errors\n" && \
pylint -E /app/*.py
RUN echo "\n#########################\nRun dragon bot by typing \npython dragon-bot.py\n#########################\n"
WORKDIR /app

View File

@ -13,11 +13,11 @@ A discord bot for the trifecta discord channel
* `curl -Ls get.docker.com | bash` * `curl -Ls get.docker.com | bash`
### Testing your changes ### ### Testing your changes ###
* Test that you can actually build the container * Build the testing container by running
* `docker build -t testing .` * `./test-dragon-bot.sh`
* `docker run -ti testing bash` * The dragon-bot-test bot will connect to the server.
* Then, if you've added print statements to the script for testing, you can see them by running: * If you want to test what the bot is seeing when you type commands, add LOTS of of print statements to dragon-bot.py
* `python /app/dragon-bot.py` * you will see the output in the terminal. This is useful for debugging
* pipeline [here](https://cloud.docker.com/app/ldooks/repository/docker/ldooks/dragon-bot/builds) * pipeline [here](https://cloud.docker.com/app/ldooks/repository/docker/ldooks/dragon-bot/builds)
### Contribution guidelines ### ### Contribution guidelines ###

View File

@ -1,19 +1,26 @@
import random import random
import sys import sys
import requests import requests
import os
import help_methods import help_methods
import discord import discord
import docker import docker
from pybooru import Danbooru from pybooru import Danbooru
from termcolor import colored
# Client object # Client object
client = discord.Client() client = discord.Client()
tokens = {
'test': 'MzQ1MjkwMTI5OTQ4Mjc4Nzg0.DG5IBw._9umb82PrL22bPe7GjmHClU-NtU',
'prod': 'MzM5NDQ2NTgwMTU3MzQ5ODg4.DG5K5Q.2kIonA_XHLXU4_Sq4O63OzCb0Jc'
}
token = os.getenv('DRAGON_ENV')
@client.event @client.event
async def on_ready(): async def on_ready():
print("Dragon bot up and ready to roll.\n") print("\n********************************")
print("\nDRAGON BOT RUNNING IN {} MODE".format(token.upper()))
print("\n********************************")
@client.event @client.event
@ -253,10 +260,5 @@ async def on_message(message):
else: else:
await client.send_message(message.channel, "There arent {} lines of output yet".format(num_lines)) await client.send_message(message.channel, "There arent {} lines of output yet".format(num_lines))
# Check if there is a command line argument after script
if len(sys.argv) > 1:
print(colored("If you're seeing this, the python compiled", 'green'))
sys.exit()
token = "MzM5NDQ2NTgwMTU3MzQ5ODg4.DFkGYg.z-XD17nFP4rtBq-YsNbOJHuBWfQ" # get from the bot page. must be a bot, not a discord app client.run(tokens[token])
client.run(token)

View File

@ -6,5 +6,5 @@ printf "[+] Done\n"
# Run that shit and mount the docker socket so it can talk to the sky-factory container # Run that shit and mount the docker socket so it can talk to the sky-factory container
printf "\n[-] Pulling latest build of container\n" printf "\n[-] Pulling latest build of container\n"
docker pull ldooks/dragon-bot:latest docker pull ldooks/dragon-bot:latest
docker run -d --name dragon-bot -v /var/run/docker.sock:/var/run/docker.sock --restart always ldooks/dragon-bot:latest docker run -d --name dragon-bot -e "DRAGON_ENV=prod" -v /var/run/docker.sock:/var/run/docker.sock --restart always ldooks/dragon-bot:latest
printf "[+] Done\n" printf "[+] Done\n"

10
test-dragon-bot.sh Executable file
View File

@ -0,0 +1,10 @@
# Remove the running container so we cna re-use the container name 'dragon-bot'
printf "\n[-] Deleting old dragon-bot container from system\n"
docker rm -f dragon-bot-test
printf "[+] Done\n"
# Run that shit and mount the docker socket so it can talk to the sky-factory container
printf "\n[-] Running dragon bot in test mode\n"
docker build -f ./Dockerfile-test-env -t dragon-bot-test . || exit
docker run -ti --name dragon-bot-test -e DRAGON_ENV=test -v /var/run/docker.sock:/var/run/docker.sock dragon-bot-test bash
printf "[+] Done\n"